Skip to content

Commit 40c2c45

Browse files
committed
Move plain preflight check back to plain preflight
1 parent c08e960 commit 40c2c45

File tree

6 files changed

+46
-80
lines changed

6 files changed

+46
-80
lines changed

plain-dev/plain/dev/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ This will:
3939
The `plain dev` command does several things:
4040

4141
- Sets `PLAIN_CSRF_TRUSTED_ORIGINS` to localhost by default
42-
- Runs `plain preflight check` to check for any issues
42+
- Runs `plain preflight` to check for any issues
4343
- Executes any pending model migrations
4444
- Starts `gunicorn` with `--reload`
4545
- Serves HTTPS on port 8443 by default (uses the next free port if 8443 is taken and no port is specified)
@@ -96,7 +96,7 @@ Runs:
9696
- Custom commands defined in `pyproject.toml` at `tool.plain.pre-commit.run`
9797
- `plain code check`, if [`plain.code`](https://plainframework.com/docs/plain-code/plain/code/) is installed
9898
- `uv lock --locked`, if using uv
99-
- `plain preflight check`
99+
- `plain preflight`
100100
- `plain migrate --check`
101101
- `plain makemigrations --dry-run --check`
102102
- `plain build`

plain-dev/plain/dev/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def modify_hosts_file(self) -> None:
266266

267267
def run_preflight(self) -> None:
268268
if subprocess.run(
269-
["plain", "preflight", "check", "--quiet"], env=self.plain_env
269+
["plain", "preflight", "--quiet"], env=self.plain_env
270270
).returncode:
271271
click.secho("Preflight check failed!", fg="red")
272272
sys.exit(1)

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ def cli(install: bool) -> None:
7777
if plain_db_connected():
7878
check_short(
7979
click.style("Preflight:", bold=True)
80-
+ click.style(" plain preflight check", dim=True),
80+
+ click.style(" plain preflight", dim=True),
8181
"plain",
8282
"preflight",
83-
"check",
8483
"--quiet",
8584
)
8685
check_short(
@@ -101,10 +100,9 @@ def cli(install: bool) -> None:
101100
else:
102101
check_short(
103102
click.style("Preflight:", bold=True)
104-
+ click.style(" plain preflight check", dim=True),
103+
+ click.style(" plain preflight", dim=True),
105104
"plain",
106105
"preflight",
107-
"check",
108106
"--quiet",
109107
)
110108
click.secho("--> Skipping migration checks", bold=True, fg="yellow")

plain/plain/cli/preflight.py

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,13 @@
55

66
from plain import preflight
77
from plain.packages import packages_registry
8-
from plain.preflight.registry import checks_registry
9-
from plain.runtime import settings
108

119

12-
@click.group("preflight")
13-
def preflight_cli() -> None:
14-
"""Run or manage preflight checks."""
15-
pass
16-
17-
18-
@preflight_cli.command("check")
10+
@click.command("preflight")
1911
@click.option(
2012
"--deploy",
2113
is_flag=True,
22-
help="Check deployment settings.",
14+
help="Include deployment checks.",
2315
)
2416
@click.option(
2517
"--format",
@@ -32,14 +24,13 @@ def preflight_cli() -> None:
3224
is_flag=True,
3325
help="Hide progress output and warnings, only show errors.",
3426
)
35-
def check_command(deploy: bool, format: str, quiet: bool) -> None:
27+
def preflight_cli(deploy: bool, format: str, quiet: bool) -> None:
3628
"""
37-
Use the system check framework to validate entire Plain project.
29+
Run preflight checks to validate your Plain project.
3830
Exit with error code if any errors are found. Warnings do not cause failure.
3931
"""
4032
# Auto-discover and load preflight checks
4133
packages_registry.autodiscover_modules("preflight", include_app=True)
42-
4334
if not quiet:
4435
click.secho("Running preflight checks...", dim=True, italic=True, err=True)
4536

@@ -200,48 +191,3 @@ def check_command(deploy: bool, format: str, quiet: bool) -> None:
200191
# Exit with error if there are any errors (not warnings)
201192
if has_errors:
202193
sys.exit(1)
203-
204-
205-
@preflight_cli.command("list")
206-
def list_checks() -> None:
207-
"""List all available preflight checks."""
208-
packages_registry.autodiscover_modules("preflight", include_app=True)
209-
210-
regular = []
211-
deployment = []
212-
silenced_checks = settings.PREFLIGHT_SILENCED_CHECKS
213-
214-
for name, (check_class, deploy) in sorted(checks_registry.checks.items()):
215-
# Use class docstring as description
216-
description = check_class.__doc__ or "No description"
217-
# Get first line of docstring
218-
description = description.strip().split("\n")[0]
219-
220-
is_silenced = name in silenced_checks
221-
if deploy:
222-
deployment.append((name, description, is_silenced))
223-
else:
224-
regular.append((name, description, is_silenced))
225-
226-
if regular:
227-
click.echo("Regular checks:")
228-
for name, description, is_silenced in regular:
229-
silenced_text = (
230-
click.style(" (silenced)", fg="red", dim=True) if is_silenced else ""
231-
)
232-
click.echo(
233-
f" {click.style(name)}: {click.style(description, dim=True)}{silenced_text}"
234-
)
235-
236-
if deployment:
237-
click.echo("\nDeployment checks:")
238-
for name, description, is_silenced in deployment:
239-
silenced_text = (
240-
click.style(" (silenced)", fg="red", dim=True) if is_silenced else ""
241-
)
242-
click.echo(
243-
f" {click.style(name)}: {click.style(description, dim=True)}{silenced_text}"
244-
)
245-
246-
if not regular and not deployment:
247-
click.echo("No preflight checks found.")

plain/plain/preflight/README.md

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Preflight checks help identify issues with your settings or environment before running your application.
1414

1515
```bash
16-
plain preflight check
16+
plain preflight
1717
```
1818

1919
## Development
@@ -22,31 +22,53 @@ If you use [`plain.dev`](/plain-dev/README.md) for local development, the Plain
2222

2323
## Deployment
2424

25-
The `plain preflight check` command should often be part of your deployment process. Make sure to add the `--deploy` flag to the command to run checks that are only relevant in a production environment.
25+
The `plain preflight` command should often be part of your deployment process. Make sure to add the `--deploy` flag to the command to run checks that are only relevant in a production environment.
2626

2727
```bash
28-
plain preflight check --deploy
28+
plain preflight --deploy
2929
```
3030

3131
## Custom preflight checks
3232

33-
Use the `@register_check` decorator to add your own preflight check to the system. Just make sure that particular Python module is somehow imported so the check registration runs.
33+
Use the `@register_check` decorator to add your own preflight check to the system. Create a class that inherits from `PreflightCheck` and implements a `run()` method that returns a list of `PreflightResult` objects.
3434

3535
```python
36-
from plain.preflight import register_check, Error
37-
38-
39-
@register_check
40-
def custom_check(package_configs, **kwargs):
41-
return Error("This is a custom error message.", id="custom.C001")
36+
from plain.preflight import PreflightCheck, PreflightResult, register_check
37+
38+
39+
@register_check("custom.example")
40+
class CustomCheck(PreflightCheck):
41+
"""Description of what this check validates."""
42+
43+
def run(self) -> list[PreflightResult]:
44+
# Your check logic here
45+
if some_condition:
46+
return [
47+
PreflightResult(
48+
fix="This is a custom error message.",
49+
id="custom.example_failed",
50+
)
51+
]
52+
return []
4253
```
4354

44-
For deployment-specific checks, add the `deploy` argument to the decorator.
55+
For deployment-specific checks, add `deploy=True` to the decorator.
4556

4657
```python
47-
@register_check(deploy=True)
48-
def custom_deploy_check(package_configs, **kwargs):
49-
return Error("This is a custom error message for deployment.", id="custom.D001")
58+
@register_check("custom.deploy_example", deploy=True)
59+
class CustomDeployCheck(PreflightCheck):
60+
"""Description of what this deployment check validates."""
61+
62+
def run(self) -> list[PreflightResult]:
63+
# Your deployment check logic here
64+
if some_deploy_condition:
65+
return [
66+
PreflightResult(
67+
fix="This is a custom error message for deployment.",
68+
id="custom.deploy_example_failed",
69+
)
70+
]
71+
return []
5072
```
5173

5274
## Silencing preflight checks

scripts/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ echo "${BOLD}Running tests${NORMAL}"
1515

1616
echo ""
1717
echo "${BOLD}Running preflight in example${NORMAL}"
18-
cd example && DATABASE_URL=sqlite://:memory: uv run plain preflight check
18+
cd example && DATABASE_URL=sqlite://:memory: uv run plain preflight

0 commit comments

Comments
 (0)