simple-module-cli 0.0.44__py3-none-any.whl → 0.0.46__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.
- simple_module_cli/_add_install.py +26 -2
- simple_module_cli/_app_project_manifests.py +7 -1
- simple_module_cli/_lint_tooling.py +36 -0
- simple_module_cli/_version_check.py +53 -0
- simple_module_cli/app_project.py +10 -7
- simple_module_cli/cli.py +33 -20
- simple_module_cli/module_cmd.py +2 -0
- simple_module_cli/new.py +57 -31
- simple_module_cli/pins.py +4 -1
- simple_module_cli/pypi.py +2 -2
- simple_module_cli/scaffolding.py +14 -4
- simple_module_cli/skills/simple-module-cli/SKILL.md +9 -5
- simple_module_cli/skills/simple-module-conventions/SKILL.md +4 -2
- simple_module_cli/skills/simple-module-creating/SKILL.md +9 -3
- simple_module_cli/skills/simple-module-doctor/SKILL.md +3 -3
- simple_module_cli/skills/simple-module-inertia-pages/SKILL.md +2 -0
- simple_module_cli/templates/docker/host-flat.Dockerfile +4 -1
- simple_module_cli/templates/docker/host.Dockerfile +4 -1
- simple_module_cli/templates/host/Makefile +3 -1
- simple_module_cli/templates/host/alembic.ini +15 -0
- simple_module_cli/templates/host/client_app/app.tsx +10 -26
- simple_module_cli/templates/host/client_app/pages/Landing.tsx +17 -8
- simple_module_cli/templates/host/client_app/tsconfig.json +1 -1
- simple_module_cli/templates/host/client_app/vite.config.ts +18 -16
- simple_module_cli/templates/host/pyproject.toml.tpl +9 -2
- simple_module_cli/templates/module/README.md.tpl +7 -0
- simple_module_cli/templates/module/__PACKAGE__/contracts/schemas.py.tpl +1 -1
- simple_module_cli/templates/module/__PACKAGE__/module.py.tpl +1 -13
- simple_module_cli/templates/module/__PACKAGE__/pages/Browse.tsx.tpl +24 -15
- simple_module_cli/templates/module/__PACKAGE__/pages/Create.tsx.tpl +10 -5
- simple_module_cli/templates/module/__PACKAGE__/pages/Edit.tsx.tpl +10 -5
- simple_module_cli/templates/module/_optional/{framework_repo → standalone}/__PACKAGE__/pages/Browse.tsx.tpl +18 -21
- {simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/_optional/framework_repo → simple_module_cli/templates/module/_optional/standalone}/__PACKAGE__/pages/Create.tsx.tpl +8 -7
- {simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/_optional/framework_repo → simple_module_cli/templates/module/_optional/standalone}/__PACKAGE__/pages/Edit.tsx.tpl +8 -7
- simple_module_cli/templates/workspace/Makefile +3 -1
- simple_module_cli/templates/workspace/README.md.tpl +4 -2
- simple_module_cli/templates/workspace/pyproject.toml.tpl +11 -3
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/docker/host-flat.Dockerfile +4 -1
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/docker/host.Dockerfile +4 -1
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/Makefile +3 -1
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/alembic.ini +15 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/client_app/app.tsx +10 -26
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/client_app/pages/Landing.tsx +17 -8
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/client_app/tsconfig.json +1 -1
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/client_app/vite.config.ts +18 -16
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/pyproject.toml.tpl +9 -2
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/README.md.tpl +7 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/contracts/schemas.py.tpl +1 -1
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/module.py.tpl +1 -13
- {simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/_optional/framework_repo → simple_module_cli-0.0.46.data/data/simple_module_cli/templates/module}/__PACKAGE__/pages/Browse.tsx.tpl +3 -0
- {simple_module_cli/templates/module/_optional/framework_repo → simple_module_cli-0.0.46.data/data/simple_module_cli/templates/module}/__PACKAGE__/pages/Create.tsx.tpl +3 -0
- {simple_module_cli/templates/module/_optional/framework_repo → simple_module_cli-0.0.46.data/data/simple_module_cli/templates/module}/__PACKAGE__/pages/Edit.tsx.tpl +3 -0
- {simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module → simple_module_cli-0.0.46.data/data/simple_module_cli/templates/module/_optional/standalone}/__PACKAGE__/pages/Browse.tsx.tpl +3 -0
- {simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module → simple_module_cli-0.0.46.data/data/simple_module_cli/templates/module/_optional/standalone}/__PACKAGE__/pages/Create.tsx.tpl +3 -0
- {simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module → simple_module_cli-0.0.46.data/data/simple_module_cli/templates/module/_optional/standalone}/__PACKAGE__/pages/Edit.tsx.tpl +3 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/workspace/Makefile +3 -1
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/workspace/README.md.tpl +4 -2
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/workspace/pyproject.toml.tpl +11 -3
- {simple_module_cli-0.0.44.dist-info → simple_module_cli-0.0.46.dist-info}/METADATA +2 -2
- {simple_module_cli-0.0.44.dist-info → simple_module_cli-0.0.46.dist-info}/RECORD +124 -122
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/docker/Makefile.snippet +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/docker/compose-base-postgres.yml.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/docker/compose-base-sqlite.yml.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/docker/compose-tasks-postgres.yml.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/docker/compose-tasks-sqlite.yml.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/docker/compose-worker.yml.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/docker/dockerignore +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/docker/worker.Dockerfile.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/.env.example +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/.gitignore +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/README.md.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/_optional/background_tasks/Makefile.snippet +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/_optional/background_tasks/run_worker.py +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/client_app/main.tsx +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/client_app/module-assets.ts +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/client_app/package.json.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/client_app/pages/Error.tsx +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/client_app/pages.ts +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/client_app/styles.css +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/client_app/vite.dev-url.ts +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/main.py +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/migrations/env.py +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/migrations/script.py.mako +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/migrations/versions/.gitkeep +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/routes.py +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/host/templates/index.html +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/.github/workflows/ci.yml +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/.github/workflows/publish.yml.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/.gitignore +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/__init__.py +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/contracts/__init__.py.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/core/__init__.py +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/core/constants.py.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/core/services.py.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/core/settings.py.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/locales/en.json.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/models.py.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/pages/api.generated.ts.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/pages/api.ts.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/py.typed +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/web/__init__.py +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/web/deps.py.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/web/endpoints/__init__.py +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/web/endpoints/api.py.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/web/endpoints/views.py.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/__PACKAGE__/web/service.py.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/_optional/framework_repo/LICENSE +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/_optional/framework_repo/README.md.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/_optional/framework_repo/pyproject.toml.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/_optional/standalone/package.json.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/_optional/standalone/tsconfig.json.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/package.json.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/pyproject.toml.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/tests/conftest.py +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/tests/core/contracts/test___PACKAGE___schemas.py.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/tests/core/module/test___PACKAGE___module.py.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/tests/web/crud/test___PACKAGE___crud.py.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/module/tsconfig.json.tpl +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/workspace/.env.example +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/workspace/.gitignore +0 -0
- {simple_module_cli-0.0.44.data → simple_module_cli-0.0.46.data}/data/simple_module_cli/templates/workspace/package.json.tpl +0 -0
- {simple_module_cli-0.0.44.dist-info → simple_module_cli-0.0.46.dist-info}/WHEEL +0 -0
- {simple_module_cli-0.0.44.dist-info → simple_module_cli-0.0.46.dist-info}/entry_points.txt +0 -0
- {simple_module_cli-0.0.44.dist-info → simple_module_cli-0.0.46.dist-info}/licenses/LICENSE +0 -0
|
@@ -8,6 +8,8 @@ from pathlib import Path
|
|
|
8
8
|
|
|
9
9
|
import typer
|
|
10
10
|
|
|
11
|
+
from simple_module_cli.uv_workspace import find_workspace_root, is_workspace_member
|
|
12
|
+
|
|
11
13
|
ExecRunner = Callable[[list[str], Path], int]
|
|
12
14
|
|
|
13
15
|
|
|
@@ -28,6 +30,24 @@ def _default_exec_runner(cmd: list[str], cwd: Path) -> int:
|
|
|
28
30
|
return subprocess.run(cmd, cwd=cwd, check=False).returncode
|
|
29
31
|
|
|
30
32
|
|
|
33
|
+
def _sync_command(project_dir: Path) -> tuple[list[str], Path]:
|
|
34
|
+
"""How to sync after editing ``project_dir``'s pyproject.
|
|
35
|
+
|
|
36
|
+
A host inside an app workspace shares one venv with the root's dev tools
|
|
37
|
+
and every module member. ``uv sync`` from ``host/`` would sync the host
|
|
38
|
+
alone and uninstall the rest (GH #916), so sync the workspace from its
|
|
39
|
+
root, as ``make install`` does.
|
|
40
|
+
"""
|
|
41
|
+
root = find_workspace_root(project_dir)
|
|
42
|
+
if (
|
|
43
|
+
root is not None
|
|
44
|
+
and root != project_dir.resolve()
|
|
45
|
+
and is_workspace_member(project_dir, project_dir)
|
|
46
|
+
):
|
|
47
|
+
return ["uv", "sync", "--all-packages"], root
|
|
48
|
+
return ["uv", "sync"], project_dir
|
|
49
|
+
|
|
50
|
+
|
|
31
51
|
def _fail(message: str) -> typer.Exit:
|
|
32
52
|
typer.echo(f"ERROR: {message}", err=True)
|
|
33
53
|
return typer.Exit(code=1)
|
|
@@ -40,8 +60,12 @@ def post_install(
|
|
|
40
60
|
exec_runner: ExecRunner,
|
|
41
61
|
) -> None:
|
|
42
62
|
"""uv sync → gen-pages → sync-js-deps → entry-point check → reminders."""
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
sync_cmd, sync_dir = _sync_command(project_dir)
|
|
64
|
+
if exec_runner(sync_cmd, sync_dir) != 0:
|
|
65
|
+
shown = " ".join(sync_cmd)
|
|
66
|
+
raise _fail(
|
|
67
|
+
f"`{shown}` failed — pyproject was written; fix and re-run `{shown}` from {sync_dir}."
|
|
68
|
+
)
|
|
45
69
|
if (project_dir / "client_app").is_dir():
|
|
46
70
|
exec_runner(["uv", "run", "smpy", "host", "gen-pages"], project_dir)
|
|
47
71
|
exec_runner(["uv", "run", "smpy", "host", "sync-js-deps"], project_dir)
|
|
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from collections.abc import Sequence
|
|
6
6
|
|
|
7
|
+
from simple_module_cli._lint_tooling import TY_REQUIREMENT
|
|
7
8
|
from simple_module_cli.scaffolding import resolve_framework_version
|
|
8
9
|
|
|
9
10
|
_FRAMEWORK_VERSION = resolve_framework_version()
|
|
@@ -22,7 +23,7 @@ _APP_PY_DEV_DEPS = [
|
|
|
22
23
|
# Floor: unpinned, uv backtracks playwright to 1.18 (GH #445).
|
|
23
24
|
"playwright>=1.45",
|
|
24
25
|
"ruff>=0.8",
|
|
25
|
-
|
|
26
|
+
TY_REQUIREMENT,
|
|
26
27
|
]
|
|
27
28
|
|
|
28
29
|
_APP_NPM_DEPS = {
|
|
@@ -50,6 +51,11 @@ _APP_NPM_DEV_DEPS = {
|
|
|
50
51
|
"vite": "^8.2.2",
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
# `@tailwindcss/typography` (pulled in by @simple-module-py/ui) pins
|
|
55
|
+
# postcss-selector-parser 6.0.10, which `npm audit` flags as a moderate ReDoS
|
|
56
|
+
# (GH #900). This repo's root package.json carries the same override.
|
|
57
|
+
_APP_NPM_OVERRIDES = {"postcss-selector-parser": "^6.1.5"}
|
|
58
|
+
|
|
53
59
|
|
|
54
60
|
def _db_url(db: str, db_name: str, *, flat: bool, password: str = "<POSTGRES_PASSWORD>") -> str:
|
|
55
61
|
if db == "postgres":
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Values that keep a scaffolded app passing its own ``make lint`` (GH #896)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
# ty is pre-1.0 and renames rules between releases, so
|
|
6
|
+
# new apps get the range this repo is tested on, not the newest ty.
|
|
7
|
+
# ``test_scaffold_lint_tooling.py`` fails once ``uv.lock`` moves past it.
|
|
8
|
+
TY_REQUIREMENT = "ty>=0.0.100,<0.0.101"
|
|
9
|
+
|
|
10
|
+
# Apps turn ty's ``invalid-assignment`` off, so this ignore would be reported as
|
|
11
|
+
# unused there; only a module inside the framework repo, which checks the rule,
|
|
12
|
+
# gets it.
|
|
13
|
+
MODEL_CONFIG_TY_IGNORE = " # ty: ignore[invalid-assignment]"
|
|
14
|
+
|
|
15
|
+
_MODULE_CONSTANTS = (
|
|
16
|
+
"API_PREFIX",
|
|
17
|
+
"LOCALE_NAMESPACE",
|
|
18
|
+
"MENU_ICON",
|
|
19
|
+
"MENU_LABEL",
|
|
20
|
+
"MENU_LABEL_KEY",
|
|
21
|
+
"MENU_ORDER",
|
|
22
|
+
"MENU_URL",
|
|
23
|
+
"PERM_GROUP",
|
|
24
|
+
"VIEW_PREFIX",
|
|
25
|
+
)
|
|
26
|
+
_MODULE_PERMISSIONS = ("CREATE", "DELETE", "EDIT", "VIEW")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def module_constants_import(package_upper: str) -> str:
|
|
30
|
+
"""The ``module.py`` constants import list, in the order ruff's isort wants.
|
|
31
|
+
|
|
32
|
+
Where ``PERM_GROUP`` falls among ``PERM_<PACKAGE>_*`` depends on the package
|
|
33
|
+
name, so a fixed template order is unsorted for half of all names.
|
|
34
|
+
"""
|
|
35
|
+
names = [*_MODULE_CONSTANTS, *(f"PERM_{package_upper}_{p}" for p in _MODULE_PERMISSIONS)]
|
|
36
|
+
return "\n".join(f" {name}," for name in sorted(names, key=str.lower))
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Warn when ``smpy new`` runs from an older CLI than PyPI's latest (GH #899).
|
|
2
|
+
|
|
3
|
+
A new app pins every framework package to the running CLI's own version, and
|
|
4
|
+
``uvx --from simple_module_cli`` quietly reuses a ``uv tool install``-ed copy, so
|
|
5
|
+
an old tool scaffolds an old app without saying so. The check is best effort: a
|
|
6
|
+
short timeout, and any failure (offline, PyPI down, bad JSON) skips it.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from functools import partial
|
|
12
|
+
|
|
13
|
+
import typer
|
|
14
|
+
from packaging.version import Version
|
|
15
|
+
|
|
16
|
+
from simple_module_cli.pins import PLACEHOLDER_VERSION
|
|
17
|
+
from simple_module_cli.pypi import PYPI_URL, Fetcher, default_fetcher, fetch_latest
|
|
18
|
+
|
|
19
|
+
CLI_DIST = "simple_module_cli"
|
|
20
|
+
_TIMEOUT_SECONDS = 3
|
|
21
|
+
_quick_fetcher: Fetcher = partial(default_fetcher, timeout=_TIMEOUT_SECONDS)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def newer_release(current: str, fetcher: Fetcher | None = None) -> str | None:
|
|
25
|
+
"""The latest stable ``simple_module_cli`` on PyPI if it is newer than ``current``."""
|
|
26
|
+
if current == PLACEHOLDER_VERSION:
|
|
27
|
+
return None
|
|
28
|
+
try:
|
|
29
|
+
running = Version(current)
|
|
30
|
+
if running.is_prerelease or running.is_devrelease or running.local:
|
|
31
|
+
return None # pre-release, dev or local build: not what PyPI ships
|
|
32
|
+
latest = fetch_latest(CLI_DIST, include_pre=False, fetcher=fetcher or _quick_fetcher)
|
|
33
|
+
if latest is not None and Version(latest) > running:
|
|
34
|
+
return latest
|
|
35
|
+
except Exception:
|
|
36
|
+
# OSError (timeouts, sockets), ValueError (bad JSON/versions), but also
|
|
37
|
+
# http.client.IncompleteRead and AttributeError on an unexpected payload shape.
|
|
38
|
+
return None
|
|
39
|
+
return None
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def warn_if_outdated(current: str, fetcher: Fetcher | None = None) -> None:
|
|
43
|
+
latest = newer_release(current, fetcher)
|
|
44
|
+
if latest is None:
|
|
45
|
+
return
|
|
46
|
+
typer.echo(
|
|
47
|
+
f"WARNING: this smpy is {current}, but {CLI_DIST} {latest} is on PyPI "
|
|
48
|
+
f"({PYPI_URL.format(name=CLI_DIST)}). The new app will pin the framework to "
|
|
49
|
+
f"{current}.\n"
|
|
50
|
+
f" Upgrade the installed tool: uv tool upgrade {CLI_DIST} (pipx upgrade {CLI_DIST})\n"
|
|
51
|
+
f" or run the latest once: uvx --from {CLI_DIST}@latest smpy new ...",
|
|
52
|
+
err=True,
|
|
53
|
+
)
|
simple_module_cli/app_project.py
CHANGED
|
@@ -22,6 +22,7 @@ from typing import Any
|
|
|
22
22
|
from simple_module_cli._app_project_manifests import (
|
|
23
23
|
_APP_NPM_DEPS,
|
|
24
24
|
_APP_NPM_DEV_DEPS,
|
|
25
|
+
_APP_NPM_OVERRIDES,
|
|
25
26
|
_APP_PY_DEV_DEPS,
|
|
26
27
|
_FRAMEWORK_VERSION,
|
|
27
28
|
_db_url,
|
|
@@ -160,19 +161,21 @@ def create_app_project(
|
|
|
160
161
|
)
|
|
161
162
|
host_pyproject.write_text(text, encoding="utf-8")
|
|
162
163
|
|
|
164
|
+
pkg_path = target / "package.json"
|
|
165
|
+
pkg_data: dict[str, Any] = (
|
|
166
|
+
_json.loads(pkg_path.read_text(encoding="utf-8"))
|
|
167
|
+
if pkg_path.exists()
|
|
168
|
+
else {"name": to_kebab_case(name), "private": True, "type": "module"}
|
|
169
|
+
)
|
|
163
170
|
if flat:
|
|
164
171
|
# The workspace template already emits a top-level package.json
|
|
165
172
|
# with workspaces; flat mode has none, so seed one with the
|
|
166
173
|
# framework npm pins so `npm install` resolves at the root.
|
|
167
|
-
pkg_path = target / "package.json"
|
|
168
|
-
pkg_data: dict[str, Any] = (
|
|
169
|
-
_json.loads(pkg_path.read_text(encoding="utf-8"))
|
|
170
|
-
if pkg_path.exists()
|
|
171
|
-
else {"name": to_kebab_case(name), "private": True, "type": "module"}
|
|
172
|
-
)
|
|
173
174
|
pkg_data.setdefault("dependencies", {}).update(_APP_NPM_DEPS)
|
|
174
175
|
pkg_data.setdefault("devDependencies", {}).update(_APP_NPM_DEV_DEPS)
|
|
175
|
-
|
|
176
|
+
# npm reads `overrides` only from the root package.json, in both layouts.
|
|
177
|
+
pkg_data.setdefault("overrides", {}).update(_APP_NPM_OVERRIDES)
|
|
178
|
+
pkg_path.write_text(_json.dumps(pkg_data, indent=2) + "\n", encoding="utf-8")
|
|
176
179
|
|
|
177
180
|
ctx = ScaffoldCtx(name=name, db=db, tenancy=tenancy, selected=tuple(resolved))
|
|
178
181
|
for mod_name in resolved:
|
simple_module_cli/cli.py
CHANGED
|
@@ -126,25 +126,35 @@ def create_host(
|
|
|
126
126
|
typer.echo(" python main.py")
|
|
127
127
|
|
|
128
128
|
|
|
129
|
-
def
|
|
130
|
-
"""
|
|
129
|
+
def _app_add_command(target: Path) -> str | None:
|
|
130
|
+
"""``smpy add …`` wiring a module into its app's host, or None outside an app (GH #442)."""
|
|
131
131
|
root = find_workspace_root(target.parent)
|
|
132
132
|
if root is None:
|
|
133
|
-
return
|
|
133
|
+
return None
|
|
134
134
|
host = root / "host"
|
|
135
135
|
if not (host / "pyproject.toml").is_file() or not is_workspace_member(host, target):
|
|
136
|
-
return
|
|
136
|
+
return None
|
|
137
137
|
rel = os.path.relpath(target.resolve(), host.resolve())
|
|
138
138
|
if not rel.startswith("."):
|
|
139
139
|
rel = f"./{rel}" # parse_add_spec reads a bare "a/b" as a PyPI requirement
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
# The steps are printed "from the app root", so name the host relative to it.
|
|
141
|
+
host_arg = host.resolve().relative_to(root.resolve()).as_posix()
|
|
142
|
+
return f"smpy add {rel} --path {host_arg}"
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _echo_app_next_steps(add_command: str, slug: str) -> None:
|
|
146
|
+
"""The module lives in an app's workspace: wire it in with the app's own commands.
|
|
147
|
+
|
|
148
|
+
Never ``uv sync`` inside the module: that syncs the module alone and
|
|
149
|
+
uninstalls the rest of the app from the shared venv (GH #916).
|
|
150
|
+
"""
|
|
151
|
+
typer.echo("\nNext steps (from the app root):")
|
|
152
|
+
typer.echo(f" {add_command} # adds it as {{ workspace = true }}")
|
|
153
|
+
typer.echo(" make install")
|
|
154
|
+
typer.echo(f' make migration msg="add {slug}"')
|
|
155
|
+
typer.echo(" make migrate")
|
|
156
|
+
typer.echo(" make test")
|
|
157
|
+
typer.echo("Then restart `make dev`: modules are discovered at start-up, not on reload.")
|
|
148
158
|
|
|
149
159
|
|
|
150
160
|
@app.command("create-module")
|
|
@@ -193,14 +203,17 @@ def create_module(
|
|
|
193
203
|
"Skipped .github/ workflows: this module is inside an existing repo, "
|
|
194
204
|
"where nested workflows never run. Use --standalone to emit them."
|
|
195
205
|
)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
206
|
+
add_command = _app_add_command(target)
|
|
207
|
+
if add_command is not None:
|
|
208
|
+
_echo_app_next_steps(add_command, slug)
|
|
209
|
+
else:
|
|
210
|
+
typer.echo("\nNext steps:")
|
|
211
|
+
typer.echo(f" cd {target}")
|
|
212
|
+
typer.echo(" uv sync --extra dev")
|
|
213
|
+
typer.echo(" uv run pytest")
|
|
214
|
+
typer.echo(" npm install")
|
|
215
|
+
typer.echo(" npm run typecheck")
|
|
216
|
+
typer.echo(" uv run smpy module verify")
|
|
204
217
|
typer.echo(
|
|
205
218
|
"\nThe pages ship sample API types (pages/api.generated.ts). Once the host serves "
|
|
206
219
|
"the module, refresh them after any endpoint change:\n"
|
simple_module_cli/module_cmd.py
CHANGED
|
@@ -50,6 +50,8 @@ def run_verify(info: ModuleInfo, *, fresh: bool = False, runner=subprocess.run)
|
|
|
50
50
|
],
|
|
51
51
|
host,
|
|
52
52
|
),
|
|
53
|
+
# Keyed pages read `keys.<module>`, which only the host's gen-i18n adds (GH #918).
|
|
54
|
+
("gen-i18n", [uv, "run", "python", "-m", "simple_module_hosting", "gen-i18n"], host),
|
|
53
55
|
("frontend build (tsc + vite)", [npm, "run", "build"], client_app),
|
|
54
56
|
)
|
|
55
57
|
for label, cmd, cwd in steps:
|
simple_module_cli/new.py
CHANGED
|
@@ -4,16 +4,19 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import shutil
|
|
6
6
|
import subprocess
|
|
7
|
+
from collections.abc import Sequence
|
|
7
8
|
from enum import StrEnum
|
|
8
9
|
from pathlib import Path
|
|
9
10
|
from typing import Annotated
|
|
10
11
|
|
|
11
12
|
import typer
|
|
12
13
|
|
|
14
|
+
from simple_module_cli._version_check import warn_if_outdated
|
|
13
15
|
from simple_module_cli.add_cmd import run_add
|
|
14
16
|
from simple_module_cli.app_project import create_app_project
|
|
15
17
|
from simple_module_cli.case import InvalidScaffoldNameError, to_kebab_case, validate_scaffold_name
|
|
16
18
|
from simple_module_cli.catalog import PRESETS, expand_deps
|
|
19
|
+
from simple_module_cli.pins import resolve_framework_version
|
|
17
20
|
from simple_module_cli.wizard import run_wizard
|
|
18
21
|
|
|
19
22
|
__all__ = ["new_project"]
|
|
@@ -110,6 +113,7 @@ def new_project(
|
|
|
110
113
|
except InvalidScaffoldNameError as exc:
|
|
111
114
|
typer.echo(f"ERROR: {exc}", err=True)
|
|
112
115
|
raise typer.Exit(code=1) from exc
|
|
116
|
+
warn_if_outdated(resolve_framework_version())
|
|
113
117
|
pypi_name = to_kebab_case(name)
|
|
114
118
|
if pypi_name != name:
|
|
115
119
|
typer.echo(f"Normalizing PyPI name to {pypi_name!r}.")
|
|
@@ -171,61 +175,83 @@ def new_project(
|
|
|
171
175
|
rel = path.relative_to(target) if path.is_relative_to(target) else path
|
|
172
176
|
typer.echo(f" {rel}")
|
|
173
177
|
typer.echo("\nGenerated secrets were written to .env (gitignored), not .env.example.")
|
|
174
|
-
|
|
175
|
-
typer.echo(f" cd {target}")
|
|
178
|
+
manual_setup = ["make install", 'make migration msg="initial schema"', "make migrate"]
|
|
176
179
|
if no_install:
|
|
177
|
-
|
|
178
|
-
typer.echo(" npm install")
|
|
179
|
-
typer.echo(' make migration msg="initial schema"')
|
|
180
|
-
typer.echo(" make migrate")
|
|
181
|
-
typer.echo(" make dev")
|
|
182
|
-
typer.echo(" make docker-up # or run the full stack in containers")
|
|
183
|
-
if "background_tasks" in resolved:
|
|
184
|
-
typer.echo(" docker compose up -d redis worker beat # background jobs")
|
|
180
|
+
_echo_next_steps(target, manual_setup, resolved)
|
|
185
181
|
return
|
|
186
182
|
|
|
187
|
-
typer.echo("
|
|
188
|
-
|
|
183
|
+
typer.echo("\nInstalling dependencies...")
|
|
184
|
+
# What `make install` runs: a workspace syncs every member, not just the root.
|
|
185
|
+
uv_sync = ["uv", "sync"] if flat else ["uv", "sync", "--all-packages"]
|
|
186
|
+
for cmd in (uv_sync, ["npm", "install"]):
|
|
189
187
|
if shutil.which(cmd[0]) is None:
|
|
190
188
|
typer.echo(
|
|
191
189
|
f"WARNING: '{cmd[0]}' not found on PATH; skipping `{' '.join(cmd)}`. "
|
|
192
190
|
"Install it and finish setup manually.",
|
|
193
191
|
err=True,
|
|
194
192
|
)
|
|
193
|
+
_echo_next_steps(target, manual_setup, resolved)
|
|
195
194
|
return
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
typer.echo(
|
|
199
|
-
f"WARNING: {' '.join(cmd)} failed (exit {result.returncode}); "
|
|
200
|
-
"finish setup manually.",
|
|
201
|
-
err=True,
|
|
202
|
-
)
|
|
195
|
+
if not _run_quietly(cmd, target):
|
|
196
|
+
_echo_next_steps(target, manual_setup, resolved)
|
|
203
197
|
return
|
|
204
198
|
|
|
205
199
|
alembic = _alembic_argv(target, host_dir)
|
|
206
|
-
|
|
200
|
+
typer.echo("Creating the database...")
|
|
201
|
+
if not _bootstrap_initial_migration(target, host_dir, alembic):
|
|
202
|
+
_echo_next_steps(target, manual_setup[1:], resolved)
|
|
203
|
+
return
|
|
207
204
|
# `heads` (plural) applies every per-module branch head; `head` (singular)
|
|
208
205
|
# errors once a second module ships its own migration branch label.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
206
|
+
if not _run_quietly([*alembic, "upgrade", "heads"], target):
|
|
207
|
+
# The revision exists now; regenerating it would create a duplicate.
|
|
208
|
+
_echo_next_steps(target, manual_setup[2:], resolved)
|
|
209
|
+
return
|
|
210
|
+
typer.echo("\nSetup complete.")
|
|
211
|
+
_echo_next_steps(target, [], resolved)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _run_quietly(cmd: list[str], cwd: Path) -> bool:
|
|
215
|
+
"""Run a setup step, showing its output only when it fails (GH #917)."""
|
|
216
|
+
try:
|
|
217
|
+
result = subprocess.run(
|
|
218
|
+
cmd, cwd=cwd, check=False, capture_output=True, text=True, errors="replace"
|
|
219
|
+
)
|
|
220
|
+
except OSError as exc: # the executable is missing
|
|
221
|
+
typer.echo(
|
|
222
|
+
f"WARNING: {' '.join(cmd)} could not run ({exc}); finish setup manually.", err=True
|
|
223
|
+
)
|
|
224
|
+
return False
|
|
225
|
+
if result.returncode == 0:
|
|
226
|
+
return True
|
|
227
|
+
typer.echo(f"{result.stdout}{result.stderr}", err=True)
|
|
228
|
+
typer.echo(
|
|
229
|
+
f"WARNING: {' '.join(cmd)} failed (exit {result.returncode}); finish setup manually.",
|
|
230
|
+
err=True,
|
|
231
|
+
)
|
|
232
|
+
return False
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def _echo_next_steps(target: Path, setup: list[str], resolved: Sequence[str]) -> None:
|
|
236
|
+
typer.echo("\nNext steps:")
|
|
237
|
+
typer.echo(f" cd {target}")
|
|
238
|
+
for step in [*setup, "make dev"]:
|
|
239
|
+
typer.echo(f" {step}")
|
|
240
|
+
typer.echo(" make docker-up # or run the full stack in containers")
|
|
212
241
|
if "background_tasks" in resolved:
|
|
213
|
-
typer.echo("
|
|
242
|
+
typer.echo(" docker compose up -d redis worker beat # background jobs")
|
|
214
243
|
|
|
215
244
|
|
|
216
|
-
def _bootstrap_initial_migration(target: Path, host_dir: Path, alembic: list[str]) ->
|
|
245
|
+
def _bootstrap_initial_migration(target: Path, host_dir: Path, alembic: list[str]) -> bool:
|
|
217
246
|
"""Autogenerate the baseline migration if the scaffold ships none.
|
|
218
247
|
|
|
219
248
|
Without a real revision, ``alembic upgrade head`` is a silent no-op
|
|
220
249
|
against an empty schema — the bundled modules' tables never exist.
|
|
221
250
|
|
|
222
251
|
Runs from ``target`` (the project root) — see :func:`_alembic_argv`.
|
|
252
|
+
Returns False when the autogenerate failed.
|
|
223
253
|
"""
|
|
224
254
|
versions_dir = host_dir / "migrations" / "versions"
|
|
225
255
|
if any(p.name != "__init__.py" for p in versions_dir.glob("*.py")):
|
|
226
|
-
return
|
|
227
|
-
|
|
228
|
-
[*alembic, "revision", "--autogenerate", "-m", "initial schema"],
|
|
229
|
-
cwd=target,
|
|
230
|
-
check=False,
|
|
231
|
-
)
|
|
256
|
+
return True
|
|
257
|
+
return _run_quietly([*alembic, "revision", "--autogenerate", "-m", "initial schema"], target)
|
simple_module_cli/pins.py
CHANGED
|
@@ -15,6 +15,9 @@ from __future__ import annotations
|
|
|
15
15
|
|
|
16
16
|
from pathlib import Path
|
|
17
17
|
|
|
18
|
+
# What resolve_framework_version() returns for an install without dist-info.
|
|
19
|
+
PLACEHOLDER_VERSION = "0.0.0"
|
|
20
|
+
|
|
18
21
|
|
|
19
22
|
def resolve_framework_version() -> str:
|
|
20
23
|
"""Resolve the framework version that scaffolded apps should pin against.
|
|
@@ -31,7 +34,7 @@ def resolve_framework_version() -> str:
|
|
|
31
34
|
try:
|
|
32
35
|
return pkg_version("simple_module_cli")
|
|
33
36
|
except PackageNotFoundError:
|
|
34
|
-
return
|
|
37
|
+
return PLACEHOLDER_VERSION
|
|
35
38
|
|
|
36
39
|
|
|
37
40
|
def _pin_one(dep: str, version: str) -> str:
|
simple_module_cli/pypi.py
CHANGED
|
@@ -57,6 +57,6 @@ def fetch_latest(name: str, *, include_pre: bool, fetcher: Fetcher) -> str | Non
|
|
|
57
57
|
return fallback if is_valid_version(fallback) else None
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
def default_fetcher(url: str) -> dict[str, Any]:
|
|
61
|
-
with urllib.request.urlopen(url, timeout=
|
|
60
|
+
def default_fetcher(url: str, timeout: float = 10) -> dict[str, Any]:
|
|
61
|
+
with urllib.request.urlopen(url, timeout=timeout) as resp:
|
|
62
62
|
return json.loads(resp.read().decode("utf-8"))
|
simple_module_cli/scaffolding.py
CHANGED
|
@@ -21,6 +21,12 @@ from collections.abc import Sequence
|
|
|
21
21
|
from pathlib import Path
|
|
22
22
|
from typing import TypeGuard
|
|
23
23
|
|
|
24
|
+
from simple_module_cli._lint_tooling import (
|
|
25
|
+
MODEL_CONFIG_TY_IGNORE,
|
|
26
|
+
TY_REQUIREMENT,
|
|
27
|
+
module_constants_import,
|
|
28
|
+
)
|
|
29
|
+
|
|
24
30
|
# The template engine lives in _templating.py; the private names are imported
|
|
25
31
|
# here because long-standing tests monkeypatch them on this module.
|
|
26
32
|
from simple_module_cli._templating import (
|
|
@@ -137,6 +143,7 @@ def create_workspace(
|
|
|
137
143
|
"{{HOST_NAME}}": validate_scaffold_name(name),
|
|
138
144
|
"{{HOST_PYPI_NAME}}": to_kebab_case(name),
|
|
139
145
|
"{{FRAMEWORK_VERSION}}": framework_version,
|
|
146
|
+
"{{TY_REQUIREMENT}}": TY_REQUIREMENT,
|
|
140
147
|
},
|
|
141
148
|
preserve_existing=preserve_existing,
|
|
142
149
|
)
|
|
@@ -213,13 +220,14 @@ def create_module(
|
|
|
213
220
|
simple_module_python monorepo itself (``make new-module``): it overlays
|
|
214
221
|
``_optional/framework_repo/`` (a workspace-sourced ``pyproject.toml`` with
|
|
215
222
|
the metadata ``scripts/check_metadata.py`` requires, a LICENSE and README
|
|
216
|
-
that pass ``check_readmes.py
|
|
217
|
-
|
|
218
|
-
:mod:`simple_module_cli.framework_repo`'s job.
|
|
223
|
+
that pass ``check_readmes.py``) and implies no ``.github/``. Wiring into
|
|
224
|
+
the repo's own pyproject files is :mod:`simple_module_cli.framework_repo`'s job.
|
|
219
225
|
|
|
220
226
|
``standalone=True`` additionally overlays ``_optional/standalone/`` (npm
|
|
221
227
|
devDependencies + a tsconfig that resolves ``@simple-module-py/ui`` from the
|
|
222
|
-
repo's own ``node_modules``) so the module type-checks outside a workspace
|
|
228
|
+
repo's own ``node_modules``) so the module type-checks outside a workspace,
|
|
229
|
+
and pages with literal English: the base pages use ``t(keys.<package>.…)``
|
|
230
|
+
(GH #918), and a module repo has no host whose ``gen-i18n`` adds its keys.
|
|
223
231
|
"""
|
|
224
232
|
dest = Path(dest)
|
|
225
233
|
existed_before = dest.exists()
|
|
@@ -239,6 +247,8 @@ def create_module(
|
|
|
239
247
|
"{{SINGULAR}}": singular,
|
|
240
248
|
"{{SINGULAR_UPPER}}": singular.upper(),
|
|
241
249
|
"{{SINGULAR_CLASS}}": to_pascal_case(singular),
|
|
250
|
+
"{{CONSTANTS_IMPORTS}}": module_constants_import(package_name.upper()),
|
|
251
|
+
"{{MODEL_CONFIG_TY_IGNORE}}": MODEL_CONFIG_TY_IGNORE if framework_repo else "",
|
|
242
252
|
# npm-side pin for @simple-module-py/* devDependencies; "*" when the
|
|
243
253
|
# caller skips pinning (mirrors _should_pin_framework_version).
|
|
244
254
|
"{{FRAMEWORK_VERSION}}": (
|
|
@@ -15,7 +15,7 @@ The `smpy` command is provided by `simple_module_cli` (installed as a dep of `si
|
|
|
15
15
|
|---|---|
|
|
16
16
|
| `smpy new <name>` | Greenfield: scaffold a complete app (host + selected modules) in one shot, with an interactive wizard for DB / tenancy / module preset |
|
|
17
17
|
| `smpy create-host <name>` | You want just a bare host project; you'll add modules later by `pip install`-ing them |
|
|
18
|
-
| `smpy create-module <name>` | You're authoring a publishable module package
|
|
18
|
+
| `smpy create-module <name>` | You're adding a module to a `smpy new` app (`--dest modules/<name>`), or authoring a publishable module package in its own repo |
|
|
19
19
|
| `smpy package-update` | Bump every `simple_module_*` / `simple-module-*` dependency, optional extra and dependency group to its latest non-yanked PyPI release, and `@simple-module-py/*` npm pins to the same core version (workspace/path/git/URL sources are left untouched) |
|
|
20
20
|
| `smpy migrations prepare <upgrade-id> --head <label>@head` | Write the host-side revision for a framework data upgrade that boot or `make doctor` reported (`mail.settings_namespace_v1`, `users.hashed_bearer_tokens_v1`); it never applies it — run your migrate step afterwards |
|
|
21
21
|
| `smpy doctor` | Run the module diagnostics (`SM0xx`, including `SM033` data-compatibility findings) against this host's database |
|
|
@@ -90,13 +90,15 @@ smpy create-host MyApp --dest ./apps/myapp # custom destination
|
|
|
90
90
|
|
|
91
91
|
## `smpy create-module <name>` — module package
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
Scaffolds one module package: inside a `smpy new` app, or as a standalone repo to publish to PyPI.
|
|
94
94
|
|
|
95
95
|
```bash
|
|
96
|
-
smpy create-module orders
|
|
97
|
-
smpy create-module orders
|
|
96
|
+
smpy create-module orders --dest modules/orders # inside an app: a workspace member
|
|
97
|
+
smpy create-module orders # writes ./simple_module_orders/
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
+
Inside an app the printed next steps are the app's: `smpy add ../modules/orders --path host` (which syncs the whole workspace), `make install`, `make migration msg="add orders"`, `make migrate`, `make test`, then restart `make dev`. Never run `uv sync` inside the module directory there: it syncs the module alone and uninstalls the rest of the app from the shared venv. Outside an app it prints the standalone flow (`uv sync --extra dev`, `uv run pytest`, `smpy module verify`).
|
|
101
|
+
|
|
100
102
|
The result is a complete package: `pyproject.toml` with the entry point declared, `module.py` with `ModuleBase`/`ModuleMeta` skeleton, `models.py`, `contracts/`, `web/endpoints/{api,views}.py`, `pages/`, `locales/en.json`, `core/{constants,settings,services}.py`, `web/{deps,service}.py`, plus nested `tests/<area>/<feature>/test_<module>_*.py` wired up with `simple_module_test` fixtures.
|
|
101
103
|
|
|
102
104
|
`<name>` accepts any case — `orders`, `Orders`, `ORDERS`, `blog_posts` all work. The CLI lowercases it for the directory and PascalCases it for `ModuleMeta.name`.
|
|
@@ -193,6 +195,7 @@ smpy settings import-from-env
|
|
|
193
195
|
Bootstraps the first admin user, or rotates an existing admin's password.
|
|
194
196
|
|
|
195
197
|
```bash
|
|
198
|
+
smpy users create-admin -e admin@example.com # prompts for the password
|
|
196
199
|
smpy users create-admin -e admin@example.com -p hunter2
|
|
197
200
|
smpy users create-admin -e admin@example.com -p new-password --force # rotate
|
|
198
201
|
smpy users create-admin -e admin@example.com -p hunter2 --full-name "Admin"
|
|
@@ -213,7 +216,8 @@ Don't bake `--password` literals into a script you commit; use a secrets store a
|
|
|
213
216
|
- **Ran `smpy new` inside an existing project.** The default `--dest ./<name>` creates a sibling directory. If the directory already exists and is non-empty, the command errors out — pass `--dest` explicitly to disambiguate.
|
|
214
217
|
- **Ran `smpy host gen-pages` from outside the host directory.** Defaults to `./client_app`; pass `--host-dir` from elsewhere.
|
|
215
218
|
- **Forgot `smpy host sync-js-deps` after `pip install`-ing a module with pages.** Vite resolves module imports against `client_app/node_modules`; the new module's JS deps won't land until you sync.
|
|
216
|
-
- **
|
|
219
|
+
- **Ran `uv sync` inside a module of a `smpy new` app.** That syncs the module's own project and uninstalls the app's other packages from the shared venv. Run `make install` (`uv sync --all-packages`) at the app root instead; a plain `uv sync` at the root also works, since the root depends on the host.
|
|
220
|
+
- **A module added while `make dev` runs logs "installed but … cannot be imported in this process".** The reload keeps the import path the server started with; restart `make dev`.
|
|
217
221
|
- **Calling `smpy create-admin` before migrations have run.** The users tables don't exist yet; the command will error. Run `alembic upgrade head` first (or use `smpy new` which does it for you when `--no-install` isn't set).
|
|
218
222
|
- **Expecting `--with products` (or `keycloak` / `audit_log`) to work on `smpy new`.** Those modules exist in the monorepo but aren't scaffolder-catalog keys, so `smpy new --with products` errors. Either scaffold without them and `pip install simple_module_products` into the host afterward, or use `smpy create-host --with Products` (which doesn't validate against the catalog).
|
|
219
223
|
- **Port 5050 already taken when starting a scaffolded app.** Set `SM_VITE_DEV_URL` in the project `.env` (e.g. `http://localhost:5310`) — the scaffolded `vite.config.ts` derives the dev server's port and origin from that same value, so it's the only knob to turn.
|
|
@@ -30,6 +30,8 @@ class OrderOut(SQLModel): # DTO — plain SQLModel, no table=True
|
|
|
30
30
|
name: str
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
On a DTO, `Field(regex=...)` is accepted but never enforced, and `Field(pattern=...)` raises `TypeError`, so check formats with a pydantic `field_validator`. Length and range limits work.
|
|
34
|
+
|
|
33
35
|
Forbidden in module code: `pydantic.BaseModel` for DTOs, and SQLAlchemy `DeclarativeBase` + `Mapped[...]` / `mapped_column(...)` for tables. Autogenerate, fixtures, Inertia serialization, and the shared mixins all assume the SQLModel metaclass.
|
|
34
36
|
|
|
35
37
|
### 2. The file-size cap
|
|
@@ -39,7 +41,7 @@ Treat 300 lines as the design pressure on every `.py`, `.ts`, and `.tsx` file (t
|
|
|
39
41
|
New module settings and their app-state container live in `core/settings.py`
|
|
40
42
|
and `core/services.py`; HTTP dependencies and services live in `web/`. Keep
|
|
41
43
|
root lookup files in place and put non-page frontend code in `ui/`. See
|
|
42
|
-
[Module layout](
|
|
44
|
+
[Module layout](https://docs.py.simplemodule.dev/module-layout).
|
|
43
45
|
|
|
44
46
|
### 3. Per-module settings: `register_module_settings` → `app.state.<module>`
|
|
45
47
|
|
|
@@ -112,7 +114,7 @@ Locale-related diagnostics: SM013 (missing file), SM014 (missing keys vs default
|
|
|
112
114
|
|
|
113
115
|
### 9. Don't re-enable the silenced ty rules
|
|
114
116
|
|
|
115
|
-
Projects using
|
|
117
|
+
Projects using `ty` 0.0.100 should globally suppress `missing-attribute`, `missing-union-attribute`, `unsupported-operator`, `unknown-argument`, `no-matching-overload`, `invalid-argument-type`, and `invalid-assignment` in `pyproject.toml`. SQLModel runtime-instruments fields as SQLAlchemy attributes, so the type checker can't see what's there (and `model_config = ConfigDict(...)` clashes with ty's internal `SQLModelConfig` type, which `invalid-assignment` covers). Real bugs surface in tests. Line-level suppressions use ty's rule names, `# ty: ignore[<rule>]`; a mypy-style `# type: ignore[arg-type]` silences nothing under ty.
|
|
116
118
|
|
|
117
119
|
### 10. Declare external asset origins with `register_csp_sources`
|
|
118
120
|
|
|
@@ -27,11 +27,17 @@ make migrate
|
|
|
27
27
|
same `create_module` as `smpy create-module`, so both produce the same tree
|
|
28
28
|
below (permissions, menu item with `label_key`, `core/constants.py`, CRUD sample,
|
|
29
29
|
`locales/en.json`); the in-repo variant adds workspace-sourced `pyproject.toml`
|
|
30
|
-
metadata
|
|
30
|
+
metadata and a `LICENSE`. The pages read their text from `locales/en.json`
|
|
31
|
+
through `t(keys.<module>.…)`; the host's `make gen-i18n` (also run by
|
|
32
|
+
`make install` and each dev boot) adds the module to `keys`. A `--standalone`
|
|
33
|
+
module repo gets pages with literal English instead, since it has no host to
|
|
34
|
+
generate `keys`. For a **standalone publishable
|
|
31
35
|
package** (its own repo, with CI + PyPI `publish.yml`), use
|
|
32
36
|
`smpy create-module orders`; pass `--standalone` to force the `.github/`
|
|
33
37
|
workflows, then `uv sync` (or `pip install -e ./orders`) to install it into the
|
|
34
|
-
host.
|
|
38
|
+
host. Inside a `smpy new` app, `smpy create-module orders --dest modules/orders`
|
|
39
|
+
makes a workspace member and prints the app's steps (`smpy add … --path host`,
|
|
40
|
+
`make install`, `make migration`); don't run `uv sync` inside the module there.
|
|
35
41
|
|
|
36
42
|
## What scaffolding produces
|
|
37
43
|
|
|
@@ -66,7 +72,7 @@ Modules use this area layout.
|
|
|
66
72
|
Area initializers hold only a docstring. Private helpers stay in their area.
|
|
67
73
|
Tests have no `__init__.py`, keep `conftest.py` at their root and use globally
|
|
68
74
|
unique `test_orders_*.py` basenames; JS tests stay in `tests-js/`.
|
|
69
|
-
See [Module layout](
|
|
75
|
+
See [Module layout](https://docs.py.simplemodule.dev/module-layout) for the lookup consumers and shim policy.
|
|
70
76
|
|
|
71
77
|
## The contract: pyproject.toml + module.py
|
|
72
78
|
|