plain 0.67.0__py3-none-any.whl → 0.68.0__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.
plain/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # plain changelog
2
2
 
3
+ ## [0.68.0](https://github.com/dropseed/plain/releases/plain@0.68.0) (2025-09-25)
4
+
5
+ ### What's changed
6
+
7
+ - Major refactor of the preflight check system with new CLI commands and improved output ([b0b610d461](https://github.com/dropseed/plain/commit/b0b610d461))
8
+ - Preflight checks now use descriptive IDs instead of numeric codes ([cd96c97b25](https://github.com/dropseed/plain/commit/cd96c97b25))
9
+ - Unified preflight error messages and hints into a single `fix` field ([c7cde12149](https://github.com/dropseed/plain/commit/c7cde12149))
10
+ - Added `plain-upgrade` as a standalone command for upgrading Plain packages ([42f2eed80c](https://github.com/dropseed/plain/commit/42f2eed80c))
11
+
12
+ ### Upgrade instructions
13
+
14
+ - Use `plain preflight check` instead of `plain preflight` to run all checks
15
+ - Custom preflight checks should be class based, extending `PreflightCheck` and implementing the `run()` method
16
+ - Preflight checks need to be registered with a custom name (ex. `@register_check("app.my_custom_check")`) and optionally with `deploy=True` if it should run in only in deploy mode
17
+ - Preflight results should use `PreflightResult` (optionally with `warning=True`) instead of `preflight.Warning` or `preflight.Error`
18
+ - Preflight result IDs should be descriptive strings (e.g., `models.lazy_reference_resolution_failed`) instead of numeric codes
19
+ - `PREFLIGHT_SILENCED_CHECKS` setting has been replaced with `PREFLIGHT_SILENCED_RESULTS` which should contain a list of result IDs to silence. `PREFLIGHT_SILENCED_CHECKS` now silences entire checks by name.
20
+
3
21
  ## [0.67.0](https://github.com/dropseed/plain/releases/plain@0.67.0) (2025-09-22)
4
22
 
5
23
  ### What's changed
plain/chores/registry.py CHANGED
@@ -1,6 +1,3 @@
1
- from importlib import import_module
2
- from importlib.util import find_spec
3
-
4
1
  from plain.packages import packages_registry
5
2
 
6
3
 
@@ -35,21 +32,7 @@ class ChoresRegistry:
35
32
  """
36
33
  Import modules from installed packages and app to trigger registration.
37
34
  """
38
- # Import from installed packages
39
- for package_config in packages_registry.get_package_configs():
40
- import_name = f"{package_config.name}.chores"
41
- try:
42
- import_module(import_name)
43
- except ModuleNotFoundError:
44
- pass
45
-
46
- # Import from app
47
- import_name = "app.chores"
48
- if find_spec(import_name):
49
- try:
50
- import_module(import_name)
51
- except ModuleNotFoundError:
52
- pass
35
+ packages_registry.autodiscover_modules("chores", include_app=True)
53
36
 
54
37
  def get_chores(self):
55
38
  """
plain/cli/core.py CHANGED
@@ -13,7 +13,7 @@ from .chores import chores
13
13
  from .docs import docs
14
14
  from .formatting import PlainContext
15
15
  from .install import install
16
- from .preflight import preflight_checks
16
+ from .preflight import preflight_cli
17
17
  from .registry import cli_registry
18
18
  from .scaffold import create
19
19
  from .settings import setting
@@ -30,7 +30,7 @@ def plain_cli():
30
30
 
31
31
  plain_cli.add_command(agent)
32
32
  plain_cli.add_command(docs)
33
- plain_cli.add_command(preflight_checks)
33
+ plain_cli.add_command(preflight_cli)
34
34
  plain_cli.add_command(create)
35
35
  plain_cli.add_command(chores)
36
36
  plain_cli.add_command(build)
plain/cli/preflight.py CHANGED
@@ -1,126 +1,247 @@
1
+ import json
2
+ import sys
3
+
1
4
  import click
2
5
 
3
6
  from plain import preflight
4
7
  from plain.packages import packages_registry
8
+ from plain.preflight.registry import checks_registry
9
+ from plain.runtime import settings
10
+
11
+
12
+ @click.group("preflight")
13
+ def preflight_cli():
14
+ """Run or manage preflight checks."""
15
+ pass
5
16
 
6
17
 
7
- @click.command("preflight")
8
- @click.argument("package_label", nargs=-1)
18
+ @preflight_cli.command("check")
9
19
  @click.option(
10
20
  "--deploy",
11
21
  is_flag=True,
12
22
  help="Check deployment settings.",
13
23
  )
14
24
  @click.option(
15
- "--fail-level",
16
- default="ERROR",
17
- type=click.Choice(["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]),
18
- help="Message level that will cause the command to exit with a non-zero status. Default is ERROR.",
25
+ "--format",
26
+ default="text",
27
+ type=click.Choice(["text", "json"]),
28
+ help="Output format (default: text)",
19
29
  )
20
30
  @click.option(
21
- "--database",
31
+ "--quiet",
22
32
  is_flag=True,
23
- help="Run database related checks as part of preflight.",
33
+ help="Hide progress output and warnings, only show errors.",
24
34
  )
25
- def preflight_checks(package_label, deploy, fail_level, database):
35
+ def check_command(deploy, format, quiet):
26
36
  """
27
37
  Use the system check framework to validate entire Plain project.
28
- Raise CommandError for any serious message (error or critical errors).
29
- If there are only light messages (like warnings), print them to stderr
30
- and don't raise an exception.
38
+ Exit with error code if any errors are found. Warnings do not cause failure.
31
39
  """
32
- include_deployment_checks = deploy
40
+ # Auto-discover and load preflight checks
41
+ packages_registry.autodiscover_modules("preflight", include_app=True)
33
42
 
34
- if package_label:
35
- package_configs = [
36
- packages_registry.get_package_config(label) for label in package_label
37
- ]
38
- else:
39
- package_configs = None
43
+ if not quiet:
44
+ click.secho("Running preflight checks...", dim=True, italic=True, err=True)
40
45
 
41
- all_issues = preflight.run_checks(
42
- package_configs=package_configs,
43
- include_deployment_checks=include_deployment_checks,
44
- database=database,
45
- )
46
+ total_checks = 0
47
+ passed_checks = 0
48
+ check_results = []
49
+
50
+ # Run checks and collect results
51
+ for check_class, check_name, issues in preflight.run_checks(
52
+ include_deploy_checks=deploy,
53
+ ):
54
+ total_checks += 1
55
+
56
+ # Filter out silenced issues
57
+ visible_issues = [issue for issue in issues if not issue.is_silenced()]
58
+
59
+ # For text format, show real-time progress
60
+ if format == "text":
61
+ if not quiet:
62
+ # Print check name without newline
63
+ click.echo("Check:", nl=False, err=True)
64
+ click.secho(f"{check_name} ", bold=True, nl=False, err=True)
46
65
 
47
- header, body, footer = "", "", ""
48
- visible_issue_count = 0 # excludes silenced warnings
49
-
50
- if all_issues:
51
- debugs = [
52
- e for e in all_issues if e.level < preflight.INFO and not e.is_silenced()
53
- ]
54
- infos = [
55
- e
56
- for e in all_issues
57
- if preflight.INFO <= e.level < preflight.WARNING and not e.is_silenced()
58
- ]
59
- warnings = [
60
- e
61
- for e in all_issues
62
- if preflight.WARNING <= e.level < preflight.ERROR and not e.is_silenced()
63
- ]
64
- errors = [
65
- e
66
- for e in all_issues
67
- if preflight.ERROR <= e.level < preflight.CRITICAL and not e.is_silenced()
68
- ]
69
- criticals = [
70
- e
71
- for e in all_issues
72
- if preflight.CRITICAL <= e.level and not e.is_silenced()
73
- ]
74
- sorted_issues = [
75
- (criticals, "CRITICALS"),
76
- (errors, "ERRORS"),
77
- (warnings, "WARNINGS"),
78
- (infos, "INFOS"),
79
- (debugs, "DEBUGS"),
80
- ]
81
-
82
- for issues, group_name in sorted_issues:
83
- if issues:
84
- visible_issue_count += len(issues)
85
- formatted = (
86
- click.style(str(e), fg="red")
87
- if e.is_serious()
88
- else click.style(str(e), fg="yellow")
89
- for e in issues
66
+ # Determine status icon based on issue severity
67
+ if not visible_issues:
68
+ # No issues - passed
69
+ if not quiet:
70
+ click.secho("✔", fg="green", err=True)
71
+ passed_checks += 1
72
+ else:
73
+ # Has issues - determine icon based on highest severity
74
+ has_errors = any(not issue.warning for issue in visible_issues)
75
+ if not quiet:
76
+ if has_errors:
77
+ click.secho("✗", fg="red", err=True)
78
+ else:
79
+ click.secho("⚠", fg="yellow", err=True)
80
+
81
+ # Print issues with simple indentation
82
+ issues_to_show = (
83
+ visible_issues
84
+ if not quiet
85
+ else [issue for issue in visible_issues if not issue.warning]
90
86
  )
91
- formatted = "\n".join(sorted(formatted))
92
- body += f"\n{group_name}:\n{formatted}\n"
87
+ for i, issue in enumerate(issues_to_show):
88
+ issue_color = "red" if not issue.warning else "yellow"
89
+ issue_type = "ERROR" if not issue.warning else "WARNING"
93
90
 
94
- if visible_issue_count:
95
- header = "Preflight check identified some issues:\n"
91
+ if quiet:
92
+ # In quiet mode, show check name once, then issues
93
+ if i == 0:
94
+ click.secho(f"{check_name}:", err=True)
95
+ # Show ID and fix on separate lines with same indentation
96
+ click.secho(
97
+ f" [{issue_type}] {issue.id}:",
98
+ fg=issue_color,
99
+ bold=True,
100
+ err=True,
101
+ nl=False,
102
+ )
103
+ click.secho(f" {issue.fix}", err=True, dim=True)
104
+ else:
105
+ # Show ID and fix on separate lines with same indentation
106
+ click.secho(
107
+ f" [{issue_type}] {issue.id}: ",
108
+ fg=issue_color,
109
+ bold=True,
110
+ err=True,
111
+ nl=False,
112
+ )
113
+ click.secho(f"{issue.fix}", err=True, dim=True)
114
+ else:
115
+ # For JSON format, just count passed checks
116
+ if not visible_issues:
117
+ passed_checks += 1
96
118
 
97
- if any(
98
- e.is_serious(getattr(preflight, fail_level)) and not e.is_silenced()
99
- for e in all_issues
100
- ):
101
- footer += "\n"
102
- footer += "Preflight check identified {} ({} silenced).".format(
103
- "no issues"
104
- if visible_issue_count == 0
105
- else "1 issue"
106
- if visible_issue_count == 1
107
- else f"{visible_issue_count} issues",
108
- len(all_issues) - visible_issue_count,
109
- )
110
- msg = click.style(f"SystemCheckError: {header}", fg="red") + body + footer
111
- raise click.ClickException(msg)
119
+ check_results.append((check_class, check_name, issues))
120
+
121
+ # Output results based on format
122
+
123
+ # Get all issues from check_results instead of maintaining separate list
124
+ all_issues = [issue for _, _, issues in check_results for issue in issues]
125
+ # Errors (non-warnings) cause preflight to fail
126
+ has_errors = any(
127
+ not issue.warning and not issue.is_silenced() for issue in all_issues
128
+ )
129
+
130
+ if format == "json":
131
+ # Build JSON output
132
+ results = {"passed": not has_errors, "checks": []}
133
+
134
+ for check_class, check_name, issues in check_results:
135
+ visible_issues = [issue for issue in issues if not issue.is_silenced()]
136
+
137
+ check_result = {
138
+ "name": check_name,
139
+ "passed": len(visible_issues) == 0,
140
+ "issues": [],
141
+ }
142
+
143
+ for issue in visible_issues:
144
+ issue_data = {
145
+ "id": issue.id,
146
+ "warning": issue.warning,
147
+ "fix": issue.fix,
148
+ "obj": str(issue.obj) if issue.obj is not None else None,
149
+ }
150
+ check_result["issues"].append(issue_data)
151
+
152
+ results["checks"].append(check_result)
153
+
154
+ click.echo(json.dumps(results, indent=2))
112
155
  else:
113
- if visible_issue_count:
114
- footer += "\n"
115
- footer += "Preflight check identified {} ({} silenced).".format(
116
- "no issues"
117
- if visible_issue_count == 0
118
- else "1 issue"
119
- if visible_issue_count == 1
120
- else f"{visible_issue_count} issues",
121
- len(all_issues) - visible_issue_count,
156
+ # Text format summary
157
+ if not quiet:
158
+ click.echo()
159
+
160
+ # Calculate warning and error counts
161
+ warning_count = sum(
162
+ 1
163
+ for _, _, issues in check_results
164
+ if issues
165
+ and not any(
166
+ not issue.warning for issue in issues if not issue.is_silenced()
122
167
  )
123
- msg = header + body + footer
124
- click.echo(msg, err=True)
168
+ )
169
+ error_count = sum(
170
+ 1
171
+ for _, _, issues in check_results
172
+ if issues
173
+ and any(not issue.warning for issue in issues if not issue.is_silenced())
174
+ )
175
+
176
+ # Build colored summary parts
177
+ summary_parts = []
178
+
179
+ if passed_checks > 0:
180
+ summary_parts.append(click.style(f"{passed_checks} passed", fg="green"))
181
+
182
+ if warning_count > 0:
183
+ summary_parts.append(click.style(f"{warning_count} warnings", fg="yellow"))
184
+
185
+ if error_count > 0:
186
+ summary_parts.append(click.style(f"{error_count} errors", fg="red"))
187
+
188
+ # Show checkmark if successful (no errors)
189
+ if not has_errors:
190
+ icon = click.style("✔ ", fg="green")
191
+ summary_color = "green"
125
192
  else:
126
- click.secho("✔ Checks passed", err=True, fg="green")
193
+ icon = ""
194
+ summary_color = None
195
+
196
+ summary_text = ", ".join(summary_parts) if summary_parts else "no issues"
197
+
198
+ click.secho(f"{icon}{summary_text}", fg=summary_color, err=True)
199
+
200
+ # Exit with error if there are any errors (not warnings)
201
+ if has_errors:
202
+ sys.exit(1)
203
+
204
+
205
+ @preflight_cli.command("list")
206
+ def list_checks():
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/cli/registry.py CHANGED
@@ -1,6 +1,3 @@
1
- from importlib import import_module
2
- from importlib.util import find_spec
3
-
4
1
  from plain.packages import packages_registry
5
2
 
6
3
 
@@ -18,21 +15,7 @@ class CLIRegistry:
18
15
  """
19
16
  Import modules from installed packages and app to trigger registration.
20
17
  """
21
- # Import from installed packages
22
- for package_config in packages_registry.get_package_configs():
23
- import_name = f"{package_config.name}.cli"
24
- try:
25
- import_module(import_name)
26
- except ModuleNotFoundError:
27
- pass
28
-
29
- # Import from app
30
- import_name = "app.cli"
31
- if find_spec(import_name):
32
- try:
33
- import_module(import_name)
34
- except ModuleNotFoundError:
35
- pass
18
+ packages_registry.autodiscover_modules("cli", include_app=True)
36
19
 
37
20
  def get_commands(self):
38
21
  """
@@ -2,6 +2,7 @@ import sys
2
2
  import threading
3
3
  from collections import Counter
4
4
  from importlib import import_module
5
+ from importlib.util import find_spec
5
6
 
6
7
  from plain.exceptions import ImproperlyConfigured, PackageRegistryNotReady
7
8
 
@@ -188,6 +189,19 @@ class PackagesRegistry:
188
189
 
189
190
  return package_config
190
191
 
192
+ def autodiscover_modules(self, module_name: str, *, include_app: bool) -> None:
193
+ def _import_if_exists(name):
194
+ if find_spec(name):
195
+ import_module(name)
196
+
197
+ # Load from all packages
198
+ for package_config in self.get_package_configs():
199
+ _import_if_exists(f"{package_config.name}.{module_name}")
200
+
201
+ # Load from app if requested
202
+ if include_app:
203
+ _import_if_exists(f"app.{module_name}")
204
+
191
205
 
192
206
  packages_registry = PackagesRegistry(installed_packages=None)
193
207
 
plain/preflight/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  Preflight checks help identify issues with your settings or environment before running your application.
14
14
 
15
15
  ```bash
16
- plain preflight
16
+ plain preflight check
17
17
  ```
18
18
 
19
19
  ## Development
@@ -22,10 +22,10 @@ If you use [`plain.dev`](/plain-dev/README.md) for local development, the Plain
22
22
 
23
23
  ## Deployment
24
24
 
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.
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.
26
26
 
27
27
  ```bash
28
- plain preflight --deploy
28
+ plain preflight check --deploy
29
29
  ```
30
30
 
31
31
  ## Custom preflight checks
@@ -1,17 +1,6 @@
1
- from .messages import (
2
- CRITICAL,
3
- DEBUG,
4
- ERROR,
5
- INFO,
6
- WARNING,
7
- CheckMessage,
8
- Critical,
9
- Debug,
10
- Error,
11
- Info,
12
- Warning,
13
- )
1
+ from .checks import PreflightCheck
14
2
  from .registry import register_check, run_checks
3
+ from .results import PreflightResult
15
4
 
16
5
  # Import these to force registration of checks
17
6
  import plain.preflight.files # NOQA isort:skip
@@ -20,17 +9,8 @@ import plain.preflight.urls # NOQA isort:skip
20
9
 
21
10
 
22
11
  __all__ = [
23
- "CheckMessage",
24
- "Debug",
25
- "Info",
26
- "Warning",
27
- "Error",
28
- "Critical",
29
- "DEBUG",
30
- "INFO",
31
- "WARNING",
32
- "ERROR",
33
- "CRITICAL",
12
+ "PreflightCheck",
13
+ "PreflightResult",
34
14
  "register_check",
35
15
  "run_checks",
36
16
  ]
@@ -0,0 +1,10 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+
4
+ class PreflightCheck(ABC):
5
+ """Base class for all preflight checks."""
6
+
7
+ @abstractmethod
8
+ def run(self):
9
+ """Must return a list of Warning/Error results."""
10
+ raise NotImplementedError
plain/preflight/files.py CHANGED
@@ -2,18 +2,22 @@ from pathlib import Path
2
2
 
3
3
  from plain.runtime import settings
4
4
 
5
- from . import Error, register_check
5
+ from .checks import PreflightCheck
6
+ from .registry import register_check
7
+ from .results import PreflightResult
6
8
 
7
9
 
8
- @register_check
9
- def check_setting_file_upload_temp_dir(package_configs, **kwargs):
10
- setting = getattr(settings, "FILE_UPLOAD_TEMP_DIR", None)
11
- if setting and not Path(setting).is_dir():
12
- return [
13
- Error(
14
- f"The FILE_UPLOAD_TEMP_DIR setting refers to the nonexistent "
15
- f"directory '{setting}'.",
16
- id="files.E001",
17
- ),
18
- ]
19
- return []
10
+ @register_check("files.upload_temp_dir")
11
+ class CheckSettingFileUploadTempDir(PreflightCheck):
12
+ """Validates that the FILE_UPLOAD_TEMP_DIR setting points to an existing directory."""
13
+
14
+ def run(self):
15
+ setting = settings.FILE_UPLOAD_TEMP_DIR
16
+ if setting and not Path(setting).is_dir():
17
+ return [
18
+ PreflightResult(
19
+ fix=f"FILE_UPLOAD_TEMP_DIR points to nonexistent directory '{setting}'. Create the directory or update the setting.",
20
+ id="files.upload_temp_dir_nonexistent",
21
+ )
22
+ ]
23
+ return []