common-python-tasks 0.13.1__tar.gz → 0.14.0__tar.gz

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.
Files changed (67) hide show
  1. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/PKG-INFO +2 -2
  2. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/README.md +1 -1
  3. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/configuration.md +24 -1
  4. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/container-images.md +38 -32
  5. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/scripts/docs_tasks_reference.py +3 -1
  6. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/data/generic/Dockerfile.j2 +28 -27
  7. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/packaging_tasks.py +2 -3
  8. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/project.py +15 -37
  9. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/release_tasks.py +2 -0
  10. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/utils.py +11 -1
  11. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/.gitignore +0 -0
  12. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/.poetry/plugins/poetry_dynamic_versioning-1.10.0.dist-info/licenses/LICENSE +0 -0
  13. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/.poetry/plugins/poetry_plugin_export-1.10.0.dist-info/licenses/LICENSE +0 -0
  14. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/LICENSE +0 -0
  15. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/documentation-workflows.md +0 -0
  16. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/getting-started.md +0 -0
  17. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/index.md +0 -0
  18. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/daily-development.md +0 -0
  19. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/documentation.md +0 -0
  20. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/index.md +0 -0
  21. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/packaging-and-releases.md +0 -0
  22. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/build-deps-image.md +0 -0
  23. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/build-image.md +0 -0
  24. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/build-package.md +0 -0
  25. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/build.md +0 -0
  26. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/bump-version.md +0 -0
  27. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/changelog.md +0 -0
  28. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/clean.md +0 -0
  29. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/container-shell.md +0 -0
  30. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/docs-build.md +0 -0
  31. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/docs-serve.md +0 -0
  32. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/format.md +0 -0
  33. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/lint.md +0 -0
  34. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/publish-github-release.md +0 -0
  35. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/publish-package.md +0 -0
  36. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/push-image.md +0 -0
  37. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/release.md +0 -0
  38. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/run-container.md +0 -0
  39. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/test.md +0 -0
  40. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/docs/tasks/reference/update-dependencies.md +0 -0
  41. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/pyproject.toml +0 -0
  42. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/scripts/__init__.py +0 -0
  43. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/scripts/add_common_python_tasks.py +0 -0
  44. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/scripts/release_script.py +0 -0
  45. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/scripts/update_docs_tasks_reference.py +0 -0
  46. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/scripts/utils.py +0 -0
  47. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/__init__.py +0 -0
  48. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/__main__.py +0 -0
  49. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/_task_registry.py +0 -0
  50. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/container_tasks.py +0 -0
  51. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/data/dockerfile_extensions/docker-in-docker/Dockerfile +0 -0
  52. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/data/dockerfile_extensions/docker-in-docker/install.sh +0 -0
  53. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/data/dockerfile_extensions/docker-in-docker/supervisor.sh +0 -0
  54. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/data/generic/.coveragerc +0 -0
  55. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/data/generic/.dockerignore +0 -0
  56. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/data/generic/Dockerfile.deps.j2 +0 -0
  57. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/data/generic/cliff.toml +0 -0
  58. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/data/generic/pytest.ini +0 -0
  59. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/data/generic/ruff.toml +0 -0
  60. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/dependency_tasks.py +0 -0
  61. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/development_tasks.py +0 -0
  62. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/docker.py +0 -0
  63. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/env.py +0 -0
  64. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/git.py +0 -0
  65. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/github.py +0 -0
  66. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/src/common_python_tasks/tasks.py +0 -0
  67. {common_python_tasks-0.13.1 → common_python_tasks-0.14.0}/zensical.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: common-python-tasks
3
- Version: 0.13.1
3
+ Version: 0.14.0
4
4
  Summary: Opinionated Poe the Poet tasks for Python package development.
5
5
  Project-URL: Homepage, http://github.com/ci-sourcerer/common-python-tasks
6
6
  Project-URL: Source, http://github.com/ci-sourcerer/common-python-tasks.git
@@ -42,7 +42,7 @@ Read the [complete documentation](https://common-python-tasks.ci-sourcerer.com/)
42
42
  Add the package as a development dependency.
43
43
 
44
44
  ```shell
45
- uv add --dev common-python-tasks==0.13.1
45
+ uv add --dev common-python-tasks==0.14.0
46
46
  ```
47
47
 
48
48
  Expose the default task set in `pyproject.toml`.
@@ -9,7 +9,7 @@ Read the [complete documentation](https://common-python-tasks.ci-sourcerer.com/)
9
9
  Add the package as a development dependency.
10
10
 
11
11
  ```shell
12
- uv add --dev common-python-tasks==0.13.1
12
+ uv add --dev common-python-tasks==0.14.0
13
13
  ```
14
14
 
15
15
  Expose the default task set in `pyproject.toml`.
@@ -26,7 +26,30 @@ Ruff uses `RUFF_CONFIG` when set. Otherwise, it discovers `.ruff.toml`, `ruff.to
26
26
  | `RELEASE_PRE_SCRIPT` | Run a command before the release steps |
27
27
  | `RELEASE_POST_SCRIPT` | Run a command after the release steps |
28
28
 
29
- The package also recognizes uv's `UV_PUBLISH_INDEX` and `UV_PUBLISH_URL` settings. Explicit task arguments take precedence over environment values and project configuration.
29
+ Publishing targets are selected from the first populated source in this order.
30
+
31
+ 1. Explicit task arguments, `--repository` or `--repository-url`.
32
+ 2. `COMMON_PYTHON_TASKS_PUBLISH_REPOSITORY` or `COMMON_PYTHON_TASKS_PUBLISH_URL`.
33
+ 3. uv's `UV_PUBLISH_INDEX` or `UV_PUBLISH_URL`.
34
+ 4. A configured publishable `[[tool.uv.index]]`, using the default entry or the sole publishable entry.
35
+ 5. uv's default publishing destination.
36
+
37
+ Blank environment values are ignored. Specifying both an index and a URL within the winning source fails before builds or release changes begin. Lower-priority settings are ignored. For example, `poe publish-package --repository internal` overrides `UV_PUBLISH_URL`, and `poe release --repository-url https://packages.example.com/legacy/` overrides `UV_PUBLISH_INDEX`.
38
+
39
+ The publishing subprocess receives the selected target as a command argument and omits `UV_PUBLISH_INDEX` and `UV_PUBLISH_URL` to prevent uv argument conflicts. The parent environment, credentials, check URLs, and other uv settings remain available. `UV_DEFAULT_INDEX` controls dependency resolution and does not select a publishing destination.
40
+
41
+ Other uv environment settings are inherited by `publish-package` and the package publishing step of `release`; no CPT aliases are required.
42
+
43
+ | Setting | Purpose |
44
+ | - | - |
45
+ | `UV_PUBLISH_TOKEN` | Authenticate publishing with a token |
46
+ | `UV_PUBLISH_USERNAME`, `UV_PUBLISH_PASSWORD` | Authenticate publishing with a username and password |
47
+ | `UV_INDEX_{name}_USERNAME`, `UV_INDEX_{name}_PASSWORD` | Supply credentials for a named index |
48
+ | `UV_PUBLISH_CHECK_URL` | Check an index for existing distributions and skip duplicate uploads |
49
+ | `UV_PUBLISH_NO_ATTESTATIONS` | Disable uploading attestations |
50
+ | `UV_KEYRING_PROVIDER` | Select uv's keyring authentication provider |
51
+
52
+ See uv's [environment variable reference](https://docs.astral.sh/uv/reference/environment/) for supported values and its [publishing guide](https://docs.astral.sh/uv/guides/package/#publishing-your-package) for publishing configuration. Availability depends on the installed uv version.
30
53
 
31
54
  ## Container settings
32
55
 
@@ -11,17 +11,24 @@ include_script = "common_python_tasks:tasks(include_tags=['common', 'containers'
11
11
 
12
12
  `build-image` renders a temporary Dockerfile and uses the project root as its build context. If the project does not provide `.dockerignore`, the task temporarily supplies a conservative default that includes `pyproject.toml`, `uv.lock`, `README.md`, `LICENSE`, and the `src/` tree.
13
13
 
14
+ Managed builds require a current `uv.lock` in the build context. If the lockfile is missing or stale, run `uv lock` and include the updated file in the build context.
15
+
14
16
  The generated Dockerfile contains the following stages.
15
17
 
16
18
  | Stage | Purpose |
17
19
  | - | - |
18
- | `builder` | Uses the host Python version, installs the installed version of uv, exports the optional `debug` dependency group, and builds the project wheel. |
19
- | `runtime` | Uses the configured Python image variant, installs optional APT packages and dependency-image artifacts, creates the non-root `py` user, installs the wheel, creates the `/pkg` package link and entrypoint, and applies container extensions. |
20
- | `debug` | Extends `runtime` with the project source and the `debug` dependency group. This stage exists only when `[dependency-groups].debug` is non-empty. |
20
+ | `uv-tool` | Supplies the uv binary to build steps through temporary mounts. |
21
+ | `builder` | Uses the host Python version to build the project wheel. |
22
+ | `runtime` | Uses the configured Python image variant and installs the locked runtime dependencies and project wheel into `/opt/venv`. It also installs optional APT packages and dependency-image artifacts, creates the non-root `py` user, configures the `/pkg` link and entrypoint, and applies container extensions. |
23
+ | `debug` | Extends `runtime` with the project source and the locked `debug` dependency group. This stage exists only when `[dependency-groups].debug` is non-empty. |
21
24
  | `final` | Extends `runtime` so tools that build the rendered Dockerfile without selecting a target still produce the normal runtime image. |
22
25
 
23
26
  The `build-image` task explicitly builds `runtime`, or `debug` when `--debug` is used. A debug build fails early when the project has no non-empty `debug` dependency group.
24
27
 
28
+ The managed Python installation excludes default dependency groups. Both targets use `/opt/venv/bin` on `PATH`. The template removes the base image's pip before applying extensions and uses uv through build-time mounts.
29
+
30
+ Maintainers can verify lockfile installation on slim and Alpine with `CPT_DOCKER_INTEGRATION=1 poe test tests/test_managed_dockerfile.py`. The tests require a running Docker daemon and network access to download base images and dependencies.
31
+
25
32
  The task supplies build arguments derived from the current environment and project metadata, including `PYTHON_VERSION`, `UV_VERSION`, `PACKAGE_VERSION`, `PACKAGE_NAME`, `AUTHORS`, `GIT_COMMIT`, `PYTHON_VARIANT`, and `WORKDIR_PATH`. It also creates short and fully qualified image tags for the package version and Git commit. A dirty working tree adds `-dirty` to the commit tag.
26
33
 
27
34
  ### Generic template reference
@@ -43,11 +50,13 @@ ARG PYTHON_VERSION=3
43
50
  # Variant for the runtime image, e.g. slim, alpine, etc.
44
51
  # See https://hub.docker.com/_/python for available variants. Leave empty for no variant.
45
52
  ARG PYTHON_VARIANT=slim
53
+ ARG UV_VERSION=latest
54
+
55
+ FROM ghcr.io/astral-sh/uv:${UV_VERSION:-latest} AS uv-tool
46
56
 
47
57
  FROM python:${PYTHON_VERSION} AS builder
48
58
 
49
59
  ARG PACKAGE_VERSION
50
- ARG UV_VERSION
51
60
 
52
61
  {% if CONTAINER_ENV_VARS %}
53
62
  # Make configured variables available to package build commands.
@@ -61,32 +70,18 @@ ENV {{ env_var }}
61
70
  # false dirty-version detection from a partial working tree.
62
71
  ENV UV_DYNAMIC_VERSIONING_BYPASS=${PACKAGE_VERSION}
63
72
 
64
- # Install uv for package build and dependency export steps
65
- RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache{{ CACHE_ID_SUFFIX }} \
66
- sh -c 'if [ -n "${UV_VERSION:-}" ]; then \
67
- pip install --root-user-action=ignore "uv==$UV_VERSION"; \
68
- else \
69
- pip install --root-user-action=ignore uv; \
70
- fi'
71
-
72
73
  # Build package
73
74
  WORKDIR /tmp/build
74
75
  COPY . /tmp/build/
75
76
 
76
- {% if HAS_DEBUG_DEPS %}
77
- # Export debug requirements when the project defines a debug dependency group
78
- RUN --mount=type=cache,target=/root/.cache/uv,id=uv-cache{{ CACHE_ID_SUFFIX }}{% for mount in UV_INDEX_SECRET_MOUNTS %} \
79
- --mount={{ mount }}{% endfor %} \
80
- uv export --frozen --only-group debug --no-hashes --format requirements-txt --output-file requirements-debug.txt
81
- {% endif %}
82
-
83
77
  # Build the wheel, caching the uv cache directory to speed up subsequent builds.
84
78
  # If running this in a CI system, you must be using a persistent builder to take
85
79
  # advantage of the cache mount, and you should configure your CI to persist the
86
80
  # cache directory between builds
87
- RUN --mount=type=cache,target=/root/.cache/uv,id=uv-cache{{ CACHE_ID_SUFFIX }}{% for mount in UV_INDEX_SECRET_MOUNTS %} \
81
+ RUN --mount=from=uv-tool,source=/uv,target=/usr/local/bin/uv \
82
+ --mount=type=cache,target=/root/.cache/uv,id=uv-cache{{ CACHE_ID_SUFFIX }}{% for mount in UV_INDEX_SECRET_MOUNTS %} \
88
83
  --mount={{ mount }}{% endfor %} \
89
- uv build --wheel
84
+ uv build --wheel --out-dir /tmp/wheels
90
85
 
91
86
  FROM python:${PYTHON_VERSION}${PYTHON_VARIANT:+-${PYTHON_VARIANT}} AS runtime
92
87
  ARG PYTHON_VERSION
@@ -147,11 +142,21 @@ RUN set -eux; \
147
142
 
148
143
  WORKDIR ${WORKDIR_PATH}
149
144
 
150
- # Grab package from builder image
151
- COPY --from=builder /tmp/build/dist/*.whl /tmp/
145
+ # Sync locked dependencies for the runtime platform, then install the built wheel.
146
+ ARG PACKAGE_VERSION
147
+ RUN --mount=from=uv-tool,source=/uv,target=/usr/local/bin/uv \
148
+ --mount=from=builder,source=/tmp/build,target=/tmp/build,rw \
149
+ --mount=from=builder,source=/tmp/wheels,target=/tmp/wheels \
150
+ --mount=type=cache,target=/root/.cache/uv,id=uv-cache{{ CACHE_ID_SUFFIX }}{% for mount in UV_INDEX_SECRET_MOUNTS %} \
151
+ --mount={{ mount }}{% endfor %} \
152
+ UV_DYNAMIC_VERSIONING_BYPASS="${PACKAGE_VERSION}" UV_PROJECT_ENVIRONMENT=/opt/venv \
153
+ uv sync --project /tmp/build --python /usr/local/bin/python --no-python-downloads \
154
+ --locked --no-default-groups --no-install-project --no-editable --link-mode copy \
155
+ && uv pip install --python /opt/venv/bin/python --no-deps --link-mode copy /tmp/wheels/*.whl \
156
+ && /usr/local/bin/python -m pip uninstall --yes --root-user-action=ignore pip
157
+
158
+ ENV PATH="/opt/venv/bin:${PATH}"
152
159
 
153
- # Install package
154
- RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache{{ CACHE_ID_SUFFIX }} pip install --root-user-action=ignore /tmp/*.whl
155
160
  # Create symlinks for the package
156
161
  ARG PACKAGE_NAME
157
162
  ENV PACKAGE_NAME=${PACKAGE_NAME}
@@ -170,9 +175,7 @@ LABEL git.commit=${GIT_COMMIT}
170
175
  # This entrypoint is deliberately not configurable via environment variables in order to
171
176
  # ensure that the container always uses the entrypoint selected at build time. If the
172
177
  # current package does not provide a console script, the entrypoint will default to `python`
173
- RUN echo "#!/bin/sh
174
-
175
- exec {{ ENTRYPOINT_COMMAND|default('python') }} \"\$@\"" >/pkg/entrypoint.sh \
178
+ RUN printf '%s\n' '#!/bin/sh' '' "exec {{ ENTRYPOINT_COMMAND|default('python') }} \"\$@\"" >/pkg/entrypoint.sh \
176
179
  && chmod +x /pkg/entrypoint.sh
177
180
 
178
181
  ARG RUNTIME_USER=py
@@ -183,16 +186,19 @@ USER ${RUNTIME_USER}
183
186
  {% endif %}
184
187
 
185
188
  {% if HAS_DEBUG_DEPS %}
186
- # Optional debug stage: only installs debug deps if they were exported. This stage will not
187
- # be built by default (the final stage below is the runtime image), and it will safely do
188
- # nothing if there are no debug requirements
189
+ # The debug target adds its locked dependency group to the runtime environment.
189
190
  FROM runtime AS debug
190
191
 
191
192
  USER root
192
193
 
193
194
  COPY --from=builder /tmp/build /tmp/build
194
195
 
195
- RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache{{ CACHE_ID_SUFFIX }} pip install --root-user-action=ignore -r /tmp/build/requirements-debug.txt
196
+ RUN --mount=from=uv-tool,source=/uv,target=/usr/local/bin/uv \
197
+ --mount=type=cache,target=/root/.cache/uv,id=uv-cache{{ CACHE_ID_SUFFIX }}{% for mount in UV_INDEX_SECRET_MOUNTS %} \
198
+ --mount={{ mount }}{% endfor %} \
199
+ UV_DYNAMIC_VERSIONING_BYPASS="${PACKAGE_VERSION}" UV_PROJECT_ENVIRONMENT=/opt/venv \
200
+ uv sync --project /tmp/build --python /usr/local/bin/python --no-python-downloads \
201
+ --locked --no-default-groups --group debug --no-install-project --no-editable --inexact --link-mode copy
196
202
 
197
203
  USER ${RUNTIME_USER}
198
204
  {% endif %}
@@ -279,4 +279,6 @@ def replace_dockerfile_reference(text: str) -> str:
279
279
  """
280
280
  if len(DOCKERFILE_REFERENCE_PATTERN.findall(text)) != 1:
281
281
  raise ValueError("Expected exactly one generated Dockerfile-reference block")
282
- return DOCKERFILE_REFERENCE_PATTERN.sub(build_dockerfile_reference(), text)
282
+ return DOCKERFILE_REFERENCE_PATTERN.sub(
283
+ lambda _: build_dockerfile_reference(), text
284
+ )
@@ -6,11 +6,13 @@ ARG PYTHON_VERSION=3
6
6
  # Variant for the runtime image, e.g. slim, alpine, etc.
7
7
  # See https://hub.docker.com/_/python for available variants. Leave empty for no variant.
8
8
  ARG PYTHON_VARIANT=slim
9
+ ARG UV_VERSION=latest
10
+
11
+ FROM ghcr.io/astral-sh/uv:${UV_VERSION:-latest} AS uv-tool
9
12
 
10
13
  FROM python:${PYTHON_VERSION} AS builder
11
14
 
12
15
  ARG PACKAGE_VERSION
13
- ARG UV_VERSION
14
16
 
15
17
  {% if CONTAINER_ENV_VARS %}
16
18
  # Make configured variables available to package build commands.
@@ -24,32 +26,18 @@ ENV {{ env_var }}
24
26
  # false dirty-version detection from a partial working tree.
25
27
  ENV UV_DYNAMIC_VERSIONING_BYPASS=${PACKAGE_VERSION}
26
28
 
27
- # Install uv for package build and dependency export steps
28
- RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache{{ CACHE_ID_SUFFIX }} \
29
- sh -c 'if [ -n "${UV_VERSION:-}" ]; then \
30
- pip install --root-user-action=ignore "uv==$UV_VERSION"; \
31
- else \
32
- pip install --root-user-action=ignore uv; \
33
- fi'
34
-
35
29
  # Build package
36
30
  WORKDIR /tmp/build
37
31
  COPY . /tmp/build/
38
32
 
39
- {% if HAS_DEBUG_DEPS %}
40
- # Export debug requirements when the project defines a debug dependency group
41
- RUN --mount=type=cache,target=/root/.cache/uv,id=uv-cache{{ CACHE_ID_SUFFIX }}{% for mount in UV_INDEX_SECRET_MOUNTS %} \
42
- --mount={{ mount }}{% endfor %} \
43
- uv export --frozen --only-group debug --no-hashes --format requirements-txt --output-file requirements-debug.txt
44
- {% endif %}
45
-
46
33
  # Build the wheel, caching the uv cache directory to speed up subsequent builds.
47
34
  # If running this in a CI system, you must be using a persistent builder to take
48
35
  # advantage of the cache mount, and you should configure your CI to persist the
49
36
  # cache directory between builds
50
- RUN --mount=type=cache,target=/root/.cache/uv,id=uv-cache{{ CACHE_ID_SUFFIX }}{% for mount in UV_INDEX_SECRET_MOUNTS %} \
37
+ RUN --mount=from=uv-tool,source=/uv,target=/usr/local/bin/uv \
38
+ --mount=type=cache,target=/root/.cache/uv,id=uv-cache{{ CACHE_ID_SUFFIX }}{% for mount in UV_INDEX_SECRET_MOUNTS %} \
51
39
  --mount={{ mount }}{% endfor %} \
52
- uv build --wheel
40
+ uv build --wheel --out-dir /tmp/wheels
53
41
 
54
42
  FROM python:${PYTHON_VERSION}${PYTHON_VARIANT:+-${PYTHON_VARIANT}} AS runtime
55
43
  ARG PYTHON_VERSION
@@ -110,11 +98,21 @@ RUN set -eux; \
110
98
 
111
99
  WORKDIR ${WORKDIR_PATH}
112
100
 
113
- # Grab package from builder image
114
- COPY --from=builder /tmp/build/dist/*.whl /tmp/
101
+ # Sync locked dependencies for the runtime platform, then install the built wheel.
102
+ ARG PACKAGE_VERSION
103
+ RUN --mount=from=uv-tool,source=/uv,target=/usr/local/bin/uv \
104
+ --mount=from=builder,source=/tmp/build,target=/tmp/build,rw \
105
+ --mount=from=builder,source=/tmp/wheels,target=/tmp/wheels \
106
+ --mount=type=cache,target=/root/.cache/uv,id=uv-cache{{ CACHE_ID_SUFFIX }}{% for mount in UV_INDEX_SECRET_MOUNTS %} \
107
+ --mount={{ mount }}{% endfor %} \
108
+ UV_DYNAMIC_VERSIONING_BYPASS="${PACKAGE_VERSION}" UV_PROJECT_ENVIRONMENT=/opt/venv \
109
+ uv sync --project /tmp/build --python /usr/local/bin/python --no-python-downloads \
110
+ --locked --no-default-groups --no-install-project --no-editable --link-mode copy \
111
+ && uv pip install --python /opt/venv/bin/python --no-deps --link-mode copy /tmp/wheels/*.whl \
112
+ && /usr/local/bin/python -m pip uninstall --yes --root-user-action=ignore pip
113
+
114
+ ENV PATH="/opt/venv/bin:${PATH}"
115
115
 
116
- # Install package
117
- RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache{{ CACHE_ID_SUFFIX }} pip install --root-user-action=ignore /tmp/*.whl
118
116
  # Create symlinks for the package
119
117
  ARG PACKAGE_NAME
120
118
  ENV PACKAGE_NAME=${PACKAGE_NAME}
@@ -133,7 +131,7 @@ LABEL git.commit=${GIT_COMMIT}
133
131
  # This entrypoint is deliberately not configurable via environment variables in order to
134
132
  # ensure that the container always uses the entrypoint selected at build time. If the
135
133
  # current package does not provide a console script, the entrypoint will default to `python`
136
- RUN echo "#!/bin/sh\n\nexec {{ ENTRYPOINT_COMMAND|default('python') }} \"\$@\"" >/pkg/entrypoint.sh \
134
+ RUN printf '%s\n' '#!/bin/sh' '' "exec {{ ENTRYPOINT_COMMAND|default('python') }} \"\$@\"" >/pkg/entrypoint.sh \
137
135
  && chmod +x /pkg/entrypoint.sh
138
136
 
139
137
  ARG RUNTIME_USER=py
@@ -144,16 +142,19 @@ USER ${RUNTIME_USER}
144
142
  {% endif %}
145
143
 
146
144
  {% if HAS_DEBUG_DEPS %}
147
- # Optional debug stage: only installs debug deps if they were exported. This stage will not
148
- # be built by default (the final stage below is the runtime image), and it will safely do
149
- # nothing if there are no debug requirements
145
+ # The debug target adds its locked dependency group to the runtime environment.
150
146
  FROM runtime AS debug
151
147
 
152
148
  USER root
153
149
 
154
150
  COPY --from=builder /tmp/build /tmp/build
155
151
 
156
- RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache{{ CACHE_ID_SUFFIX }} pip install --root-user-action=ignore -r /tmp/build/requirements-debug.txt
152
+ RUN --mount=from=uv-tool,source=/uv,target=/usr/local/bin/uv \
153
+ --mount=type=cache,target=/root/.cache/uv,id=uv-cache{{ CACHE_ID_SUFFIX }}{% for mount in UV_INDEX_SECRET_MOUNTS %} \
154
+ --mount={{ mount }}{% endfor %} \
155
+ UV_DYNAMIC_VERSIONING_BYPASS="${PACKAGE_VERSION}" UV_PROJECT_ENVIRONMENT=/opt/venv \
156
+ uv sync --project /tmp/build --python /usr/local/bin/python --no-python-downloads \
157
+ --locked --no-default-groups --group debug --no-install-project --no-editable --inexact --link-mode copy
157
158
 
158
159
  USER ${RUNTIME_USER}
159
160
  {% endif %}
@@ -20,11 +20,10 @@ def publish_package(
20
20
  from .project import get_publish_command
21
21
  from .utils import run_command
22
22
 
23
+ command = get_publish_command(repository=repository, repository_url=repository_url)
23
24
  if build_first:
24
25
  build_package(clean_dist=True)
25
- run_command(
26
- get_publish_command(repository=repository, repository_url=repository_url)
27
- )
26
+ run_command(command, unset_env=("UV_PUBLISH_INDEX", "UV_PUBLISH_URL"))
28
27
 
29
28
 
30
29
  @tasks.script(
@@ -18,14 +18,6 @@ LOGGER = logging.getLogger(__name__)
18
18
 
19
19
  PUBLISH_REPOSITORY_ENV_VAR = "COMMON_PYTHON_TASKS_PUBLISH_REPOSITORY"
20
20
  PUBLISH_REPOSITORY_URL_ENV_VAR = "COMMON_PYTHON_TASKS_PUBLISH_URL"
21
- PUBLISH_REPOSITORY_ENV_VARS = (
22
- PUBLISH_REPOSITORY_ENV_VAR,
23
- "UV_PUBLISH_INDEX",
24
- )
25
- PUBLISH_URL_ENV_VARS = (
26
- PUBLISH_REPOSITORY_URL_ENV_VAR,
27
- "UV_PUBLISH_URL",
28
- )
29
21
 
30
22
 
31
23
  def _parse_tool_version_output(output: str, tool_name: str) -> str:
@@ -44,14 +36,6 @@ def _parse_tool_version_output(output: str, tool_name: str) -> str:
44
36
  utils.fatal(f"Unable to parse {tool_name} version output: {output!r}")
45
37
 
46
38
 
47
- def _find_non_empty_env_override(env_vars: Sequence[str]) -> tuple[str, str] | None:
48
- for env_var in env_vars:
49
- value = os.getenv(env_var)
50
- if value is not None and value.strip():
51
- return env_var, value.strip()
52
- return None
53
-
54
-
55
39
  def _resolve_uv_publish_repository_from_config() -> str | None:
56
40
  pyproject_data = read_pyproject_toml()
57
41
  uv_config = pyproject_data.get("tool", {}).get("uv", {})
@@ -101,27 +85,17 @@ def _resolve_uv_publish_repository_from_config() -> str | None:
101
85
 
102
86
 
103
87
  def _resolve_default_publish_target() -> tuple[str | None, str | None]:
104
- repository_override = _find_non_empty_env_override(PUBLISH_REPOSITORY_ENV_VARS)
105
- if repository_override is not None:
106
- env_var, repository_name = repository_override
107
- LOGGER.debug("Using uv publish index %s from %s", repository_name, env_var)
108
- return repository_name, None
109
-
110
- config_repository_name = _resolve_uv_publish_repository_from_config()
111
- if config_repository_name is not None:
112
- LOGGER.debug(
113
- "Using uv publish index %s from [[tool.uv.index]] configuration",
114
- config_repository_name,
115
- )
116
- return config_repository_name, None
117
-
118
- repository_url_override = _find_non_empty_env_override(PUBLISH_URL_ENV_VARS)
119
- if repository_url_override is None:
120
- return None, None
121
-
122
- env_var, repository_url = repository_url_override
123
- LOGGER.debug("Using uv publish URL %s from %s", repository_url, env_var)
124
- return None, repository_url
88
+ for repository_var, url_var in (
89
+ (PUBLISH_REPOSITORY_ENV_VAR, PUBLISH_REPOSITORY_URL_ENV_VAR),
90
+ ("UV_PUBLISH_INDEX", "UV_PUBLISH_URL"),
91
+ ):
92
+ repository = os.getenv(repository_var, "").strip()
93
+ repository_url = os.getenv(url_var, "").strip()
94
+ if repository and repository_url:
95
+ utils.fatal(f"Specify either {repository_var} or {url_var}, not both.")
96
+ if repository or repository_url:
97
+ return repository or None, repository_url or None
98
+ return _resolve_uv_publish_repository_from_config(), None
125
99
 
126
100
 
127
101
  def get_build_command(wheel_only: bool = False) -> list[str]:
@@ -174,6 +148,10 @@ def get_publish_command(
174
148
 
175
149
  Returns:
176
150
  Command tokens for the package publish command.
151
+
152
+ Raises:
153
+ SystemExit: The winning target source specifies both an index and URL,
154
+ or configured publishing indexes are ambiguous.
177
155
  """
178
156
  if repository is not None and repository_url is not None:
179
157
  utils.fatal("Specify either `repository` or `repository_url`, not both.")
@@ -150,11 +150,13 @@ def _run_release_flow(
150
150
  parse_release_stage,
151
151
  )
152
152
  from .packaging_tasks import bump_version, publish_github_release
153
+ from .project import get_publish_command
153
154
  from .utils import (
154
155
  log_dry_run,
155
156
  run_command,
156
157
  )
157
158
 
159
+ get_publish_command(repository=repository, repository_url=repository_url)
158
160
  release_component = parse_release_component(component)
159
161
  release_stage = parse_release_stage(stage)
160
162
  pre_script = pre_script or os.getenv("RELEASE_PRE_SCRIPT")
@@ -114,6 +114,7 @@ def run_command(
114
114
  env: dict[str, str] | None = None,
115
115
  always_show_command: bool = False,
116
116
  dry_run: bool = False,
117
+ unset_env: Collection[str] | None = None,
117
118
  ) -> subprocess.CompletedProcess | None:
118
119
  """Run a command as a subprocess and handle errors.
119
120
 
@@ -128,6 +129,7 @@ def run_command(
128
129
  always_show_command: If `True`, log the command with INFO when not in dry-run
129
130
  mode.
130
131
  dry_run: If `True`, log the command without executing it.
132
+ unset_env: Environment variable names to remove after merging overrides.
131
133
 
132
134
  Returns:
133
135
  The `CompletedProcess` instance from the subprocess run, or `None` for dry-run
@@ -151,12 +153,20 @@ def run_command(
151
153
  log_dry_run("Would run command: %s", " ".join(command))
152
154
  return None
153
155
 
154
- merged_env = {**os.environ, **env} if env is not None else None
156
+ merged_env = (
157
+ {**os.environ, **(env or {})}
158
+ if env is not None or unset_env is not None
159
+ else None
160
+ )
161
+ if merged_env is not None:
162
+ for name in unset_env or ():
163
+ merged_env.pop(name, None)
155
164
 
156
165
  out = subprocess.run(
157
166
  command,
158
167
  capture_output=capture_output,
159
168
  check=False,
169
+ shell=False,
160
170
  text=True,
161
171
  env=merged_env,
162
172
  )