simple-module-cli 0.0.41__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/cli.py +17 -0
- simple_module_cli/docker_assets.py +1 -1
- simple_module_cli/git_source.py +3 -87
- simple_module_cli/git_versions.py +114 -0
- simple_module_cli/migration_recipes/mail_settings.py +48 -0
- simple_module_cli/migration_recipes/users_tokens.py +34 -0
- simple_module_cli/migrations_cmd.py +66 -0
- simple_module_cli/package_update.py +68 -141
- simple_module_cli/package_update_deps.py +160 -0
- simple_module_cli/package_update_npm.py +126 -0
- 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-cli/SKILL.md +21 -3
- 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/docker/compose-base-postgres.yml.tpl +2 -0
- simple_module_cli/templates/docker/compose-base-sqlite.yml.tpl +1 -0
- simple_module_cli/templates/docker/compose-tasks-postgres.yml.tpl +4 -0
- simple_module_cli/templates/docker/dockerignore +11 -1
- simple_module_cli/templates/docker/host-flat.Dockerfile +3 -2
- simple_module_cli/templates/docker/host.Dockerfile +4 -2
- simple_module_cli/templates/docker/worker.Dockerfile.tpl +3 -1
- simple_module_cli/templates/host/README.md.tpl +18 -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.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/docker/compose-base-postgres.yml.tpl +2 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/docker/compose-base-sqlite.yml.tpl +1 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/docker/compose-tasks-postgres.yml.tpl +4 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/docker/dockerignore +11 -1
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/docker/host-flat.Dockerfile +3 -2
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/docker/host.Dockerfile +4 -2
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/docker/worker.Dockerfile.tpl +3 -1
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/README.md.tpl +18 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/migrations/env.py +3 -2
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/templates/index.html +1 -1
- {simple_module_cli-0.0.41.dist-info → simple_module_cli-0.0.43.dist-info}/METADATA +3 -2
- {simple_module_cli-0.0.41.dist-info → simple_module_cli-0.0.43.dist-info}/RECORD +111 -105
- {simple_module_cli-0.0.41.dist-info → simple_module_cli-0.0.43.dist-info}/WHEEL +1 -1
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/docker/Makefile.snippet +0 -0
- {simple_module_cli-0.0.41.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.41.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.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/.env.example +0 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/.gitignore +0 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/Makefile +0 -0
- {simple_module_cli-0.0.41.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.41.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.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/alembic.ini +0 -0
- {simple_module_cli-0.0.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/main.py +0 -0
- {simple_module_cli-0.0.41.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.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/migrations/versions/.gitkeep +0 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/pyproject.toml.tpl +0 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/host/routes.py +0 -0
- {simple_module_cli-0.0.41.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.41.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.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/.gitignore +0 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/README.md.tpl +0 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/__init__.py +0 -0
- {simple_module_cli-0.0.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/__PACKAGE__/py.typed +0 -0
- {simple_module_cli-0.0.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.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.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/package.json.tpl +0 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/pyproject.toml.tpl +0 -0
- {simple_module_cli-0.0.41.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.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/module/tsconfig.json.tpl +0 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/workspace/.env.example +0 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/workspace/.gitignore +0 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/workspace/Makefile +0 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/workspace/README.md.tpl +0 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/workspace/package.json.tpl +0 -0
- {simple_module_cli-0.0.41.data → simple_module_cli-0.0.43.data}/data/simple_module_cli/templates/workspace/pyproject.toml.tpl +0 -0
- {simple_module_cli-0.0.41.dist-info → simple_module_cli-0.0.43.dist-info}/entry_points.txt +0 -0
- {simple_module_cli-0.0.41.dist-info → simple_module_cli-0.0.43.dist-info}/licenses/LICENSE +0 -0
simple_module_cli/cli.py
CHANGED
|
@@ -23,6 +23,7 @@ import typer
|
|
|
23
23
|
from simple_module_cli.add_cmd import add_module, run_add
|
|
24
24
|
from simple_module_cli.case import to_kebab_case
|
|
25
25
|
from simple_module_cli.docker_cmd import docker_app
|
|
26
|
+
from simple_module_cli.migrations_cmd import migrations_app
|
|
26
27
|
from simple_module_cli.module_cmd import module_app
|
|
27
28
|
from simple_module_cli.new import new_project
|
|
28
29
|
from simple_module_cli.openapi_cmd import openapi_app
|
|
@@ -49,6 +50,22 @@ app.add_typer(docker_app, name="docker")
|
|
|
49
50
|
app.add_typer(skills_app, name="skills")
|
|
50
51
|
app.add_typer(module_app, name="module")
|
|
51
52
|
app.add_typer(openapi_app, name="openapi")
|
|
53
|
+
app.add_typer(migrations_app, name="migrations")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@app.command("doctor")
|
|
57
|
+
def doctor() -> None:
|
|
58
|
+
"""Check installed modules and their database compatibility."""
|
|
59
|
+
try:
|
|
60
|
+
from simple_module_core.__main__ import main as run_doctor
|
|
61
|
+
except ImportError:
|
|
62
|
+
# The CLI installs on its own (to scaffold); doctor needs a project's framework.
|
|
63
|
+
typer.echo(
|
|
64
|
+
"ERROR: smpy doctor needs simple_module_core; run it inside a project.", err=True
|
|
65
|
+
)
|
|
66
|
+
raise typer.Exit(1) from None
|
|
67
|
+
|
|
68
|
+
raise typer.Exit(run_doctor())
|
|
52
69
|
|
|
53
70
|
|
|
54
71
|
@app.command("create-host")
|
|
@@ -78,7 +78,7 @@ def scaffold_docker_assets(target: Path, ctx: ScaffoldCtx, *, flat: bool = False
|
|
|
78
78
|
.replace(_PG_DB_TOKEN, pg_db)
|
|
79
79
|
.replace(_APP_EXTRA_ENV_TOKEN, _APP_BROKER_ENV if with_tasks else "")
|
|
80
80
|
)
|
|
81
|
-
volumes = ["pgdata"] if db == "postgres" else ["appdata"]
|
|
81
|
+
volumes = ["appdata", "pgdata"] if db == "postgres" else ["appdata"]
|
|
82
82
|
if with_tasks:
|
|
83
83
|
compose += _read(templates / f"compose-tasks-{db}.yml.tpl").replace(_PG_DB_TOKEN, pg_db)
|
|
84
84
|
volumes.append("redisdata")
|
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
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Frozen system mail-settings move from d7b3a9e5c1f2 (#711).
|
|
2
|
+
|
|
3
|
+
An existing target value wins; the obsolete source row is removed.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import sqlalchemy as sa
|
|
7
|
+
from alembic import op
|
|
8
|
+
|
|
9
|
+
_TABLE = "settings_setting"
|
|
10
|
+
_SCOPE_SYSTEM = "system"
|
|
11
|
+
_SYSTEM_SCOPE_ID = ""
|
|
12
|
+
|
|
13
|
+
_KEY_PAIRS = (
|
|
14
|
+
("users.mailer", "mail.backend"),
|
|
15
|
+
*((f"users.smtp_{f}", f"mail.smtp_{f}") for f in ("host", "port", "username", "password")),
|
|
16
|
+
("users.smtp_from", "mail.smtp_from"),
|
|
17
|
+
("users.smtp_tls", "mail.smtp_tls"),
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _rename(old: str, new: str) -> None:
|
|
22
|
+
scope = {"scope": _SCOPE_SYSTEM, "scope_id": _SYSTEM_SCOPE_ID, "old": old, "new": new}
|
|
23
|
+
bind = op.get_bind()
|
|
24
|
+
bind.execute(
|
|
25
|
+
sa.text(
|
|
26
|
+
f"DELETE FROM {_TABLE} WHERE scope = :scope AND scope_id = :scope_id AND key = :old"
|
|
27
|
+
f" AND EXISTS (SELECT 1 FROM {_TABLE} AS t WHERE t.scope = :scope"
|
|
28
|
+
" AND t.scope_id = :scope_id AND t.key = :new)"
|
|
29
|
+
),
|
|
30
|
+
scope,
|
|
31
|
+
)
|
|
32
|
+
bind.execute(
|
|
33
|
+
sa.text(
|
|
34
|
+
f"UPDATE {_TABLE} SET key = :new"
|
|
35
|
+
" WHERE scope = :scope AND scope_id = :scope_id AND key = :old"
|
|
36
|
+
),
|
|
37
|
+
scope,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def upgrade() -> None:
|
|
42
|
+
for old, new in _KEY_PAIRS:
|
|
43
|
+
_rename(old, new)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def downgrade() -> None:
|
|
47
|
+
for old, new in _KEY_PAIRS:
|
|
48
|
+
_rename(new, old)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Frozen token-storage upgrade from a626b1c8d023 (#711).
|
|
2
|
+
|
|
3
|
+
Upgrade and downgrade invalidate all access/refresh credentials. Stop all old
|
|
4
|
+
application workers before upgrading; clients must sign in again.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import sqlalchemy as sa
|
|
8
|
+
from alembic import op
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _clear_tokens() -> None:
|
|
12
|
+
for table in ("users_refresh_token", "users_access_token"):
|
|
13
|
+
op.execute(sa.table(table).delete())
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def upgrade() -> None:
|
|
17
|
+
_clear_tokens()
|
|
18
|
+
with op.batch_alter_table("users_refresh_token") as batch:
|
|
19
|
+
batch.alter_column(
|
|
20
|
+
"token", existing_type=sa.Uuid(), type_=sa.String(64), postgresql_using="token::text"
|
|
21
|
+
)
|
|
22
|
+
with op.batch_alter_table("users_access_token") as batch:
|
|
23
|
+
batch.alter_column("token", existing_type=sa.String(43), type_=sa.String(64))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def downgrade() -> None:
|
|
27
|
+
# Digests cannot be restored to UUIDs or bearer secrets.
|
|
28
|
+
_clear_tokens()
|
|
29
|
+
with op.batch_alter_table("users_refresh_token") as batch:
|
|
30
|
+
batch.alter_column(
|
|
31
|
+
"token", existing_type=sa.String(64), type_=sa.Uuid(), postgresql_using="token::uuid"
|
|
32
|
+
)
|
|
33
|
+
with op.batch_alter_table("users_access_token") as batch:
|
|
34
|
+
batch.alter_column("token", existing_type=sa.String(64), type_=sa.String(43))
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Prepare frozen framework upgrades in a consuming host's own Alembic graph."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from importlib.resources import files
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Annotated
|
|
9
|
+
from uuid import uuid4
|
|
10
|
+
|
|
11
|
+
import typer
|
|
12
|
+
|
|
13
|
+
migrations_app = typer.Typer(help="Prepare host-owned framework upgrade revisions.")
|
|
14
|
+
_RECIPES = {
|
|
15
|
+
"mail.settings_namespace_v1": ("mail", "mail_settings.py"),
|
|
16
|
+
"users.hashed_bearer_tokens_v1": ("users", "users_tokens.py"),
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@migrations_app.command("prepare")
|
|
21
|
+
def prepare(
|
|
22
|
+
upgrade_id: Annotated[str, typer.Argument(help="Stable framework upgrade id.")],
|
|
23
|
+
head: Annotated[str, typer.Option("--head", help="Explicit host head or label@head.")],
|
|
24
|
+
config: Annotated[Path | None, typer.Option("--config", help="Host alembic.ini.")] = None,
|
|
25
|
+
) -> None:
|
|
26
|
+
"""Write a self-contained revision; never connect to or migrate the database."""
|
|
27
|
+
if upgrade_id not in _RECIPES:
|
|
28
|
+
raise typer.BadParameter(f"Unknown upgrade {upgrade_id!r}; choose {', '.join(_RECIPES)}")
|
|
29
|
+
try:
|
|
30
|
+
from alembic.config import Config
|
|
31
|
+
from alembic.script import ScriptDirectory
|
|
32
|
+
from alembic.util.exc import CommandError
|
|
33
|
+
except ImportError as exc:
|
|
34
|
+
raise typer.BadParameter(
|
|
35
|
+
"Run this command in the host environment with Alembic installed"
|
|
36
|
+
) from exc
|
|
37
|
+
|
|
38
|
+
root = Path(os.environ.get("SM_PROJECT_ROOT", Path.cwd()))
|
|
39
|
+
if config is None:
|
|
40
|
+
config = root / "alembic.ini"
|
|
41
|
+
if not config.is_file():
|
|
42
|
+
config = root / "host/alembic.ini"
|
|
43
|
+
if not config.is_file():
|
|
44
|
+
raise typer.BadParameter(f"Host Alembic config not found: {config}")
|
|
45
|
+
try:
|
|
46
|
+
script = ScriptDirectory.from_config(Config(str(config)))
|
|
47
|
+
parent = script.get_revision(head)
|
|
48
|
+
if parent is None or not parent.is_head:
|
|
49
|
+
raise typer.BadParameter("--head must resolve to one existing host head")
|
|
50
|
+
label, recipe = _RECIPES[upgrade_id]
|
|
51
|
+
existing = {name for rev in script.walk_revisions() for name in rev.branch_labels}
|
|
52
|
+
except CommandError as exc:
|
|
53
|
+
raise typer.BadParameter(str(exc)) from exc
|
|
54
|
+
|
|
55
|
+
# Frozen source is copied, so future package changes cannot change this revision.
|
|
56
|
+
source = files("simple_module_cli").joinpath("migration_recipes", recipe).read_text()
|
|
57
|
+
revision = uuid4().hex[:12]
|
|
58
|
+
branch_labels = None if label in existing else (label,)
|
|
59
|
+
identifiers = (
|
|
60
|
+
f"\nrevision = {revision!r}\ndown_revision = {parent.revision!r}\n"
|
|
61
|
+
f"branch_labels = {branch_labels!r}\ndepends_on = None\n"
|
|
62
|
+
)
|
|
63
|
+
path = Path(script.versions) / f"{revision}_{upgrade_id.replace('.', '_')}.py"
|
|
64
|
+
with path.open("x") as output:
|
|
65
|
+
output.write(source + identifiers)
|
|
66
|
+
typer.echo(f"Prepared {upgrade_id}: {path}. Review it, then run alembic upgrade heads.")
|