simple-module-cli 0.0.42__py3-none-any.whl → 0.0.44__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/framework_repo.py +1 -0
- simple_module_cli/git_source.py +3 -87
- simple_module_cli/git_versions.py +114 -0
- simple_module_cli/package_update.py +1 -1
- simple_module_cli/package_update_deps.py +9 -2
- simple_module_cli/pypi.py +12 -5
- simple_module_cli/pyproject_edit.py +22 -6
- simple_module_cli/requirements.py +50 -30
- simple_module_cli/scaffolding.py +3 -0
- simple_module_cli/skills/README.md +1 -0
- simple_module_cli/skills/simple-module-cli/SKILL.md +1 -1
- simple_module_cli/skills/simple-module-conventions/SKILL.md +7 -2
- simple_module_cli/skills/simple-module-creating/SKILL.md +26 -21
- simple_module_cli/skills/simple-module-database/SKILL.md +6 -3
- simple_module_cli/skills/simple-module-inertia-pages/SKILL.md +4 -3
- simple_module_cli/skills/simple-module-migrations/SKILL.md +2 -2
- simple_module_cli/skills/simple-module-page-perf/SKILL.md +157 -0
- simple_module_cli/skills/simple-module-page-perf/scripts/page_audit/__main__.py +245 -0
- simple_module_cli/skills/simple-module-page-perf/scripts/page_audit/audit_browser.py +208 -0
- simple_module_cli/skills/simple-module-page-perf/scripts/page_audit/audit_crawl.py +79 -0
- simple_module_cli/skills/simple-module-page-perf/scripts/page_audit/audit_report.py +171 -0
- simple_module_cli/skills/simple-module-page-perf/scripts/page_audit/audit_server.py +175 -0
- simple_module_cli/skills/simple-module-registries/SKILL.md +1 -1
- simple_module_cli/skills/simple-module-testing/SKILL.md +39 -5
- simple_module_cli/templates/docker/dockerignore +1 -1
- simple_module_cli/templates/host/_optional/background_tasks/run_worker.py +3 -3
- simple_module_cli/templates/host/client_app/module-assets.ts +6 -4
- simple_module_cli/templates/host/migrations/env.py +3 -2
- simple_module_cli/templates/host/templates/index.html +1 -1
- simple_module_cli/templates/module/README.md.tpl +11 -0
- simple_module_cli/templates/module/__PACKAGE__/contracts/schemas.py.tpl +1 -1
- simple_module_cli/templates/module/__PACKAGE__/core/__init__.py +1 -0
- simple_module_cli/templates/module/__PACKAGE__/{services.py.tpl → core/services.py.tpl} +1 -1
- simple_module_cli/templates/module/__PACKAGE__/models.py.tpl +1 -1
- simple_module_cli/templates/module/__PACKAGE__/module.py.tpl +5 -5
- simple_module_cli/templates/module/__PACKAGE__/web/__init__.py +1 -0
- simple_module_cli/templates/module/__PACKAGE__/{deps.py.tpl → web/deps.py.tpl} +1 -1
- simple_module_cli/templates/module/__PACKAGE__/web/endpoints/__init__.py +1 -0
- simple_module_cli/templates/module/__PACKAGE__/{endpoints → web/endpoints}/api.py.tpl +8 -8
- {simple_module_cli-0.0.42.data/data/simple_module_cli/templates/module/__PACKAGE__ → simple_module_cli/templates/module/__PACKAGE__/web}/endpoints/views.py.tpl +7 -7
- simple_module_cli/templates/module/_optional/framework_repo/README.md.tpl +9 -1
- simple_module_cli/templates/module/_optional/framework_repo/pyproject.toml.tpl +1 -0
- simple_module_cli/templates/module/pyproject.toml.tpl +1 -0
- simple_module_cli/templates/module/tests/conftest.py +1 -0
- simple_module_cli/templates/module/tests/core/contracts/test___PACKAGE___schemas.py.tpl +26 -0
- simple_module_cli/templates/module/tests/core/module/test___PACKAGE___module.py.tpl +27 -0
- simple_module_cli-0.0.42.data/data/simple_module_cli/templates/module/tests/test___PACKAGE__.py.tpl → simple_module_cli/templates/module/tests/web/crud/test___PACKAGE___crud.py.tpl +3 -51
- simple_module_cli/update_cmd.py +11 -2
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/docker/dockerignore +1 -1
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/_optional/background_tasks/run_worker.py +3 -3
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/client_app/module-assets.ts +6 -4
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/migrations/env.py +3 -2
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/templates/index.html +1 -1
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/README.md.tpl +11 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/__PACKAGE__/contracts/schemas.py.tpl +1 -1
- simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/__PACKAGE__/core/__init__.py +1 -0
- {simple_module_cli-0.0.42.data/data/simple_module_cli/templates/module/__PACKAGE__ → simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/__PACKAGE__/core}/services.py.tpl +1 -1
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/__PACKAGE__/models.py.tpl +1 -1
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/__PACKAGE__/module.py.tpl +5 -5
- simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/__PACKAGE__/web/__init__.py +1 -0
- {simple_module_cli-0.0.42.data/data/simple_module_cli/templates/module/__PACKAGE__ → simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/__PACKAGE__/web}/deps.py.tpl +1 -1
- simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/__PACKAGE__/web/endpoints/__init__.py +1 -0
- {simple_module_cli-0.0.42.data/data/simple_module_cli/templates/module/__PACKAGE__ → simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/__PACKAGE__/web}/endpoints/api.py.tpl +8 -8
- {simple_module_cli/templates/module/__PACKAGE__ → simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/__PACKAGE__/web}/endpoints/views.py.tpl +7 -7
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/_optional/framework_repo/README.md.tpl +9 -1
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/_optional/framework_repo/pyproject.toml.tpl +1 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/pyproject.toml.tpl +1 -0
- simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/tests/conftest.py +1 -0
- simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/tests/core/contracts/test___PACKAGE___schemas.py.tpl +26 -0
- simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/tests/core/module/test___PACKAGE___module.py.tpl +27 -0
- simple_module_cli/templates/module/tests/test___PACKAGE__.py.tpl → simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/tests/web/crud/test___PACKAGE___crud.py.tpl +3 -51
- {simple_module_cli-0.0.42.dist-info → simple_module_cli-0.0.44.dist-info}/METADATA +3 -2
- {simple_module_cli-0.0.42.dist-info → simple_module_cli-0.0.44.dist-info}/RECORD +138 -121
- simple_module_cli/templates/module/__PACKAGE__/endpoints/__init__.py +0 -0
- simple_module_cli-0.0.42.data/data/simple_module_cli/templates/module/__PACKAGE__/endpoints/__init__.py +0 -0
- /simple_module_cli/templates/module/__PACKAGE__/{constants.py.tpl → core/constants.py.tpl} +0 -0
- /simple_module_cli/templates/module/__PACKAGE__/{settings.py.tpl → core/settings.py.tpl} +0 -0
- /simple_module_cli/templates/module/__PACKAGE__/{service.py.tpl → web/service.py.tpl} +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/docker/Makefile.snippet +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/docker/compose-base-postgres.yml.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/docker/compose-base-sqlite.yml.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/docker/compose-tasks-postgres.yml.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/docker/compose-tasks-sqlite.yml.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/docker/compose-worker.yml.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/docker/host-flat.Dockerfile +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/docker/host.Dockerfile +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/docker/worker.Dockerfile.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/.env.example +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/.gitignore +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/Makefile +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/README.md.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/_optional/background_tasks/Makefile.snippet +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/alembic.ini +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/client_app/app.tsx +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/client_app/main.tsx +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/client_app/package.json.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/client_app/pages/Error.tsx +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/client_app/pages/Landing.tsx +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/client_app/pages.ts +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/client_app/styles.css +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/client_app/tsconfig.json +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/client_app/vite.config.ts +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/client_app/vite.dev-url.ts +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/main.py +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/migrations/script.py.mako +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/migrations/versions/.gitkeep +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/pyproject.toml.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/host/routes.py +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/.github/workflows/ci.yml +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/.github/workflows/publish.yml.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/.gitignore +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/__PACKAGE__/__init__.py +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/__PACKAGE__/contracts/__init__.py.tpl +0 -0
- {simple_module_cli-0.0.42.data/data/simple_module_cli/templates/module/__PACKAGE__ → simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/__PACKAGE__/core}/constants.py.tpl +0 -0
- {simple_module_cli-0.0.42.data/data/simple_module_cli/templates/module/__PACKAGE__ → simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/__PACKAGE__/core}/settings.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/__PACKAGE__/locales/en.json.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/__PACKAGE__/pages/Browse.tsx.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/__PACKAGE__/pages/Create.tsx.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/__PACKAGE__/pages/Edit.tsx.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/__PACKAGE__/pages/api.generated.ts.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/__PACKAGE__/pages/api.ts.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/__PACKAGE__/py.typed +0 -0
- {simple_module_cli-0.0.42.data/data/simple_module_cli/templates/module/__PACKAGE__ → simple_module_cli-0.0.44.data/data/simple_module_cli/templates/module/__PACKAGE__/web}/service.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/_optional/framework_repo/LICENSE +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/_optional/framework_repo/__PACKAGE__/pages/Browse.tsx.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/_optional/framework_repo/__PACKAGE__/pages/Create.tsx.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/_optional/framework_repo/__PACKAGE__/pages/Edit.tsx.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/_optional/standalone/package.json.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/_optional/standalone/tsconfig.json.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/package.json.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/module/tsconfig.json.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/workspace/.env.example +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/workspace/.gitignore +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/workspace/Makefile +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/workspace/README.md.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/workspace/package.json.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.44.data}/data/simple_module_cli/templates/workspace/pyproject.toml.tpl +0 -0
- {simple_module_cli-0.0.42.dist-info → simple_module_cli-0.0.44.dist-info}/WHEEL +0 -0
- {simple_module_cli-0.0.42.dist-info → simple_module_cli-0.0.44.dist-info}/entry_points.txt +0 -0
- {simple_module_cli-0.0.42.dist-info → simple_module_cli-0.0.44.dist-info}/licenses/LICENSE +0 -0
|
@@ -70,6 +70,7 @@ def update_root_pyproject(root: Path, name: str) -> None:
|
|
|
70
70
|
root_toml = root / "pyproject.toml"
|
|
71
71
|
content = root_toml.read_text()
|
|
72
72
|
src_path = f"modules/{name}"
|
|
73
|
+
# Pytest recursively collects area/feature tests from this one root.
|
|
73
74
|
test_path = f"modules/{name}/tests"
|
|
74
75
|
|
|
75
76
|
if f'"{src_path}",' in content and f'"{test_path}"' in content:
|
simple_module_cli/git_source.py
CHANGED
|
@@ -11,15 +11,16 @@ tomlkit alone (see test_no_framework_deps.py); clones are read with tomllib.
|
|
|
11
11
|
|
|
12
12
|
from __future__ import annotations
|
|
13
13
|
|
|
14
|
-
import re
|
|
15
14
|
import subprocess
|
|
16
15
|
import tomllib
|
|
17
|
-
from collections.abc import Callable
|
|
16
|
+
from collections.abc import Callable
|
|
18
17
|
from dataclasses import dataclass
|
|
19
18
|
from pathlib import Path
|
|
20
19
|
from typing import Literal
|
|
21
20
|
from urllib.parse import urlsplit
|
|
22
21
|
|
|
22
|
+
from simple_module_cli.git_versions import derive_range, pick_latest_tag, satisfies, version_tuple
|
|
23
|
+
|
|
23
24
|
__all__ = [
|
|
24
25
|
"FoundModule",
|
|
25
26
|
"GitAddSpec",
|
|
@@ -94,91 +95,6 @@ def _parse_git(raw: str) -> GitAddSpec:
|
|
|
94
95
|
return GitAddSpec(url=body, ref=ref, subdirectory=subdirectory)
|
|
95
96
|
|
|
96
97
|
|
|
97
|
-
# --- version helpers (no `packaging` dep — CLI depends on typer + tomlkit only) ---
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def version_tuple(v: str) -> tuple[int, ...]:
|
|
101
|
-
parts: list[int] = []
|
|
102
|
-
for part in v.split("."):
|
|
103
|
-
digits = ""
|
|
104
|
-
for ch in part:
|
|
105
|
-
if ch.isdigit():
|
|
106
|
-
digits += ch
|
|
107
|
-
else:
|
|
108
|
-
break
|
|
109
|
-
parts.append(int(digits) if digits else 0)
|
|
110
|
-
return tuple(parts)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
def _cmp(a: str, b: str) -> int:
|
|
114
|
-
ta, tb = version_tuple(a), version_tuple(b)
|
|
115
|
-
width = max(len(ta), len(tb))
|
|
116
|
-
ta += (0,) * (width - len(ta))
|
|
117
|
-
tb += (0,) * (width - len(tb))
|
|
118
|
-
if ta != tb:
|
|
119
|
-
return (ta > tb) - (ta < tb)
|
|
120
|
-
pa, pb = _prerelease_key(a), _prerelease_key(b)
|
|
121
|
-
return (pa > pb) - (pa < pb)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
def _prerelease_key(version: str) -> tuple[int, int]:
|
|
125
|
-
# shortcut: handles Python a/b/rc suffixes; use a full parser for other version schemes.
|
|
126
|
-
match = re.search(r"(alpha|beta|a|b|rc)(\d*)$", version, re.IGNORECASE)
|
|
127
|
-
if match is None:
|
|
128
|
-
return (3, 0)
|
|
129
|
-
return (
|
|
130
|
-
{"a": 0, "alpha": 0, "b": 1, "beta": 1, "rc": 2}[match[1].lower()],
|
|
131
|
-
int(match[2] or "0"),
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
_OPS = ("<=", ">=", "==", "!=", "<", ">")
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
def satisfies(version: str, constraint: str) -> bool:
|
|
139
|
-
for clause in constraint.split(","):
|
|
140
|
-
clause = clause.strip()
|
|
141
|
-
if not clause:
|
|
142
|
-
continue
|
|
143
|
-
for op in _OPS:
|
|
144
|
-
if clause.startswith(op):
|
|
145
|
-
bound = clause[len(op) :].strip()
|
|
146
|
-
c = _cmp(version, bound)
|
|
147
|
-
ok = {
|
|
148
|
-
"<=": c <= 0,
|
|
149
|
-
">=": c >= 0,
|
|
150
|
-
"==": c == 0,
|
|
151
|
-
"!=": c != 0,
|
|
152
|
-
"<": c < 0,
|
|
153
|
-
">": c > 0,
|
|
154
|
-
}[op]
|
|
155
|
-
if not ok:
|
|
156
|
-
return False
|
|
157
|
-
break
|
|
158
|
-
else:
|
|
159
|
-
return False
|
|
160
|
-
return True
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
def derive_range(version: str) -> str:
|
|
164
|
-
major = version_tuple(version)[0]
|
|
165
|
-
upper = "1.0" if major == 0 else f"{major + 1}.0"
|
|
166
|
-
return f">={version},<{upper}"
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
def pick_latest_tag(tags: Iterable[str], constraint: str | None) -> str | None:
|
|
170
|
-
best: str | None = None
|
|
171
|
-
for tag in tags:
|
|
172
|
-
if not tag.startswith("v") or len(tag) < 2 or not tag[1].isdigit():
|
|
173
|
-
continue
|
|
174
|
-
ver = tag[1:]
|
|
175
|
-
if constraint and not satisfies(ver, constraint):
|
|
176
|
-
continue
|
|
177
|
-
if best is None or _cmp(ver, best[1:]) > 0:
|
|
178
|
-
best = tag
|
|
179
|
-
return best
|
|
180
|
-
|
|
181
|
-
|
|
182
98
|
# --- remote resolution + clone scanning ---
|
|
183
99
|
|
|
184
100
|
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Version policies and release-tag selection for git module sources."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from collections.abc import Iterable
|
|
7
|
+
|
|
8
|
+
from packaging.version import InvalidVersion
|
|
9
|
+
|
|
10
|
+
from simple_module_cli.requirements import _compare as _cmp
|
|
11
|
+
from simple_module_cli.requirements import (
|
|
12
|
+
_compatible_band,
|
|
13
|
+
_matches_wildcard,
|
|
14
|
+
is_valid_version,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
# --- version helpers ---
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def version_tuple(v: str) -> tuple[int, ...]:
|
|
21
|
+
parts: list[int] = []
|
|
22
|
+
for part in v.split("."):
|
|
23
|
+
digits = ""
|
|
24
|
+
for ch in part:
|
|
25
|
+
if ch.isdigit():
|
|
26
|
+
digits += ch
|
|
27
|
+
else:
|
|
28
|
+
break
|
|
29
|
+
parts.append(int(digits) if digits else 0)
|
|
30
|
+
return tuple(parts)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _prerelease_key(version: str) -> tuple[int, int]:
|
|
34
|
+
# shortcut: handles Python a/b/rc suffixes; use a full parser for other version schemes.
|
|
35
|
+
match = re.search(r"(alpha|beta|a|b|rc)(\d*)$", version, re.IGNORECASE)
|
|
36
|
+
if match is None:
|
|
37
|
+
return (3, 0)
|
|
38
|
+
return (
|
|
39
|
+
{"a": 0, "alpha": 0, "b": 1, "beta": 1, "rc": 2}[match[1].lower()],
|
|
40
|
+
int(match[2] or "0"),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
_OPS = ("<=", ">=", "==", "!=", "~=", "<", ">")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def satisfies(version: str, constraint: str) -> bool:
|
|
48
|
+
for clause in constraint.split(","):
|
|
49
|
+
clause = clause.strip()
|
|
50
|
+
if not clause:
|
|
51
|
+
continue
|
|
52
|
+
for op in _OPS:
|
|
53
|
+
if clause.startswith(op):
|
|
54
|
+
bound = clause[len(op) :].strip()
|
|
55
|
+
if op in ("==", "!=") and bound.endswith(".*"):
|
|
56
|
+
if (op == "==") != _matches_wildcard(version, bound):
|
|
57
|
+
return False
|
|
58
|
+
break
|
|
59
|
+
if op == "<" and _excluded_prerelease(version, bound):
|
|
60
|
+
return False
|
|
61
|
+
try:
|
|
62
|
+
c = _cmp(version, bound)
|
|
63
|
+
except InvalidVersion:
|
|
64
|
+
return False
|
|
65
|
+
if op == "~=":
|
|
66
|
+
band = _compatible_band(bound)
|
|
67
|
+
if c < 0 or band is None or not _matches_wildcard(version, band):
|
|
68
|
+
return False
|
|
69
|
+
break
|
|
70
|
+
ok = {
|
|
71
|
+
"<=": c <= 0,
|
|
72
|
+
">=": c >= 0,
|
|
73
|
+
"==": c == 0,
|
|
74
|
+
"!=": c != 0,
|
|
75
|
+
"<": c < 0,
|
|
76
|
+
">": c > 0,
|
|
77
|
+
}[op]
|
|
78
|
+
if not ok:
|
|
79
|
+
return False
|
|
80
|
+
break
|
|
81
|
+
else:
|
|
82
|
+
return False
|
|
83
|
+
return True
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _excluded_prerelease(version: str, bound: str) -> bool:
|
|
87
|
+
"""PEP 440: ``<0.4`` excludes ``0.4.0rc1`` unless the bound is itself a pre-release."""
|
|
88
|
+
final = (3, 0)
|
|
89
|
+
if _prerelease_key(version) == final or _prerelease_key(bound) != final:
|
|
90
|
+
return False
|
|
91
|
+
width = max(len(version_tuple(version)), len(version_tuple(bound)))
|
|
92
|
+
pad = (0,) * width
|
|
93
|
+
return (version_tuple(version) + pad)[:width] == (version_tuple(bound) + pad)[:width]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def derive_range(version: str) -> str:
|
|
97
|
+
major = version_tuple(version)[0]
|
|
98
|
+
upper = "1.0" if major == 0 else f"{major + 1}.0"
|
|
99
|
+
return f">={version},<{upper}"
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def pick_latest_tag(tags: Iterable[str], constraint: str | None) -> str | None:
|
|
103
|
+
best: str | None = None
|
|
104
|
+
for tag in tags:
|
|
105
|
+
if not tag.startswith("v") or len(tag) < 2 or not tag[1].isdigit():
|
|
106
|
+
continue
|
|
107
|
+
ver = tag[1:]
|
|
108
|
+
if not is_valid_version(ver):
|
|
109
|
+
continue
|
|
110
|
+
if constraint and not satisfies(ver, constraint):
|
|
111
|
+
continue
|
|
112
|
+
if best is None or _cmp(ver, best[1:]) > 0:
|
|
113
|
+
best = tag
|
|
114
|
+
return best
|
|
@@ -55,7 +55,7 @@ def _npm_target(cache: dict[str, str | None], skips: list[Skip]) -> tuple[str |
|
|
|
55
55
|
if normalize(skip.package) == _CORE:
|
|
56
56
|
return None, f"simple_module_core not updated ({skip.reason})"
|
|
57
57
|
latest = next((v for n, v in cache.items() if normalize(n) == _CORE), None)
|
|
58
|
-
return latest, None if latest else "simple_module_core
|
|
58
|
+
return latest, None if latest else "simple_module_core has no eligible release on PyPI"
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
def _print_summary(changes: list[Change], skips: list[Skip], dry_run: bool) -> None:
|
|
@@ -11,6 +11,7 @@ import tomlkit
|
|
|
11
11
|
from tomlkit.items import Array
|
|
12
12
|
|
|
13
13
|
from simple_module_cli.requirements import parse_requirement, rewrite_requirement
|
|
14
|
+
from simple_module_cli.uv_workspace import is_workspace_member
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
@dataclass(frozen=True)
|
|
@@ -72,7 +73,7 @@ def workspace_member_dirs(root_pyproject: Path, doc: tomlkit.TOMLDocument) -> li
|
|
|
72
73
|
out: list[Path] = []
|
|
73
74
|
for pattern in members:
|
|
74
75
|
for match in sorted(base.glob(str(pattern))):
|
|
75
|
-
if (match / "pyproject.toml").is_file():
|
|
76
|
+
if (match / "pyproject.toml").is_file() and is_workspace_member(base, match):
|
|
76
77
|
out.append(match / "pyproject.toml")
|
|
77
78
|
return list(dict.fromkeys(p.resolve() for p in out))
|
|
78
79
|
|
|
@@ -140,7 +141,13 @@ def process_file(
|
|
|
140
141
|
continue
|
|
141
142
|
latest = cache.get(name)
|
|
142
143
|
if latest is None:
|
|
143
|
-
skips.append(
|
|
144
|
+
skips.append(
|
|
145
|
+
Skip(
|
|
146
|
+
path,
|
|
147
|
+
name,
|
|
148
|
+
"no eligible release on PyPI (missing, or only pre-release/yanked)",
|
|
149
|
+
)
|
|
150
|
+
)
|
|
144
151
|
continue
|
|
145
152
|
result = rewrite_requirement(dep_str, latest, loosen=loosen)
|
|
146
153
|
if result.spec is None:
|
simple_module_cli/pypi.py
CHANGED
|
@@ -14,7 +14,9 @@ import urllib.request
|
|
|
14
14
|
from collections.abc import Callable
|
|
15
15
|
from typing import Any
|
|
16
16
|
|
|
17
|
-
from
|
|
17
|
+
from packaging.version import Version
|
|
18
|
+
|
|
19
|
+
from simple_module_cli.requirements import is_valid_version
|
|
18
20
|
|
|
19
21
|
__all__ = ["PYPI_URL", "Fetcher", "default_fetcher", "fetch_latest"]
|
|
20
22
|
|
|
@@ -23,8 +25,8 @@ Fetcher = Callable[[str], dict[str, Any]]
|
|
|
23
25
|
PYPI_URL = "https://pypi.org/pypi/{name}/json"
|
|
24
26
|
|
|
25
27
|
# PEP 440 release segments contain only digits + dots; any letter signals
|
|
26
|
-
# a pre/post/dev release (a, b, rc, post, dev).
|
|
27
|
-
#
|
|
28
|
+
# a pre/post/dev release (a, b, rc, post, dev). Deliberately stricter than
|
|
29
|
+
# ``Version.is_prerelease``, which would let ``.post`` releases through as stable.
|
|
28
30
|
_PRE_RELEASE_RE = re.compile(r"[a-zA-Z]")
|
|
29
31
|
|
|
30
32
|
|
|
@@ -43,11 +45,16 @@ def fetch_latest(name: str, *, include_pre: bool, fetcher: Fetcher) -> str | Non
|
|
|
43
45
|
continue
|
|
44
46
|
if not include_pre and _PRE_RELEASE_RE.search(version):
|
|
45
47
|
continue
|
|
48
|
+
if not is_valid_version(version):
|
|
49
|
+
continue
|
|
46
50
|
candidates.append(version)
|
|
47
51
|
if candidates:
|
|
48
|
-
return max(candidates, key=
|
|
52
|
+
return max(candidates, key=Version)
|
|
53
|
+
if releases:
|
|
54
|
+
return None
|
|
49
55
|
info = data.get("info") or {}
|
|
50
|
-
|
|
56
|
+
fallback = info.get("version")
|
|
57
|
+
return fallback if is_valid_version(fallback) else None
|
|
51
58
|
|
|
52
59
|
|
|
53
60
|
def default_fetcher(url: str) -> dict[str, Any]:
|
|
@@ -14,6 +14,7 @@ import tomlkit
|
|
|
14
14
|
from tomlkit.items import Array, Table
|
|
15
15
|
|
|
16
16
|
from simple_module_cli.git_source import RefInfo
|
|
17
|
+
from simple_module_cli.requirements import parse_requirement
|
|
17
18
|
|
|
18
19
|
__all__ = [
|
|
19
20
|
"dep_constraint",
|
|
@@ -65,20 +66,35 @@ def dep_constraint(doc: tomlkit.TOMLDocument, dist_name: str) -> str | None:
|
|
|
65
66
|
idx = _dep_index(deps, dist_name)
|
|
66
67
|
if idx is None:
|
|
67
68
|
return None
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return None
|
|
69
|
+
parsed = parse_requirement(str(deps[idx]))
|
|
70
|
+
if parsed is None or not parsed.clauses:
|
|
71
|
+
return None
|
|
72
|
+
return ",".join(f"{op}{version}" for op, version in parsed.clauses)
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
def write_dependency(
|
|
75
|
+
def write_dependency(
|
|
76
|
+
doc: tomlkit.TOMLDocument,
|
|
77
|
+
dist_name: str,
|
|
78
|
+
constraint: str,
|
|
79
|
+
*,
|
|
80
|
+
keep_extras_and_marker: bool = False,
|
|
81
|
+
) -> bool:
|
|
82
|
+
"""Write ``dist_name`` + ``constraint``, replacing any existing declaration.
|
|
83
|
+
|
|
84
|
+
``keep_extras_and_marker`` is for version bumps (``smpy update``): the
|
|
85
|
+
existing extras and environment marker survive and only the version
|
|
86
|
+
changes (#735). ``smpy add`` writes the declaration it was given.
|
|
87
|
+
"""
|
|
76
88
|
deps = _dependencies(doc)
|
|
77
89
|
entry = f"{dist_name}{constraint}"
|
|
78
90
|
idx = _dep_index(deps, dist_name)
|
|
79
91
|
if idx is None:
|
|
80
92
|
deps.append(entry)
|
|
81
93
|
return True
|
|
94
|
+
if keep_extras_and_marker:
|
|
95
|
+
parsed = parse_requirement(str(deps[idx]))
|
|
96
|
+
if parsed:
|
|
97
|
+
entry = f"{dist_name}{parsed.extras}{constraint}{parsed.marker}"
|
|
82
98
|
if str(deps[idx]).strip() == entry:
|
|
83
99
|
return False
|
|
84
100
|
deps[idx] = entry
|
|
@@ -16,6 +16,9 @@ from __future__ import annotations
|
|
|
16
16
|
import re
|
|
17
17
|
from dataclasses import dataclass
|
|
18
18
|
|
|
19
|
+
from packaging.specifiers import InvalidSpecifier, Specifier
|
|
20
|
+
from packaging.version import InvalidVersion, Version
|
|
21
|
+
|
|
19
22
|
__all__ = ["ParsedRequirement", "RewriteResult", "parse_requirement", "rewrite_requirement"]
|
|
20
23
|
|
|
21
24
|
# Longest-first: ``===`` must win over ``==``, and ``>=`` over ``>``.
|
|
@@ -30,8 +33,8 @@ _FLOOR_OPS = frozenset({"==", "===", ">="})
|
|
|
30
33
|
|
|
31
34
|
#: Suffix marking a PEP 440 wildcard (``==1.4.*``, ``!=1.0.*``). These match on
|
|
32
35
|
#: a *prefix* of the release segments, so they must never go through the
|
|
33
|
-
#: numeric comparison —
|
|
34
|
-
#:
|
|
36
|
+
#: numeric comparison — a numeric compare would read ``1.0.*`` as ``1.0.0`` and
|
|
37
|
+
#: quietly answer the wrong question.
|
|
35
38
|
_WILDCARD = ".*"
|
|
36
39
|
|
|
37
40
|
|
|
@@ -59,29 +62,42 @@ class RewriteResult:
|
|
|
59
62
|
reason: str | None = None
|
|
60
63
|
|
|
61
64
|
|
|
62
|
-
def
|
|
63
|
-
"""
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
parts: list[int] = []
|
|
70
|
-
for part in version.split("."):
|
|
71
|
-
digits = re.match(r"\d+", part)
|
|
72
|
-
parts.append(int(digits.group()) if digits else 0)
|
|
73
|
-
return tuple(parts)
|
|
65
|
+
def is_valid_version(version: str | None) -> bool:
|
|
66
|
+
"""Is ``version`` a string PEP 440 can order? ``None`` and legacy spellings are not."""
|
|
67
|
+
try:
|
|
68
|
+
Version(version) # ty: ignore[invalid-argument-type] # None -> TypeError, handled
|
|
69
|
+
except (InvalidVersion, TypeError):
|
|
70
|
+
return False
|
|
71
|
+
return True
|
|
74
72
|
|
|
75
73
|
|
|
76
74
|
def _compare(left: str, right: str) -> int:
|
|
77
|
-
"""Three-way
|
|
78
|
-
a, b =
|
|
79
|
-
width = max(len(a), len(b))
|
|
80
|
-
a += (0,) * (width - len(a))
|
|
81
|
-
b += (0,) * (width - len(b))
|
|
75
|
+
"""Three-way PEP 440 comparison, including pre/dev/post releases."""
|
|
76
|
+
a, b = Version(left), Version(right)
|
|
82
77
|
return (a > b) - (a < b)
|
|
83
78
|
|
|
84
79
|
|
|
80
|
+
def _unparseable(parsed: ParsedRequirement, latest: str) -> str | None:
|
|
81
|
+
"""The first version that is not valid PEP 440, or ``None``.
|
|
82
|
+
|
|
83
|
+
Legacy spellings (``==1.x``, ``===local-build``) can't be ordered, so the
|
|
84
|
+
requirement is reported as a skip instead of aborting the whole run.
|
|
85
|
+
"""
|
|
86
|
+
for candidate in (
|
|
87
|
+
latest,
|
|
88
|
+
*(v[: -len(_WILDCARD)] if v.endswith(_WILDCARD) else v for _, v in parsed.clauses),
|
|
89
|
+
):
|
|
90
|
+
if not is_valid_version(candidate):
|
|
91
|
+
return candidate
|
|
92
|
+
for op, version in parsed.clauses:
|
|
93
|
+
if op in ("<", "<=", "!=") and not version.endswith(_WILDCARD):
|
|
94
|
+
try: # a valid Version can still be an invalid bound, e.g. ``<1.0+local``
|
|
95
|
+
Specifier(f"{op}{version}")
|
|
96
|
+
except InvalidSpecifier:
|
|
97
|
+
return version
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
|
|
85
101
|
def parse_requirement(spec: str) -> ParsedRequirement | None:
|
|
86
102
|
"""Split a PEP 508 requirement string, or ``None`` if the name is unusable."""
|
|
87
103
|
base, sep, marker = spec.partition(";")
|
|
@@ -117,9 +133,10 @@ def _render(parsed: ParsedRequirement, clauses: tuple[tuple[str, str], ...]) ->
|
|
|
117
133
|
|
|
118
134
|
def _matches_wildcard(version: str, pattern: str) -> bool:
|
|
119
135
|
"""Does ``version`` fall under a PEP 440 wildcard like ``1.4.*``?"""
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
136
|
+
try:
|
|
137
|
+
return Specifier(f"=={pattern}").contains(version, prereleases=True)
|
|
138
|
+
except InvalidSpecifier:
|
|
139
|
+
return False
|
|
123
140
|
|
|
124
141
|
|
|
125
142
|
def _compatible_band(version: str) -> str | None:
|
|
@@ -151,13 +168,8 @@ def _allows(op: str, version: str, latest: str) -> bool:
|
|
|
151
168
|
if op == "~=":
|
|
152
169
|
band = _compatible_band(version)
|
|
153
170
|
return band is not None and _matches_wildcard(latest, band)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return cmp < 0
|
|
157
|
-
if op == "<=":
|
|
158
|
-
return cmp <= 0
|
|
159
|
-
if op == "!=":
|
|
160
|
-
return cmp != 0
|
|
171
|
+
if op in ("<", "<=", "!="):
|
|
172
|
+
return Specifier(f"{op}{version}").contains(latest, prereleases=True)
|
|
161
173
|
# ``>`` — already satisfied by anything newer than the pin.
|
|
162
174
|
return True
|
|
163
175
|
|
|
@@ -193,7 +205,11 @@ def _bump(op: str, version: str, latest: str) -> str:
|
|
|
193
205
|
if len(parts) < segments:
|
|
194
206
|
return version
|
|
195
207
|
candidate = ".".join(parts[:segments])
|
|
196
|
-
|
|
208
|
+
# A pre-release ``latest`` truncates to a release above itself
|
|
209
|
+
# (``1.5.0rc1`` -> ``1.5``), which nothing published satisfies yet.
|
|
210
|
+
if _compare(candidate, version) > 0 and _compare(candidate, latest) <= 0:
|
|
211
|
+
return candidate
|
|
212
|
+
return version
|
|
197
213
|
if op in _FLOOR_OPS:
|
|
198
214
|
return latest if _compare(latest, version) > 0 else version
|
|
199
215
|
return version
|
|
@@ -217,6 +233,10 @@ def rewrite_requirement(spec: str, latest: str, *, loosen: bool = False) -> Rewr
|
|
|
217
233
|
new = f"{parsed.name}{parsed.extras}>={latest}{parsed.marker}"
|
|
218
234
|
return RewriteResult(None) if new == spec.strip() else RewriteResult(new)
|
|
219
235
|
|
|
236
|
+
bad = _unparseable(parsed, latest)
|
|
237
|
+
if bad is not None:
|
|
238
|
+
return RewriteResult(None, reason=f"unsupported version spelling {bad!r}")
|
|
239
|
+
|
|
220
240
|
blocker = _excluded_by(parsed, latest)
|
|
221
241
|
if blocker is not None:
|
|
222
242
|
return RewriteResult(None, reason=f"{latest} excluded by {blocker}")
|
simple_module_cli/scaffolding.py
CHANGED
|
@@ -194,6 +194,9 @@ def create_module(
|
|
|
194
194
|
) -> Path:
|
|
195
195
|
"""Scaffold a module package at ``dest``.
|
|
196
196
|
|
|
197
|
+
Implementation lives in ``core/`` and ``web/``; nested tests mirror those
|
|
198
|
+
areas without test-package initializers. Root lookup paths stay stable.
|
|
199
|
+
|
|
197
200
|
When ``framework_version`` is a concrete version, the template's
|
|
198
201
|
forward-looking ``simple_module_*`` ranges are rewritten to an exact pin so
|
|
199
202
|
the module resolves against that framework version (e.g. ``uv add`` into the
|
|
@@ -44,6 +44,7 @@ The CLI is [vercel-labs/skills](https://github.com/vercel-labs/skills); see its
|
|
|
44
44
|
| [simple-module-database](./simple-module-database/SKILL.md) | Adding SQLModel tables, picking a mixin, or debugging session/transaction behavior |
|
|
45
45
|
| [simple-module-migrations](./simple-module-migrations/SKILL.md) | Generating, applying, or reviewing Alembic migrations after installing or changing a module |
|
|
46
46
|
| [simple-module-inertia-pages](./simple-module-inertia-pages/SKILL.md) | Adding or debugging an Inertia page in a module — render keys, shared props, common pitfalls |
|
|
47
|
+
| [simple-module-page-perf](./simple-module-page-perf/SKILL.md) | Auditing pages for speed and perceived speed — server time and SQL counts (`Server-Timing`), payloads, deferred props, navigation timing, layout shift, UX checks; ships `scripts/page_audit` |
|
|
47
48
|
| [simple-module-locales](./simple-module-locales/SKILL.md) | Adding or debugging i18n in a module — `locale_dirs()`, namespaces, CLDR plurals, the Zod-in-hook rule |
|
|
48
49
|
| [simple-module-registries](./simple-module-registries/SKILL.md) | Contributing menu items, permissions, feature flags, or events from a module |
|
|
49
50
|
| [simple-module-testing](./simple-module-testing/SKILL.md) | Writing pytest tests — picking the right fixture (`db_session` / `app` / `authenticated_client`), single-test runs, e2e |
|
|
@@ -97,7 +97,7 @@ smpy create-module orders # writes ./simple_module_orders/
|
|
|
97
97
|
smpy create-module orders --dest ./packages/orders
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
The result is a complete package: `pyproject.toml` with the entry point declared, `module.py` with `ModuleBase`/`ModuleMeta` skeleton, `models.py`, `contracts/`, `endpoints/{api,views}.py`, `pages/`, `locales/en.json`, plus
|
|
100
|
+
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
101
|
|
|
102
102
|
`<name>` accepts any case — `orders`, `Orders`, `ORDERS`, `blog_posts` all work. The CLI lowercases it for the directory and PascalCases it for `ModuleMeta.name`.
|
|
103
103
|
|
|
@@ -36,6 +36,11 @@ Forbidden in module code: `pydantic.BaseModel` for DTOs, and SQLAlchemy `Declara
|
|
|
36
36
|
|
|
37
37
|
Treat 300 lines as the design pressure on every `.py`, `.ts`, and `.tsx` file (the reference codebase enforces this in CI). When you approach it, **split by responsibility** — don't golf comments and blank lines to squeeze under.
|
|
38
38
|
|
|
39
|
+
New module settings and their app-state container live in `core/settings.py`
|
|
40
|
+
and `core/services.py`; HTTP dependencies and services live in `web/`. Keep
|
|
41
|
+
root lookup files in place and put non-page frontend code in `ui/`. See
|
|
42
|
+
[Module layout](../../docs/module-layout.md).
|
|
43
|
+
|
|
39
44
|
### 3. Per-module settings: `register_module_settings` → `app.state.<module>`
|
|
40
45
|
|
|
41
46
|
```python
|
|
@@ -44,8 +49,8 @@ from simple_module_core.module_settings import register_module_settings
|
|
|
44
49
|
|
|
45
50
|
class UsersModule(ModuleBase):
|
|
46
51
|
def register_settings(self, app: FastAPI) -> None:
|
|
47
|
-
from users.settings import UsersSettings # a DbBackedSettings subclass
|
|
48
|
-
from users.state import UsersState
|
|
52
|
+
from users.core.settings import UsersSettings # a DbBackedSettings subclass
|
|
53
|
+
from users.core.state import UsersState
|
|
49
54
|
|
|
50
55
|
register_module_settings(app, "users", UsersSettings, lambda s: UsersState(settings=s))
|
|
51
56
|
```
|
|
@@ -25,7 +25,7 @@ make migrate
|
|
|
25
25
|
|
|
26
26
|
`make new-module` (→ `scripts/new_module.py`) is the in-repo path. It calls the
|
|
27
27
|
same `create_module` as `smpy create-module`, so both produce the same tree
|
|
28
|
-
below (permissions, menu item with `label_key`, `constants.py`, CRUD sample,
|
|
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
30
|
metadata, `LICENSE`, and i18n-keyed pages. For a **standalone publishable
|
|
31
31
|
package** (its own repo, with CI + PyPI `publish.yml`), use
|
|
@@ -35,26 +35,25 @@ host.
|
|
|
35
35
|
|
|
36
36
|
## What scaffolding produces
|
|
37
37
|
|
|
38
|
-
```
|
|
38
|
+
```text
|
|
39
39
|
modules/orders/
|
|
40
|
-
├── pyproject.toml
|
|
41
|
-
├──
|
|
42
|
-
├──
|
|
43
|
-
├──
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
├──
|
|
54
|
-
├──
|
|
55
|
-
├──
|
|
56
|
-
|
|
57
|
-
└── locales/en.json
|
|
40
|
+
├── pyproject.toml, package.json, tsconfig.json
|
|
41
|
+
├── orders/
|
|
42
|
+
│ ├── __init__.py, py.typed, module.py
|
|
43
|
+
│ ├── models.py # or models/; discovered by name
|
|
44
|
+
│ ├── contracts/ # public SQLModel DTOs and extension contracts
|
|
45
|
+
│ ├── core/ # constants.py, settings.py, services.py, errors.py
|
|
46
|
+
│ ├── web/ # deps.py, service.py (or services/), private schemas
|
|
47
|
+
│ │ └── endpoints/ # api.py, views.py
|
|
48
|
+
│ ├── pages/ # Inertia pages, api.ts, api.generated.ts
|
|
49
|
+
│ ├── locales/ # <lang>.json
|
|
50
|
+
│ ├── ui/ # components/, hooks/, utils/ (when needed)
|
|
51
|
+
│ └── tasks.py, theme.css, styles.css # optional root lookup files
|
|
52
|
+
└── tests/
|
|
53
|
+
├── conftest.py # module-wide fixtures
|
|
54
|
+
├── core/module/test_orders_module.py
|
|
55
|
+
├── core/contracts/test_orders_schemas.py
|
|
56
|
+
└── web/crud/test_orders_crud.py
|
|
58
57
|
```
|
|
59
58
|
|
|
60
59
|
`make new-module` also edits `host/pyproject.toml` (adds the workspace dep), the
|
|
@@ -63,6 +62,12 @@ root `pyproject.toml` (type-check + test paths) and the `publish-pypi` matrix in
|
|
|
63
62
|
test` without further wiring. Commit the `uv.lock`, `package-lock.json` and
|
|
64
63
|
regenerated i18n key files it leaves behind.
|
|
65
64
|
|
|
65
|
+
Modules use this area layout.
|
|
66
|
+
Area initializers hold only a docstring. Private helpers stay in their area.
|
|
67
|
+
Tests have no `__init__.py`, keep `conftest.py` at their root and use globally
|
|
68
|
+
unique `test_orders_*.py` basenames; JS tests stay in `tests-js/`.
|
|
69
|
+
See [Module layout](../../docs/module-layout.md) for the lookup consumers and shim policy.
|
|
70
|
+
|
|
66
71
|
## The contract: pyproject.toml + module.py
|
|
67
72
|
|
|
68
73
|
The host discovers modules via a single entry point. If this is wrong, the module silently does nothing in dev and **fails boot in production** (strict discovery).
|
|
@@ -130,7 +135,7 @@ The new module should appear in the registered-modules log line. If it has a vie
|
|
|
130
135
|
- **Registered the module by hand in host code.** Don't — discovery is entry-point-only; host code never imports module code.
|
|
131
136
|
|
|
132
137
|
Services raise domain exceptions derived from a per-module base in
|
|
133
|
-
`
|
|
138
|
+
`core/errors.py`, never `HTTPException`. Map them in endpoints or
|
|
134
139
|
`register_exception_handlers(app)` (as in `file_storage`); translate at the
|
|
135
140
|
request boundary. Preserve existing status codes, JSON bodies and headers.
|
|
136
141
|
Endpoint-level `HTTPException` for pure request validation remains fine.
|