|
6 | 6 |
|
7 | 7 | from bolt.cli.print import print_event
|
8 | 8 |
|
| 9 | +from ..services import Services |
| 10 | + |
9 | 11 | try:
|
10 | 12 | import tomllib
|
11 | 13 | except ModuleNotFoundError:
|
@@ -38,60 +40,63 @@ def cli(install):
|
38 | 40 |
|
39 | 41 | pyproject = Path("pyproject.toml")
|
40 | 42 |
|
41 |
| - if pyproject.exists(): |
42 |
| - with open(pyproject, "rb") as f: |
43 |
| - pyproject = tomllib.load(f) |
44 |
| - for name, data in ( |
45 |
| - pyproject.get("tool", {}) |
46 |
| - .get("bolt", {}) |
47 |
| - .get("pre-commit", {}) |
48 |
| - .get("run", {}) |
49 |
| - ).items(): |
50 |
| - cmd = data["cmd"] |
51 |
| - print_event(f"Custom: {name} -> {cmd}") |
52 |
| - result = subprocess.run(cmd, shell=True) |
53 |
| - if result.returncode != 0: |
54 |
| - sys.exit(result.returncode) |
55 |
| - |
56 |
| - # Run this first since it's probably the most likely to fail |
57 |
| - if find_spec("bolt.code"): |
58 |
| - check_short("Running bolt code checks", "bolt", "code", "check") |
59 |
| - |
60 |
| - if Path("poetry.lock").exists(): |
61 |
| - check_short("Checking poetry.lock", "poetry", "lock", "--check") |
62 |
| - |
63 |
| - if bolt_db_connected(): |
64 |
| - check_short( |
65 |
| - "Running preflight checks", |
66 |
| - "bolt", |
67 |
| - "preflight", |
68 |
| - "--database", |
69 |
| - "default", |
70 |
| - ) |
71 |
| - check_short("Checking Bolt migrations", "bolt", "legacy", "migrate", "--check") |
72 |
| - check_short( |
73 |
| - "Checking for Bolt models missing migrations", |
74 |
| - "bolt", |
75 |
| - "legacy", |
76 |
| - "makemigrations", |
77 |
| - "--dry-run", |
78 |
| - "--check", |
79 |
| - ) |
80 |
| - else: |
81 |
| - check_short("Running Bolt checks (without database)", "bolt", "preflight") |
82 |
| - click.secho("--> Skipping migration checks", bold=True, fg="yellow") |
83 |
| - |
84 |
| - print_event("Running bolt compile") |
85 |
| - result = subprocess.run(["bolt", "compile"]) |
86 |
| - if result.returncode != 0: |
87 |
| - sys.exit(result.returncode) |
| 43 | + with Services(): |
| 44 | + if pyproject.exists(): |
| 45 | + with open(pyproject, "rb") as f: |
| 46 | + pyproject = tomllib.load(f) |
| 47 | + for name, data in ( |
| 48 | + pyproject.get("tool", {}) |
| 49 | + .get("bolt", {}) |
| 50 | + .get("pre-commit", {}) |
| 51 | + .get("run", {}) |
| 52 | + ).items(): |
| 53 | + cmd = data["cmd"] |
| 54 | + print_event(f"Custom: {name} -> {cmd}") |
| 55 | + result = subprocess.run(cmd, shell=True) |
| 56 | + if result.returncode != 0: |
| 57 | + sys.exit(result.returncode) |
| 58 | + |
| 59 | + # Run this first since it's probably the most likely to fail |
| 60 | + if find_spec("bolt.code"): |
| 61 | + check_short("Running bolt code checks", "bolt", "code", "check") |
| 62 | + |
| 63 | + if Path("poetry.lock").exists(): |
| 64 | + check_short("Checking poetry.lock", "poetry", "lock", "--check") |
| 65 | + |
| 66 | + if bolt_db_connected(): |
| 67 | + check_short( |
| 68 | + "Running preflight checks", |
| 69 | + "bolt", |
| 70 | + "preflight", |
| 71 | + "--database", |
| 72 | + "default", |
| 73 | + ) |
| 74 | + check_short( |
| 75 | + "Checking Bolt migrations", "bolt", "legacy", "migrate", "--check" |
| 76 | + ) |
| 77 | + check_short( |
| 78 | + "Checking for Bolt models missing migrations", |
| 79 | + "bolt", |
| 80 | + "legacy", |
| 81 | + "makemigrations", |
| 82 | + "--dry-run", |
| 83 | + "--check", |
| 84 | + ) |
| 85 | + else: |
| 86 | + check_short("Running Bolt checks (without database)", "bolt", "preflight") |
| 87 | + click.secho("--> Skipping migration checks", bold=True, fg="yellow") |
88 | 88 |
|
89 |
| - if find_spec("bolt.pytest"): |
90 |
| - print_event("Running tests") |
91 |
| - result = subprocess.run(["bolt", "test"]) |
| 89 | + print_event("Running bolt compile") |
| 90 | + result = subprocess.run(["bolt", "compile"]) |
92 | 91 | if result.returncode != 0:
|
93 | 92 | sys.exit(result.returncode)
|
94 | 93 |
|
| 94 | + if find_spec("bolt.pytest"): |
| 95 | + print_event("Running tests") |
| 96 | + result = subprocess.run(["bolt", "test"]) |
| 97 | + if result.returncode != 0: |
| 98 | + sys.exit(result.returncode) |
| 99 | + |
95 | 100 |
|
96 | 101 | def bolt_db_connected():
|
97 | 102 | result = subprocess.run(
|
|
0 commit comments