Skip to content

Commit b09edfd

Browse files
committed
print_event usage and styling
1 parent 89f88ec commit b09edfd

File tree

5 files changed

+32
-96
lines changed

5 files changed

+32
-96
lines changed

plain-code/plain/code/cli.py

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,16 @@ def maybe_exit(return_code: int) -> None:
102102
sys.exit(return_code)
103103

104104
if not skip_ruff:
105-
print_event(
106-
click.style("Ruff lint:", bold=True) + click.style(" ruff check", dim=True)
107-
)
105+
print_event("ruff check...", newline=False)
108106
result = subprocess.run(["ruff", "check", path, *ruff_args])
109107
maybe_exit(result.returncode)
110108

111-
print_event(
112-
click.style("Ruff format:", bold=True)
113-
+ click.style(" ruff format --check", dim=True)
114-
)
109+
print_event("ruff format --check...", newline=False)
115110
result = subprocess.run(["ruff", "format", path, "--check", *ruff_args])
116111
maybe_exit(result.returncode)
117112

118113
if not skip_ty and config.get("ty", {}).get("enabled", True):
119-
print_event(click.style("Ty:", bold=True) + click.style(" ty check", dim=True))
114+
print_event("ty check...", newline=False)
120115
result = subprocess.run(["ty", "check", path])
121116
maybe_exit(result.returncode)
122117

@@ -126,9 +121,7 @@ def maybe_exit(return_code: int) -> None:
126121
if biome.needs_update():
127122
ctx.invoke(install)
128123

129-
print_event(
130-
click.style("Biome:", bold=True) + click.style(" biome check", dim=True)
131-
)
124+
print_event("biome check...")
132125
result = biome.invoke("check", path)
133126
maybe_exit(result.returncode)
134127

@@ -153,32 +146,21 @@ def fix(ctx: click.Context, path: str, unsafe_fixes: bool, add_noqa: bool) -> No
153146
raise click.UsageError("Cannot use both --unsafe-fixes and --add-noqa")
154147

155148
if unsafe_fixes:
156-
print_event(
157-
click.style("Ruff lint:", bold=True)
158-
+ click.style(" ruff check --fix --unsafe-fixes", dim=True)
159-
)
149+
print_event("ruff check --fix --unsafe-fixes...", newline=False)
160150
result = subprocess.run(
161151
["ruff", "check", path, "--fix", "--unsafe-fixes", *ruff_args]
162152
)
163153
elif add_noqa:
164-
print_event(
165-
click.style("Ruff lint:", bold=True)
166-
+ click.style(" ruff check --add-noqa", dim=True)
167-
)
154+
print_event("ruff check --add-noqa...", newline=False)
168155
result = subprocess.run(["ruff", "check", path, "--add-noqa", *ruff_args])
169156
else:
170-
print_event(
171-
click.style("Ruff lint:", bold=True)
172-
+ click.style(" ruff check --fix", dim=True)
173-
)
157+
print_event("ruff check --fix...", newline=False)
174158
result = subprocess.run(["ruff", "check", path, "--fix", *ruff_args])
175159

176160
if result.returncode != 0:
177161
sys.exit(result.returncode)
178162

179-
print_event(
180-
click.style("Ruff format:", bold=True) + click.style(" ruff format", dim=True)
181-
)
163+
print_event("ruff format...", newline=False)
182164
result = subprocess.run(["ruff", "format", path, *ruff_args])
183165
if result.returncode != 0:
184166
sys.exit(result.returncode)
@@ -193,15 +175,9 @@ def fix(ctx: click.Context, path: str, unsafe_fixes: bool, add_noqa: bool) -> No
193175

194176
if unsafe_fixes:
195177
args.append("--unsafe")
196-
print_event(
197-
click.style("Biome:", bold=True)
198-
+ click.style(" biome check --write --unsafe", dim=True)
199-
)
178+
print_event("biome check --write --unsafe...")
200179
else:
201-
print_event(
202-
click.style("Biome:", bold=True)
203-
+ click.style(" biome check --write", dim=True)
204-
)
180+
print_event("biome check --write...")
205181

206182
result = biome.invoke(*args)
207183

plain-dev/plain/dev/core.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from rich.console import Console
1414
from rich.text import Text
1515

16+
from plain.cli.print import print_event
1617
from plain.runtime import APP_PATH, PLAIN_TEMP_PATH
1718

1819
from .mkcert import MkcertManager
@@ -140,7 +141,7 @@ def run(self) -> int:
140141
self.generate_agents_md()
141142
self.modify_hosts_file()
142143

143-
click.secho("→ Running preflight checks... ", dim=True, nl=False)
144+
print_event("Running preflight checks...", newline=False)
144145
self.run_preflight()
145146

146147
# if ServicesProcess.running_pid():
@@ -150,20 +151,21 @@ def run(self) -> int:
150151
# )
151152

152153
if find_spec("plain.models"):
153-
click.secho("→ Waiting for database... ", dim=True, nl=False)
154+
print_event("Waiting for database...", newline=False)
154155
subprocess.run(
155156
[sys.executable, "-m", "plain", "db", "wait"],
156157
env=self.plain_env,
157158
check=True,
158159
)
159-
click.secho("→ Running migrations...", dim=True)
160+
print_event("Running migrations...")
160161
subprocess.run(
161162
[sys.executable, "-m", "plain", "migrate", "--backup"],
162163
env=self.plain_env,
163164
check=True,
164165
)
165166

166-
click.secho("\n→ Starting app...", dim=True)
167+
click.echo()
168+
print_event("Starting app...")
167169

168170
# Manually start the status bar now so it isn't bungled by
169171
# another thread checking db stuff...

plain-dev/plain/dev/precommit/cli.py

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -58,77 +58,36 @@ def run_checks() -> None:
5858
.get("run", {})
5959
).items():
6060
cmd = data["cmd"]
61-
print_event(
62-
click.style(f"Custom[{name}]:", bold=True)
63-
+ click.style(f" {cmd}", dim=True),
64-
newline=False,
65-
)
61+
print_event(f"Custom: {cmd}")
6662
result = subprocess.run(cmd, shell=True)
6763
if result.returncode != 0:
6864
sys.exit(result.returncode)
6965

7066
# Run this first since it's probably the most likely to fail
7167
if find_spec("plain.code"):
72-
check_short(
73-
click.style("Code:", bold=True)
74-
+ click.style(" plain code check", dim=True),
75-
"plain",
76-
"code",
77-
"check",
78-
)
68+
check_short("plain code check", "plain", "code", "check")
7969

8070
if Path("uv.lock").exists():
81-
check_short(
82-
click.style("Dependencies:", bold=True)
83-
+ click.style(" uv lock --check", dim=True),
84-
"uv",
85-
"lock",
86-
"--check",
87-
)
71+
check_short("uv lock --check", "uv", "lock", "--check")
8872

8973
if plain_db_connected():
74+
check_short("plain preflight", "plain", "preflight", "--quiet")
75+
check_short("plain migrate --check", "plain", "migrate", "--check")
9076
check_short(
91-
click.style("Preflight:", bold=True)
92-
+ click.style(" plain preflight", dim=True),
93-
"plain",
94-
"preflight",
95-
"--quiet",
96-
)
97-
check_short(
98-
click.style("Migrate:", bold=True)
99-
+ click.style(" plain migrate --check", dim=True),
100-
"plain",
101-
"migrate",
102-
"--check",
103-
)
104-
check_short(
105-
click.style("Migrations:", bold=True)
106-
+ click.style(" plain makemigrations --dry-run --check", dim=True),
77+
"plain makemigrations --dry-run --check",
10778
"plain",
10879
"makemigrations",
10980
"--dry-run",
11081
"--check",
11182
)
11283
else:
113-
check_short(
114-
click.style("Preflight:", bold=True)
115-
+ click.style(" plain preflight", dim=True),
116-
"plain",
117-
"preflight",
118-
"--quiet",
119-
)
84+
check_short("plain preflight", "plain", "preflight", "--quiet")
12085
click.secho("--> Skipping migration checks", bold=True, fg="yellow")
12186

122-
check_short(
123-
click.style("Build:", bold=True) + click.style(" plain build", dim=True),
124-
"plain",
125-
"build",
126-
)
87+
check_short("plain build", "plain", "build")
12788

12889
if find_spec("plain.pytest"):
129-
print_event(
130-
click.style("Test:", bold=True) + click.style(" plain test", dim=True)
131-
)
90+
print_event("plain test")
13291
result = subprocess.run(["plain", "test"])
13392
if result.returncode != 0:
13493
sys.exit(result.returncode)

plain/plain/cli/build.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import plain.runtime
1111
from plain.assets.compile import compile_assets, get_compiled_path
12+
from plain.cli.print import print_event
1213

1314

1415
@click.command()
@@ -54,18 +55,16 @@ def build(keep_original: bool, fingerprint: bool, compress: bool) -> None:
5455
.get("run", {})
5556
.items()
5657
):
57-
click.secho(f"Running {name} from pyproject.toml", bold=True)
58+
print_event(f"{name}...")
5859
result = subprocess.run(data["cmd"], shell=True)
59-
print()
6060
if result.returncode:
6161
click.secho(f"Error in {name} (exit {result.returncode})", fg="red")
6262
sys.exit(result.returncode)
6363

6464
# Then run installed package build steps (like tailwind, typically should run last...)
6565
for entry_point in entry_points(group="plain.build"):
66-
click.secho(f"Running {entry_point.name}", bold=True)
67-
result = entry_point.load()()
68-
print()
66+
print_event(f"{entry_point.name}...")
67+
entry_point.load()()
6968

7069
# Compile our assets
7170
target_dir = get_compiled_path()

plain/plain/cli/print.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33

44
def print_event(msg: str, newline: bool = True) -> None:
5-
arrow = click.style("-->", fg=214, bold=True)
6-
message = str(msg)
5+
arrow = click.style("-->", fg=214, bold=True, dim=True)
6+
message = click.style(msg, dim=True)
77
if not newline:
88
message += " "
9-
click.secho(f"{arrow} {message}", nl=newline)
9+
click.echo(f"{arrow} {message}", nl=newline)

0 commit comments

Comments
 (0)