Skip to content

Commit 8809012

Browse files
committed
Change bolt code to check and fix, add to precommit, re-use print_event
1 parent fad6c58 commit 8809012

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

bolt-code/bolt/code/cli.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import click
77

8+
from bolt.cli.print import print_event
9+
810
DEFAULT_RUFF_CONFIG = Path(__file__).parent / "ruff_defaults.toml"
911

1012

@@ -16,35 +18,22 @@ def cli():
1618

1719
@cli.command()
1820
@click.argument("path", default=".")
19-
@click.option("--fix/--no-fix", "do_fix", default=False)
20-
def lint(path, do_fix):
21+
def check(path):
22+
"""Check the given path for formatting or linting issues."""
2123
ruff_args = []
2224

2325
if not user_has_ruff_config():
24-
click.secho("Using default bolt.code ruff config", italic=True, bold=True)
26+
click.secho("Using default bolt.code ruff config", italic=True)
2527
ruff_args.extend(["--config", str(DEFAULT_RUFF_CONFIG)])
2628

27-
if do_fix:
28-
ruff_args.append("--fix")
29-
30-
click.secho("Ruff check", bold=True)
29+
print_event("Ruff check")
3130
result = subprocess.run(["ruff", "check", path, *ruff_args])
3231

3332
if result.returncode != 0:
3433
sys.exit(result.returncode)
3534

36-
37-
@cli.command()
38-
@click.argument("path", default=".")
39-
def format(path):
40-
ruff_args = []
41-
42-
if not user_has_ruff_config():
43-
click.secho("Using default bolt.code ruff config", italic=True, bold=True)
44-
ruff_args.extend(["--config", str(DEFAULT_RUFF_CONFIG)])
45-
46-
click.secho("Ruff format", bold=True)
47-
result = subprocess.run(["ruff", "format", path, *ruff_args])
35+
print_event("Ruff format check")
36+
result = subprocess.run(["ruff", "format", path, "--check", *ruff_args])
4837

4938
if result.returncode != 0:
5039
sys.exit(result.returncode)
@@ -57,16 +46,16 @@ def fix(path):
5746
ruff_args = []
5847

5948
if not user_has_ruff_config():
60-
click.secho("Using default bolt.code ruff config", italic=True, bold=True)
49+
click.secho("Using default bolt.code ruff config", italic=True)
6150
ruff_args.extend(["--config", str(DEFAULT_RUFF_CONFIG)])
6251

63-
click.secho("Ruff check", bold=True)
52+
print_event("Ruff check")
6453
result = subprocess.run(["ruff", "check", path, "--fix", *ruff_args])
6554

6655
if result.returncode != 0:
6756
sys.exit(result.returncode)
6857

69-
click.secho("Ruff format", bold=True)
58+
print_event("Ruff format")
7059
result = subprocess.run(["ruff", "format", path, *ruff_args])
7160

7261
if result.returncode != 0:

bolt-dev/bolt/dev/precommit/cli.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from importlib.util import find_spec
55
from pathlib import Path
66

7+
from bolt.cli.print import print_event
8+
79
try:
810
import tomllib
911
except ModuleNotFoundError:
@@ -51,6 +53,11 @@ def cli(install):
5153
if result.returncode != 0:
5254
sys.exit(result.returncode)
5355

56+
# Run this first since it's probably the most likely to fail
57+
if find_spec("bolt.code"):
58+
print_event("Running bolt code checks")
59+
subprocess.check_call(["bolt", "code", "check"])
60+
5461
check_short("Checking .env files for changes", "bolt", "env", "check")
5562

5663
if Path("poetry.lock").exists():
@@ -99,14 +106,6 @@ def bolt_db_connected():
99106
return result.returncode == 0
100107

101108

102-
def print_event(msg, newline=True):
103-
arrow = click.style("-->", fg=214, bold=True)
104-
message = str(msg)
105-
if not newline:
106-
message += " "
107-
click.secho(f"{arrow} {message}", nl=newline)
108-
109-
110109
def check_short(message, *args):
111110
print_event(message, newline=False)
112111
result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

bolt/cli/print.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import click
2+
3+
4+
def print_event(msg, newline=True):
5+
arrow = click.style("-->", fg=214, bold=True)
6+
message = str(msg)
7+
if not newline:
8+
message += " "
9+
click.secho(f"{arrow} {message}", nl=newline)

0 commit comments

Comments
 (0)