python-ship 0.1.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.
@@ -0,0 +1,52 @@
1
+ # Published by `ship init`; edit freely. `ship init --force` replaces it with the version
2
+ # matching the installed python-ship.
3
+ ARG PYTHON_VERSION=3.13
4
+ @ASSET_STAGE@
5
+ FROM python:${PYTHON_VERSION}-slim AS base
6
+ ARG PYTHON_VERSION
7
+ # The first patched release per Python branch, from the generated Compose file. A stale, locally
8
+ # cached base image fails here instead of building on a release with known vulnerabilities.
9
+ ARG SHIP_PYTHON_FLOOR=""
10
+ COPY ship/check-python-security-floor.py /usr/local/share/ship/check-python-security-floor.py
11
+ RUN SHIP_BASE_IMAGE="python:${PYTHON_VERSION}-slim" SHIP_PYTHON_FLOOR="${SHIP_PYTHON_FLOOR}" \
12
+ python /usr/local/share/ship/check-python-security-floor.py
13
+ ENV PYTHONDONTWRITEBYTECODE=1 \
14
+ PYTHONUNBUFFERED=1 \
15
+ VIRTUAL_ENV=/opt/ship-venv \
16
+ PATH="/opt/ship-venv/bin:$PATH"
17
+ WORKDIR /app
18
+
19
+ FROM base AS builder
20
+ ARG SHIP_SERVER_REQUIREMENT="uvicorn==0.54.0"
21
+ COPY --from=ghcr.io/astral-sh/uv:@UV_VERSION@ /uv /uvx /bin/
22
+ ENV UV_NO_CACHE=1 \
23
+ UV_LINK_MODE=copy \
24
+ UV_PYTHON_DOWNLOADS=never \
25
+ UV_PROJECT_ENVIRONMENT=/opt/ship-venv
26
+ COPY . /app
27
+ @ASSET_COPY@
28
+ # Dependencies live outside /app, so the development bind mount cannot hide them.
29
+ RUN uv venv /opt/ship-venv
30
+ # A locked uv project keeps its lockfile authoritative; other projects use uv's pip interface.
31
+ RUN if [ -f uv.lock ] && [ -f pyproject.toml ]; then \
32
+ uv sync --locked --no-dev; \
33
+ elif [ -f requirements.txt ]; then \
34
+ uv pip install -r requirements.txt; \
35
+ elif [ -f pyproject.toml ]; then \
36
+ uv sync --no-dev; \
37
+ fi
38
+ # Ship supplies the selected ASGI server even when the app declares no dependencies.
39
+ RUN uv pip install "$SHIP_SERVER_REQUIREMENT"
40
+
41
+ # Production: the installed app and server only. No uv, no pip, no source bind mount, not root.
42
+ FROM base AS production
43
+ COPY --from=builder /opt/ship-venv /opt/ship-venv
44
+ COPY --from=builder --chown=10001:10001 /app /app
45
+ # The app may write under /app at boot (collectstatic, caches); the venv stays read-only.
46
+ RUN chown 10001:10001 /app \
47
+ && /usr/local/bin/python -m pip uninstall --yes --quiet pip setuptools wheel
48
+ USER 10001:10001
49
+ EXPOSE 8000
50
+
51
+ FROM builder AS development
52
+ EXPOSE 8000
@@ -0,0 +1,49 @@
1
+ """Fail the image build on a Python release with known security vulnerabilities.
2
+
3
+ Published by `ship init` and run by ship/Dockerfile's base stage. ship.json's
4
+ "python" is normally a branch ("3.13"), and Docker keeps building on whatever
5
+ python:3.13-slim is cached locally, so this checks the Python actually in the
6
+ image. SHIP_PYTHON_FLOOR is the first patched release per branch, oldest first
7
+ ("3.11.18 3.12.16 ..."); empty skips the check. An optional argument stands in
8
+ for the running version, for tests.
9
+ """
10
+
11
+ import os
12
+ import platform
13
+ import sys
14
+
15
+
16
+ def parse(version):
17
+ return tuple(int(part) for part in version.split(".")[:3])
18
+
19
+
20
+ def main():
21
+ version = sys.argv[1] if len(sys.argv) > 1 else platform.python_version()
22
+ floor = [parse(item) for item in os.environ.get("SHIP_PYTHON_FLOOR", "").split()]
23
+ if not floor:
24
+ return 0
25
+ image = os.environ.get("SHIP_BASE_IMAGE") or "the Python base image"
26
+ try:
27
+ current = parse(version)
28
+ except ValueError:
29
+ return 0 # A pre-release such as 3.16.0a1 has no floor yet.
30
+ if current[:2] < floor[0][:2]:
31
+ oldest = ".".join(map(str, floor[0][:2]))
32
+ sys.stderr.write(
33
+ f"ship: Python {version} is past end of life and gets no security fixes. "
34
+ f"Set \"python\" in ship.json to {oldest} or newer, then build again.\n"
35
+ )
36
+ return 1
37
+ for minimum in floor:
38
+ if minimum[:2] == current[:2] and current < minimum:
39
+ sys.stderr.write(
40
+ f"ship: Python {version} has known security vulnerabilities, fixed in "
41
+ f"{'.'.join(map(str, minimum))}. The locally cached base image is stale: "
42
+ f"run `docker pull {image}` and build again.\n"
43
+ )
44
+ return 1
45
+ return 0
46
+
47
+
48
+ if __name__ == "__main__":
49
+ sys.exit(main())
@@ -0,0 +1,7 @@
1
+ FROM alpine:3.24.4 AS config
2
+ ARG GARAGE_RPC_PUBLIC_ADDR=garage:3901
3
+ COPY garage.toml /garage.toml
4
+ RUN sed -i "s/__GARAGE_RPC_PUBLIC_ADDR__/${GARAGE_RPC_PUBLIC_ADDR}/" /garage.toml
5
+
6
+ FROM dxflrs/garage:v2.5.0
7
+ COPY --from=config /garage.toml /etc/garage.toml
@@ -0,0 +1,15 @@
1
+ metadata_dir = "/meta"
2
+ data_dir = "/data"
3
+ db_engine = "sqlite"
4
+ replication_factor = 1
5
+
6
+ rpc_bind_addr = "[::]:3901"
7
+ rpc_public_addr = "__GARAGE_RPC_PUBLIC_ADDR__"
8
+
9
+ [s3_api]
10
+ s3_region = "garage"
11
+ api_bind_addr = "[::]:3900"
12
+ root_domain = ".s3.garage.localhost"
13
+
14
+ [admin]
15
+ api_bind_addr = "[::]:3903"
python_ship/uv.py ADDED
@@ -0,0 +1,76 @@
1
+ """Find or install uv before initializing a project."""
2
+
3
+ import os
4
+ from pathlib import Path
5
+ import shutil
6
+ import subprocess
7
+ import sys
8
+ from tempfile import TemporaryDirectory
9
+ from urllib.error import URLError
10
+ from urllib.request import Request, urlopen
11
+
12
+ from .config import ConfigError
13
+
14
+ UV_VERSION = "0.13.3"
15
+
16
+
17
+ def locate_uv() -> str | None:
18
+ found = shutil.which("uv")
19
+ if found:
20
+ return found
21
+ # The official standalone installer may not update this process's PATH.
22
+ local = Path.home() / ".local" / "bin" / ("uv.exe" if os.name == "nt" else "uv")
23
+ return str(local) if local.is_file() and (os.name == "nt" or os.access(local, os.X_OK)) else None
24
+
25
+
26
+ def _install_uv() -> None:
27
+ environment = os.environ.copy()
28
+ environment["UV_INSTALL_DIR"] = str(Path.home() / ".local" / "bin")
29
+ if os.name == "nt":
30
+ powershell = shutil.which("powershell") or shutil.which("pwsh")
31
+ if powershell is None:
32
+ raise ConfigError("PowerShell is required to install uv automatically on Windows.")
33
+ # A parent PowerShell 7 session can pass its module path to Windows
34
+ # PowerShell 5.1, making the latter load the wrong Security module.
35
+ environment = {key: value for key, value in environment.items() if key.casefold() != "psmodulepath"}
36
+ command = [
37
+ powershell, "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command",
38
+ f"irm https://astral.sh/uv/{UV_VERSION}/install.ps1 | iex",
39
+ ]
40
+ result = subprocess.run(command, check=False, env=environment)
41
+ else:
42
+ url = f"https://astral.sh/uv/{UV_VERSION}/install.sh"
43
+ try:
44
+ with urlopen(Request(url, headers={"User-Agent": "python-ship/0.1"}), timeout=30) as response:
45
+ script = response.read()
46
+ except (OSError, URLError) as exc:
47
+ raise ConfigError(f"Could not download uv installer from {url}: {exc}") from exc
48
+ with TemporaryDirectory(prefix="python-ship-uv-") as directory:
49
+ installer = Path(directory) / "install.sh"
50
+ installer.write_bytes(script)
51
+ result = subprocess.run(["sh", str(installer)], check=False, env=environment)
52
+ if result.returncode != 0:
53
+ raise ConfigError("The uv installer failed; ship init made no project changes.")
54
+
55
+
56
+ def require_uv() -> str:
57
+ existing = locate_uv()
58
+ if existing:
59
+ return existing
60
+ installer_suffix = "ps1" if os.name == "nt" else "sh"
61
+ installer_url = f"https://astral.sh/uv/{UV_VERSION}/install.{installer_suffix}"
62
+ try:
63
+ answer = input(
64
+ "uv is required. Install it using Astral's official installer "
65
+ f"({installer_url})? [y/N] "
66
+ )
67
+ except EOFError as exc:
68
+ raise ConfigError("uv is required; installation was not confirmed.") from exc
69
+ if answer.strip().lower() not in {"y", "yes"}:
70
+ raise ConfigError("uv is required; ship init cancelled without changing the project.")
71
+ print("Installing uv...", file=sys.stderr)
72
+ _install_uv()
73
+ installed = locate_uv()
74
+ if installed is None:
75
+ raise ConfigError("uv installer finished, but uv was not found; ship init made no project changes.")
76
+ return installed