simple-module-cli 0.0.42__py3-none-any.whl → 0.0.43__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/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/skills/simple-module-database/SKILL.md +6 -3
- simple_module_cli/skills/simple-module-inertia-pages/SKILL.md +2 -2
- simple_module_cli/skills/simple-module-migrations/SKILL.md +2 -2
- simple_module_cli/skills/simple-module-testing/SKILL.md +30 -0
- simple_module_cli/templates/host/migrations/env.py +3 -2
- simple_module_cli/templates/host/templates/index.html +1 -1
- simple_module_cli/update_cmd.py +11 -2
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/migrations/env.py +3 -2
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/templates/index.html +1 -1
- {simple_module_cli-0.0.42.dist-info → simple_module_cli-0.0.43.dist-info}/METADATA +3 -2
- {simple_module_cli-0.0.42.dist-info → simple_module_cli-0.0.43.dist-info}/RECORD +96 -95
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/docker/Makefile.snippet +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.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.43.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.43.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.43.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.43.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.43.data}/data/simple_module_cli/templates/docker/dockerignore +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/docker/host-flat.Dockerfile +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/docker/host.Dockerfile +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/docker/worker.Dockerfile.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/.env.example +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/.gitignore +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/Makefile +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/README.md.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.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.43.data}/data/simple_module_cli/templates/host/_optional/background_tasks/run_worker.py +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/alembic.ini +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.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.43.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.43.data}/data/simple_module_cli/templates/host/client_app/module-assets.ts +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.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.43.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.43.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.43.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.43.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.43.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.43.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.43.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.43.data}/data/simple_module_cli/templates/host/main.py +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.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.43.data}/data/simple_module_cli/templates/host/migrations/versions/.gitkeep +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/pyproject.toml.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/routes.py +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.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.43.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.43.data}/data/simple_module_cli/templates/module/.gitignore +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/README.md.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/__init__.py +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/constants.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/contracts/__init__.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/contracts/schemas.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/deps.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/endpoints/__init__.py +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/endpoints/api.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/endpoints/views.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.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.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/models.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/module.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.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.43.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.43.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.43.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.43.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.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/py.typed +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/service.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/services.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/settings.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.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.43.data}/data/simple_module_cli/templates/module/_optional/framework_repo/README.md.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.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.43.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.43.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.43.data}/data/simple_module_cli/templates/module/_optional/framework_repo/pyproject.toml.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.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.43.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.43.data}/data/simple_module_cli/templates/module/package.json.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/pyproject.toml.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/tests/test___PACKAGE__.py.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/tsconfig.json.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/workspace/.env.example +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/workspace/.gitignore +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/workspace/Makefile +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/workspace/README.md.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/workspace/package.json.tpl +0 -0
- {simple_module_cli-0.0.42.data → simple_module_cli-0.0.43.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.43.dist-info}/WHEEL +0 -0
- {simple_module_cli-0.0.42.dist-info → simple_module_cli-0.0.43.dist-info}/entry_points.txt +0 -0
- {simple_module_cli-0.0.42.dist-info → simple_module_cli-0.0.43.dist-info}/licenses/LICENSE +0 -0
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}")
|
|
@@ -34,7 +34,7 @@ All modules — on Postgres and SQLite alike — share the host's single schema.
|
|
|
34
34
|
|---|---|---|
|
|
35
35
|
| `AuditMixin` | `created_at`, `updated_at`, `created_by`, `updated_by` | `created_at` defaults Python-side (and via `server_default`); `updated_at`/`created_by`/`updated_by` set by the `before_flush` listener from `current_user_id` + timestamp. |
|
|
36
36
|
| `SoftDeleteMixin` | `is_deleted`, `deleted_at`, `deleted_by` | `session.delete(obj)` → soft-delete; `SELECT` auto-filters deleted rows. |
|
|
37
|
-
| `MultiTenantMixin` | `tenant_id` | Auto-populated on insert from `current_tenant_id`. Column is **non-nullable
|
|
37
|
+
| `MultiTenantMixin` | `tenant_id` | Auto-populated on insert from `current_tenant_id`. Column is **non-nullable**; with `multi_tenant` on, inserting with no bound tenant raises `MissingTenantError` even when `tenant_id` is set explicitly (cross-tenant writes go in `all_tenants()`); creating/mutating a row for a different tenant raises `TenantIsolationError`. `SELECT` auto-scoped when `current_tenant_id` is set. |
|
|
38
38
|
| `VersionedMixin` | `version: int` | Auto-incremented on update. Use for optimistic concurrency. |
|
|
39
39
|
|
|
40
40
|
List `Base` first; Python MRO handles mixin ordering after that:
|
|
@@ -60,10 +60,10 @@ The per-request session opens once, and **the dependency commits or rolls back f
|
|
|
60
60
|
| Outcome | What `get_db` does |
|
|
61
61
|
|---|---|
|
|
62
62
|
| Request succeeded **and** session has pending writes | `commit()` (one transaction) |
|
|
63
|
-
| Request succeeded **and** session is read-only |
|
|
63
|
+
| Request succeeded **and** session is read-only | closes the transaction (rollback; loaded objects stay usable, no expiry) |
|
|
64
64
|
| Request raised | `rollback()` |
|
|
65
65
|
|
|
66
|
-
A pending-writes flag is set by
|
|
66
|
+
A pending-writes flag is set by flushes and session-executed INSERT/UPDATE/DELETE (follows savepoints: a rolled-back savepoint's writes no longer count) and by inspecting `session.new / dirty / deleted`. **Service code must not call `session.commit()`.** Manual commits double-commit on success and break the read-only optimization (which keeps read-only requests out of write-side profiling and pgBouncer transaction stats).
|
|
67
67
|
|
|
68
68
|
`session.flush()` is fine and sometimes necessary — use it when you need a DB-assigned primary key mid-request:
|
|
69
69
|
|
|
@@ -79,6 +79,9 @@ async def create_order(session: AsyncSession, payload: OrderCreate) -> Order:
|
|
|
79
79
|
## Pitfalls
|
|
80
80
|
|
|
81
81
|
- **Setting `tenant_id` manually.** `MultiTenantMixin` populates it on insert from request state (`current_tenant_id`). Setting it to a *different* tenant than the active context raises `TenantIsolationError`; changing it on an existing row raises too.
|
|
82
|
+
- **Legacy bulk APIs on tenant models.** `Session.bulk_save_objects()`, `bulk_insert_mappings()` and `bulk_update_mappings()` raise `TenantIsolationError` on a `MultiTenantMixin` model while a tenant is bound or strict mode is on; use `session.execute(insert(Model), rows)` / `session.execute(update(Model), rows)`, which are scoped. SQLite `INSERT OR REPLACE` into a tenant table and an INSERT embedded as a CTE are refused the same way.
|
|
83
|
+
- **`aliased(Model, <subquery>)` over Core.** A selectable built with `select(Other.__table__)` (or any Core read of a tenant-scoped / soft-deletable table other than the entity's own, or of the entity's own table with `GROUP BY`, `HAVING`, an aggregate or a window function) raises `TenantIsolationError`; build it from ORM entities (`select(Other)`), which the loader criteria scope. Relationships with `secondary=Link.__table__` are scoped in every loader (lazy, joined, selectin, subquery) only when `Link` is a mapped class using the mixins; a bare association `Table` is never filtered.
|
|
84
|
+
- **Objects made persistent in memory.** `make_transient_to_detached()` / `merge(load=False)` objects, and any detached object passed to `session.add()`, have their row's `tenant_id` read (once) before a flush writes them; another tenant's row raises `TenantIsolationError`. Load the row instead.
|
|
82
85
|
- **Querying `WHERE is_deleted = false` by hand.** The listener already does it. Use `execution_options(include_deleted=True)` only when you genuinely want deleted rows.
|
|
83
86
|
|
|
84
87
|
## Related skills
|
|
@@ -27,7 +27,7 @@ Boot regenerates it too; mid-session adds need the manual call before HMR sees t
|
|
|
27
27
|
|
|
28
28
|
## Shared props (no setup needed)
|
|
29
29
|
|
|
30
|
-
`InertiaLayoutDataMiddleware`
|
|
30
|
+
`InertiaLayoutDataMiddleware` prepares these for every page render (lazily: a JSON `/api` call never builds them; code that renders outside `InertiaDep` awaits `resolve_inertia_shared(request)` from `simple_module_hosting.inertia_deps`):
|
|
31
31
|
|
|
32
32
|
| Prop | Shape | Populated from |
|
|
33
33
|
|---|---|---|
|
|
@@ -35,7 +35,7 @@ Boot regenerates it too; mid-session adds need the manual call before HMR sees t
|
|
|
35
35
|
| `auth.isAuthenticated` | bool | `request.state.user` presence |
|
|
36
36
|
| `auth.permissions` | string[] | Roles → permissions expansion via the framework's permission registry |
|
|
37
37
|
| `menus` | `{ sidebar, adminSidebar, navbar, userDropdown }` | All modules' `register_menu_items()` output, auth/role-filtered |
|
|
38
|
-
| `i18n` | `{ locale, supportedLocales, messages }` | Active locale (`request.state.locale`) + flattened message bundle for that locale (`messages` is `null` on Inertia
|
|
38
|
+
| `i18n` | `{ locale, supportedLocales, audience, messages }` | Active locale (`request.state.locale`) + flattened message bundle for that locale and audience (`messages` is `null` on an Inertia visit whose `X-SM-I18n` header reports the same locale and audience; the host client sends it per tab) |
|
|
39
39
|
|
|
40
40
|
**Typing them in TSX.** A page receives its own props as typed component arguments (`export default function Browse({ items }: Props)`). Shared props are typed globally: `usePage().props.auth` is already a `SharedProps['auth']`. Components and layouts that need page props too use `usePageProps<Props>()` from `@simple-module-py/ui` (it returns `Props & SharedProps & { errors }`). Never write `usePage<{ props: X }>().props as unknown as X`; `make lint` rejects `as unknown as` outside tests unless the line carries `// cast-ok: <reason>`.
|
|
41
41
|
|
|
@@ -43,9 +43,9 @@ process_revision_directives = make_process_revision_directives(target_metadata)
|
|
|
43
43
|
# context.configure(..., render_item=render_item)
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
`build_module_metadata()` walks the `simple_module` entry-point group, imports each module's `models` submodule, and merges every module's per-module `MetaData` into one unified `MetaData`. `make_include_object(metadata)` allowlists only tables owned by installed modules — any host-owned tables (and `alembic_version`) outside the module system are preserved untouched. So one autogenerate call covers every installed module in a single pass; editable installs and wheels behave identically.
|
|
46
|
+
`build_module_metadata()` walks the `simple_module` entry-point group, imports each module's `models` submodule (a missing `models` module is skipped; a missing dependency inside it raises), and merges every module's per-module `MetaData` into one unified `MetaData`. `make_include_object(metadata)` allowlists only tables owned by installed modules — any host-owned tables (and `alembic_version`) outside the module system are preserved untouched. So one autogenerate call covers every installed module in a single pass; editable installs and wheels behave identically.
|
|
47
47
|
|
|
48
|
-
Two extras matter for correctness: `render_item` collapses SQLModel's `AutoString` to `sa.String` and renders `StrEnum` columns so the generated file imports cleanly, and `make_process_revision_directives` re-emits expression-based (functional) indexes — e.g. `lower(email)` — that autogenerate silently drops under SQLite.
|
|
48
|
+
Two extras matter for correctness: `render_item` collapses SQLModel's `AutoString` to `sa.String` and renders `StrEnum` columns with the runtime type's labels so the generated file imports cleanly, and `make_process_revision_directives` re-emits expression-based (functional) indexes — e.g. `lower(email)` — that autogenerate silently drops under SQLite.
|
|
49
49
|
|
|
50
50
|
All module tables live in the **host's single shared schema** on both Postgres and SQLite (each module still owns its own `MetaData` purely so autogenerate can attribute a table to its module). There is no schema-per-module; `__tablename__` is prefixed with the module name (`orders_order`) to avoid collisions, and a cross-module FK is an ordinary same-schema reference.
|
|
51
51
|
|
|
@@ -46,6 +46,36 @@ async def test_view_renders_index(authenticated_client):
|
|
|
46
46
|
|
|
47
47
|
`authenticated_client` already carries the cookie — don't manually pass `cookies=`.
|
|
48
48
|
|
|
49
|
+
## Asserting Inertia pages
|
|
50
|
+
|
|
51
|
+
Use `InertiaPage.from_response(resp)` or `inertia_page(resp)` from
|
|
52
|
+
`simple_module_test` for either an HTML document or an `X-Inertia` JSON page:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from simple_module_test import inertia_page
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def test_orders_page(authenticated_client):
|
|
59
|
+
resp = await authenticated_client.get("/orders/")
|
|
60
|
+
assert resp.status_code == 200
|
|
61
|
+
page = inertia_page(resp)
|
|
62
|
+
page.assert_component("Orders/Browse").has("orders", count=2)
|
|
63
|
+
page.where("orders.0.id", lambda value: value > 0).missing("secret")
|
|
64
|
+
page.deferred("default", "stats")
|
|
65
|
+
loaded = await page.load_deferred(authenticated_client, "default")
|
|
66
|
+
loaded.has("stats")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Assertions chain and use dot paths into props, including list indices. `where`
|
|
70
|
+
accepts a value or predicate; `assert_url` and `assert_version` check page fields.
|
|
71
|
+
`reload_only(client, *props)`, `reload_except(client, *props)`, and
|
|
72
|
+
`load_deferred(client, group=None)` send the correct Inertia version and partial
|
|
73
|
+
headers. Each returns a new page with the server's response, without merging it
|
|
74
|
+
into the original props; omitting a deferred group loads all advertised groups.
|
|
75
|
+
No fixture is needed. Metadata is available as `deferred_props`, `merge_props`,
|
|
76
|
+
`prepend_props`, `deep_merge_props`, `match_props_on`, `once_props`, `scroll_props`,
|
|
77
|
+
`shared_props`, `rescued_props`, `encrypt_history`, and `clear_history`.
|
|
78
|
+
|
|
49
79
|
## Single-test / focused runs
|
|
50
80
|
|
|
51
81
|
```bash
|
|
@@ -20,6 +20,7 @@ from simple_module_db import (
|
|
|
20
20
|
make_process_revision_directives,
|
|
21
21
|
render_item,
|
|
22
22
|
)
|
|
23
|
+
from simple_module_hosting.migrations import ALEMBIC_DATABASE_URL_ATTRIBUTE
|
|
23
24
|
from simple_module_hosting.settings import Settings
|
|
24
25
|
from sqlalchemy import engine_from_config, pool
|
|
25
26
|
from sqlalchemy.engine import make_url
|
|
@@ -51,8 +52,8 @@ def _get_url() -> str:
|
|
|
51
52
|
(a stray app.db, nothing else) that printing the target, password masked,
|
|
52
53
|
is worth the one line.
|
|
53
54
|
"""
|
|
54
|
-
|
|
55
|
-
url =
|
|
55
|
+
database_url = config.attributes.get(ALEMBIC_DATABASE_URL_ATTRIBUTE) or Settings().database_url
|
|
56
|
+
url = database_url.replace("+aiosqlite", "").replace("+asyncpg", "+psycopg2")
|
|
56
57
|
logger.info(
|
|
57
58
|
"Migrating %s (cwd=%s)", make_url(url).render_as_string(hide_password=True), Path.cwd()
|
|
58
59
|
)
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Outfit:wght@400;500;600;700;800&display=swap" rel="stylesheet" />
|
|
16
16
|
{% inertia_head %}
|
|
17
17
|
{% if request.app.state.sm.inertia_config.environment == "development" %}
|
|
18
|
-
<script type="module">
|
|
18
|
+
<script type="module" nonce="{{ request.state.csp_nonce }}">
|
|
19
19
|
import RefreshRuntime from "{{ request.app.state.sm.inertia_config.dev_url }}/@react-refresh";
|
|
20
20
|
RefreshRuntime.injectIntoGlobalHook(window);
|
|
21
21
|
window.$RefreshReg$ = () => {};
|