python-ship 0.2.0__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_ship/__init__.py +1 -1
- python_ship/adapters.py +28 -3
- python_ship/capabilities.py +26 -1
- python_ship/cli.py +305 -90
- python_ship/compose.py +40 -14
- python_ship/config.py +26 -11
- python_ship/contracts.py +13 -1
- python_ship/environment.py +252 -38
- python_ship/image_build.py +143 -0
- python_ship/init.py +298 -76
- python_ship/layout.py +50 -0
- python_ship/mutagen.py +1 -1
- python_ship/package_managers.py +1 -1
- python_ship/plugins.py +22 -2
- python_ship/portable.py +7 -0
- python_ship/ports.py +120 -0
- python_ship/production.py +1 -0
- python_ship/release.py +4 -2
- python_ship/runtime.py +9 -7
- python_ship/schema/ship.schema.json +22 -0
- python_ship/security.py +2 -1
- python_ship/service_setup.py +80 -0
- python_ship/services.py +63 -4
- python_ship/storage.py +9 -3
- python_ship/stubs.py +23 -21
- python_ship/templates/Dockerfile +12 -2
- python_ship/templates/check-python-security-floor.py +1 -1
- python_ship/templates/launcher +49 -0
- python_ship/terminal.py +77 -0
- python_ship/wizard.py +52 -6
- {python_ship-0.2.0.dist-info → python_ship-0.3.0.dist-info}/METADATA +363 -178
- python_ship-0.3.0.dist-info/RECORD +47 -0
- python_ship-0.2.0.dist-info/RECORD +0 -41
- {python_ship-0.2.0.dist-info → python_ship-0.3.0.dist-info}/WHEEL +0 -0
- {python_ship-0.2.0.dist-info → python_ship-0.3.0.dist-info}/entry_points.txt +0 -0
- {python_ship-0.2.0.dist-info → python_ship-0.3.0.dist-info}/licenses/LICENSE.md +0 -0
- {python_ship-0.2.0.dist-info → python_ship-0.3.0.dist-info}/top_level.txt +0 -0
python_ship/__init__.py
CHANGED
python_ship/adapters.py
CHANGED
|
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
|
7
7
|
import re
|
|
8
8
|
|
|
9
9
|
from .config import ShipConfig
|
|
10
|
-
from .contracts import Interface
|
|
10
|
+
from .contracts import Interface, SetupAdvice, ShipEnvironment
|
|
11
11
|
|
|
12
12
|
TARGET = re.compile(r"[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*:[A-Za-z_][A-Za-z0-9_]*(?:\(\))?")
|
|
13
13
|
# Directories never searched when detecting a project's app module.
|
|
@@ -104,6 +104,11 @@ def callable_interface(project_root: Path, target: str) -> Interface | None:
|
|
|
104
104
|
return None
|
|
105
105
|
|
|
106
106
|
|
|
107
|
+
def _declares_celery(root: Path) -> bool:
|
|
108
|
+
return any(path.is_file() and re.search(r"\bcelery\b", path.read_text(encoding="utf-8"), re.I)
|
|
109
|
+
for path in (root / "pyproject.toml", root / "requirements.txt"))
|
|
110
|
+
|
|
111
|
+
|
|
107
112
|
class PythonCapabilities:
|
|
108
113
|
"""Optional metadata and process suggestions, requiring actual project evidence."""
|
|
109
114
|
|
|
@@ -134,8 +139,7 @@ class PythonCapabilities:
|
|
|
134
139
|
return {"health": None, "urlSetting": None, "requiredEnv": sorted(set(required))}
|
|
135
140
|
|
|
136
141
|
def suggest_processes(self, config: ShipConfig, root: Path) -> dict:
|
|
137
|
-
|
|
138
|
-
if not any(path.is_file() and re.search(r"\bcelery\b", path.read_text(encoding="utf-8"), re.I) for path in manifests):
|
|
142
|
+
if not _declares_celery(root):
|
|
139
143
|
return {}
|
|
140
144
|
# The app supplies its Celery instance; the environment remains authoritative.
|
|
141
145
|
suggestions = {"celery-beat": "celery -A \"$CELERY_APP\" beat --loglevel=info --schedule=/tmp/celerybeat-schedule"}
|
|
@@ -143,6 +147,11 @@ class PythonCapabilities:
|
|
|
143
147
|
suggestions["celery-worker"] = "celery -A \"$CELERY_APP\" worker --loglevel=info"
|
|
144
148
|
return suggestions
|
|
145
149
|
|
|
150
|
+
def setup_advice(self, config: ShipConfig, root: Path) -> list[SetupAdvice]:
|
|
151
|
+
if config.services.get("tasks") == "celery" and not _declares_celery(root):
|
|
152
|
+
return [SetupAdvice("Declare Celery in your project dependencies and set CELERY_APP before starting the worker.", before_up=True)]
|
|
153
|
+
return []
|
|
154
|
+
|
|
146
155
|
|
|
147
156
|
class GenericAdapter(PythonCapabilities):
|
|
148
157
|
"""Serve any ASGI or WSGI callable; no web framework required."""
|
|
@@ -187,6 +196,22 @@ class DjangoAdapter(PythonCapabilities):
|
|
|
187
196
|
def detect(self, project_root: Path) -> bool:
|
|
188
197
|
return (project_root / "manage.py").is_file()
|
|
189
198
|
|
|
199
|
+
def environment_defaults(self, config: ShipConfig, root: Path, environment: ShipEnvironment) -> dict[str, str]:
|
|
200
|
+
for path in (module_file(root, config.app), root / "manage.py"):
|
|
201
|
+
if not path.is_file():
|
|
202
|
+
continue
|
|
203
|
+
found = re.search(r"""DJANGO_SETTINGS_MODULE['"]\s*,\s*['"]([\w.]+)['"]""",
|
|
204
|
+
path.read_text(encoding="utf-8", errors="replace"))
|
|
205
|
+
if found:
|
|
206
|
+
return {"DJANGO_SETTINGS_MODULE": found[1]}
|
|
207
|
+
return {}
|
|
208
|
+
|
|
209
|
+
def setup_advice(self, config: ShipConfig, root: Path) -> list[SetupAdvice]:
|
|
210
|
+
advice = super().setup_advice(config, root)
|
|
211
|
+
if config.services.get("database"):
|
|
212
|
+
advice.append(SetupAdvice("Configure Django DATABASES from the DB_* settings, then run `ship manage migrate` after `ship up`."))
|
|
213
|
+
return advice
|
|
214
|
+
|
|
190
215
|
def default_app(self, project_root: Path) -> str | None:
|
|
191
216
|
manage = project_root / "manage.py"
|
|
192
217
|
package = None
|
python_ship/capabilities.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"""Optional adapter capabilities, shared by initialization, validation and releases."""
|
|
2
2
|
from pathlib import Path
|
|
3
|
+
import re
|
|
3
4
|
from typing import Any
|
|
4
5
|
|
|
5
6
|
from .config import ConfigError, ShipConfig, http_problem, process_problem
|
|
7
|
+
from .contracts import SetupAdvice, ShipEnvironment
|
|
6
8
|
from .production import DEVELOPMENT_DEFAULTS, read_env
|
|
7
9
|
|
|
8
10
|
|
|
@@ -16,13 +18,36 @@ def release_description(adapter: Any, config: ShipConfig, root: Path) -> dict[st
|
|
|
16
18
|
problem = http_problem({"port": 8000, "role": "site", "health": result.get("health"), "urlSetting": result.get("urlSetting")})
|
|
17
19
|
if problem:
|
|
18
20
|
raise ConfigError(problem)
|
|
19
|
-
import re
|
|
20
21
|
if not isinstance(result.get("requiredEnv", []), list) or any(
|
|
21
22
|
not isinstance(key, str) or not re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", key) for key in result.get("requiredEnv", [])):
|
|
22
23
|
raise ConfigError("Adapter requiredEnv must list setting names.")
|
|
23
24
|
return result
|
|
24
25
|
|
|
25
26
|
|
|
27
|
+
def environment_defaults(adapter: Any, config: ShipConfig, root: Path, environment: ShipEnvironment) -> dict[str, str]:
|
|
28
|
+
hook = getattr(adapter, "environment_defaults", None)
|
|
29
|
+
if hook is None:
|
|
30
|
+
return {}
|
|
31
|
+
result = hook(config, root, environment)
|
|
32
|
+
if not isinstance(result, dict) or any(not isinstance(key, str) or not re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", key)
|
|
33
|
+
or not isinstance(value, str) for key, value in result.items()):
|
|
34
|
+
raise ConfigError(f"Adapter {adapter.key!r} environment defaults must map variable names to strings.")
|
|
35
|
+
return result
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def setup_advice(config: ShipConfig, root: Path) -> list[SetupAdvice]:
|
|
39
|
+
from .plugins import load_extensions
|
|
40
|
+
|
|
41
|
+
adapter = load_extensions(config).adapter(config)
|
|
42
|
+
hook = getattr(adapter, "setup_advice", None)
|
|
43
|
+
if hook is None:
|
|
44
|
+
return []
|
|
45
|
+
result = hook(config, root)
|
|
46
|
+
if not isinstance(result, list) or any(not isinstance(item, SetupAdvice) or not item.message.strip() for item in result):
|
|
47
|
+
raise ConfigError(f"Adapter {adapter.key!r} setup advice must be a list of nonempty SetupAdvice entries.")
|
|
48
|
+
return result
|
|
49
|
+
|
|
50
|
+
|
|
26
51
|
def required_setting_problems(description: dict[str, Any], root: Path) -> list[str]:
|
|
27
52
|
values = read_env(root / ".env.production")
|
|
28
53
|
return [f"{key} is required in .env.production with a real value."
|