llamactl 0.3.25__py3-none-any.whl → 0.3.27__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -76,7 +76,8 @@ class ConfigManager:
76
76
 
77
77
  with sqlite3.connect(self.db_path) as conn:
78
78
  # Apply ad-hoc SQL migrations based on PRAGMA user_version
79
- run_migrations(conn)
79
+ # Pass db_path to enable file-based locking across processes
80
+ run_migrations(conn, self.db_path)
80
81
 
81
82
  conn.commit()
82
83
 
@@ -6,10 +6,14 @@ Inspired by https://eskerda.com/sqlite-schema-migrations-python/
6
6
  from __future__ import annotations
7
7
 
8
8
  import logging
9
+ import os
9
10
  import re
10
11
  import sqlite3
11
12
  import sys
13
+ from contextlib import contextmanager
12
14
  from importlib import import_module, resources
15
+ from pathlib import Path
16
+ from typing import Generator
13
17
 
14
18
  if sys.version_info >= (3, 11):
15
19
  from importlib.resources.abc import Traversable
@@ -23,6 +27,42 @@ _MIGRATIONS_PKG = "llama_deploy.cli.config.migrations"
23
27
  _USER_VERSION_PATTERN = re.compile(r"pragma\s+user_version\s*=\s*(\d+)", re.IGNORECASE)
24
28
 
25
29
 
30
+ def _lock_file_unix(fd: int) -> None:
31
+ """Acquire exclusive lock on Unix using fcntl."""
32
+ import fcntl
33
+
34
+ fcntl.flock(fd, fcntl.LOCK_EX)
35
+
36
+
37
+ def _unlock_file_unix(fd: int) -> None:
38
+ """Release lock on Unix using fcntl."""
39
+ import fcntl
40
+
41
+ fcntl.flock(fd, fcntl.LOCK_UN)
42
+
43
+
44
+ @contextmanager
45
+ def _file_lock(lock_path: Path) -> Generator[None, None, None]:
46
+ """File lock to serialize migrations across processes.
47
+
48
+ Uses fcntl.flock on Unix. On Windows, SQLite's built-in locking provides
49
+ sufficient protection for typical CLI usage patterns.
50
+ """
51
+ if os.name == "nt":
52
+ # On Windows, rely on SQLite's own file locking
53
+ yield
54
+ return
55
+
56
+ lock_path.parent.mkdir(parents=True, exist_ok=True)
57
+ lock_file = open(lock_path, "w") # noqa: SIM115
58
+ try:
59
+ _lock_file_unix(lock_file.fileno())
60
+ yield
61
+ finally:
62
+ _unlock_file_unix(lock_file.fileno())
63
+ lock_file.close()
64
+
65
+
26
66
  def _iter_migration_files() -> list[Traversable]:
27
67
  """Yield packaged SQL migration files in lexicographic order."""
28
68
  pkg = import_module(_MIGRATIONS_PKG)
@@ -40,12 +80,8 @@ def _parse_target_version(sql_text: str) -> int | None:
40
80
  return int(match.group(1)) if match else None
41
81
 
42
82
 
43
- def run_migrations(conn: sqlite3.Connection) -> None:
44
- """Apply pending migrations found under the migrations package.
45
-
46
- Each migration file should start with a `PRAGMA user_version=N;` line.
47
- Files are applied in lexicographic order and only when N > current_version.
48
- """
83
+ def _apply_pending_migrations(conn: sqlite3.Connection) -> None:
84
+ """Apply pending migrations (internal, assumes lock is held)."""
49
85
  cur = conn.cursor()
50
86
  current_version_row = cur.execute("PRAGMA user_version").fetchone()
51
87
  current_version = int(current_version_row[0]) if current_version_row else 0
@@ -68,3 +104,20 @@ def run_migrations(conn: sqlite3.Connection) -> None:
68
104
  else:
69
105
  cur.execute("COMMIT")
70
106
  current_version = target_version
107
+
108
+
109
+ def run_migrations(conn: sqlite3.Connection, db_path: Path | None = None) -> None:
110
+ """Apply pending migrations found under the migrations package.
111
+
112
+ Each migration file should start with a `PRAGMA user_version=N;` line.
113
+ Files are applied in lexicographic order and only when N > current_version.
114
+
115
+ Uses a file lock to prevent concurrent migrations across processes when
116
+ db_path is provided.
117
+ """
118
+ if db_path is not None:
119
+ lock_path = db_path.with_suffix(".db.lock")
120
+ with _file_lock(lock_path):
121
+ _apply_pending_migrations(conn)
122
+ else:
123
+ _apply_pending_migrations(conn)
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: llamactl
3
- Version: 0.3.25
3
+ Version: 0.3.27
4
4
  Summary: A command-line interface for managing LlamaDeploy projects and deployments
5
5
  Author: Adrian Lyjak
6
6
  Author-email: Adrian Lyjak <adrianlyjak@gmail.com>
7
7
  License: MIT
8
- Requires-Dist: llama-deploy-core[client]>=0.3.25,<0.4.0
9
- Requires-Dist: llama-deploy-appserver>=0.3.25,<0.4.0
8
+ Requires-Dist: llama-deploy-core[client]>=0.3.27,<0.4.0
9
+ Requires-Dist: llama-deploy-appserver>=0.3.27,<0.4.0
10
10
  Requires-Dist: vibe-llama-core>=0.1.0
11
11
  Requires-Dist: rich>=13.0.0
12
12
  Requires-Dist: questionary>=2.0.0
@@ -10,8 +10,8 @@ llama_deploy/cli/commands/env.py,sha256=ae8f94eb2651a10615bac37afa16447ad1d78cb7
10
10
  llama_deploy/cli/commands/init.py,sha256=afdb65b5e70cfaf3bdbc923d13db1a31ad23c14605e5bcd55ddaab8fff6e69a4,17514
11
11
  llama_deploy/cli/commands/pkg.py,sha256=f91a87220c1d527e02a183dac5ca52c58608128e29bedf664362af3d2d31c461,4084
12
12
  llama_deploy/cli/commands/serve.py,sha256=c66fed8b3117c278eca2eca86eb7933ba434442d4f315c1505449580f59bfdca,12974
13
- llama_deploy/cli/config/_config.py,sha256=66ba1869d620ef2f31fa3b7d7ba38c3e3718c3dabdbe90f7ea49cbdcdfc4a951,14262
14
- llama_deploy/cli/config/_migrations.py,sha256=9b5e3b9eec692a3edb58c1f99a03d04a63bfc29dbebfc1719a5daf5a9d024738,2448
13
+ llama_deploy/cli/config/_config.py,sha256=47c7b24f9d644c1b37345f1e5b754424ac924a13c24cd16ef50e6ceb6f4c606e,14349
14
+ llama_deploy/cli/config/_migrations.py,sha256=3c5caec002e7eb226dfc451a60af8a820b4e48ccf0ce53f45f5a04a7070fc703,3969
15
15
  llama_deploy/cli/config/auth_service.py,sha256=0cf47ad032aceefc27283ce2760432e915554d544876ce471746a58692cb9249,5150
16
16
  llama_deploy/cli/config/env_service.py,sha256=cd51a68f1e9aad0bdd49cd76351cd54cea612a7f669512484c42e2876fea0458,2650
17
17
  llama_deploy/cli/config/migrations/0001_init.sql,sha256=dc9ee7439d8d79262e41f2d9f1a9306ae5b0812cc4b454167d556330f0cc578c,1092
@@ -41,7 +41,7 @@ llama_deploy/cli/utils/env_inject.py,sha256=01911758bcc3cf22aad0db0d1ade56aece48
41
41
  llama_deploy/cli/utils/redact.py,sha256=1e768d76b4a6708230c34f7ce8a5a82ab52795bb3d6ab0387071ab4e8d7e7934,863
42
42
  llama_deploy/cli/utils/retry.py,sha256=62ca6f286cb4de38cc5efcef3f376b12c2e6eb9b3e5ebe555d2a60aeb0957c19,1526
43
43
  llama_deploy/cli/utils/version.py,sha256=bf01a6dda948b868cc08c93701ed44cd36b487402404af8451d4c0996a2edb31,364
44
- llamactl-0.3.25.dist-info/WHEEL,sha256=66530aef82d5020ef5af27ae0123c71abb9261377c5bc519376c671346b12918,79
45
- llamactl-0.3.25.dist-info/entry_points.txt,sha256=b67e1eb64305058751a651a80f2d2268b5f7046732268421e796f64d4697f83c,52
46
- llamactl-0.3.25.dist-info/METADATA,sha256=d9a13b3e596b86e5eb582b5756230c2994ea9a4aec6d12be7cab534e542b1022,3329
47
- llamactl-0.3.25.dist-info/RECORD,,
44
+ llamactl-0.3.27.dist-info/WHEEL,sha256=66530aef82d5020ef5af27ae0123c71abb9261377c5bc519376c671346b12918,79
45
+ llamactl-0.3.27.dist-info/entry_points.txt,sha256=b67e1eb64305058751a651a80f2d2268b5f7046732268421e796f64d4697f83c,52
46
+ llamactl-0.3.27.dist-info/METADATA,sha256=c7f87e2a67c5269f2631fc5ef375e679bc8cb0e42f27c3ef526fb433e47f118f,3329
47
+ llamactl-0.3.27.dist-info/RECORD,,