common-python-tasks 0.13.1__py3-none-any.whl → 0.14.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.
@@ -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
  )
@@ -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`.
@@ -8,22 +8,22 @@ common_python_tasks/docker.py,sha256=1vmuDfxmdKkqOATpJfERkILAykpQp-vNxuWYjH6GQi4
8
8
  common_python_tasks/env.py,sha256=3Ehrqte8xaVp2Xn7limHMb75hQdvfc74KIpDnnobnd8,21832
9
9
  common_python_tasks/git.py,sha256=teGf4V0oo1vW-4kHrmU1s6BmO4V3F8zVrI4Atx6Eu2w,12206
10
10
  common_python_tasks/github.py,sha256=Jc04x-ky3o17AYmMB26psSHPlbdvqaV6n-w9hvpurRs,21725
11
- common_python_tasks/packaging_tasks.py,sha256=to1SAD7wnDAXt2KT9H7pr9wySAoR2hiYurpUx-ME5TI,5251
12
- common_python_tasks/project.py,sha256=taJDqaIC4hZkDx6D2aNtACQW0Z01evnub3XblYCuWaw,17292
13
- common_python_tasks/release_tasks.py,sha256=YOTdvDgPZUvHfSTwT1dxhnIbhVAhMVQsODUtSLGNh_A,14529
11
+ common_python_tasks/packaging_tasks.py,sha256=xGDTeh3TUuN4eYLSORuFWTLoOIQys9X_4ytLSRfdT04,5309
12
+ common_python_tasks/project.py,sha256=F8XsBen5yuZQa1VgnEtlg_HlGAgQJSmvv3COcdoFAhE,16660
13
+ common_python_tasks/release_tasks.py,sha256=5vk7g2P3TemBZP4XELb26mIV-hZh7g0jqan4jbmI33s,14652
14
14
  common_python_tasks/tasks.py,sha256=yeEPOkWrABaF5_HjJbYMDKha81OaYGC7-6DFSUBHZVE,2326
15
- common_python_tasks/utils.py,sha256=uY508Sm2mzNQaLX6xWPusXy4ZpJqPg7-qz2BXZ06b-0,21207
15
+ common_python_tasks/utils.py,sha256=jfGeaX_Fl0PgFbjrFyb1PUYGdQhRQk1C6D13FaAvIwc,21527
16
16
  common_python_tasks/data/dockerfile_extensions/docker-in-docker/Dockerfile,sha256=m7jeQyFe6mAv8AVGpM89NHljzG21ctcSyllbvoEL0Do,1021
17
17
  common_python_tasks/data/dockerfile_extensions/docker-in-docker/install.sh,sha256=F87oojGFYT5F1mdcMchRNlUeI_viAO4ip04UHBC_8bQ,1224
18
18
  common_python_tasks/data/dockerfile_extensions/docker-in-docker/supervisor.sh,sha256=l1R_ZzkcR0PhL21zgXZSV-tqTjV3KeG9i371Ux_1-ms,3768
19
19
  common_python_tasks/data/generic/.coveragerc,sha256=8zXwDq18wIKQV4NtW2NJYpo3nxCO4LsAChyluYTUoJc,85
20
20
  common_python_tasks/data/generic/.dockerignore,sha256=8kHwNa6Ct-6y3EvRjNuhOKfquuGEywq3P2BHIbG4uXo,53
21
21
  common_python_tasks/data/generic/Dockerfile.deps.j2,sha256=fBmcytyUd4LsC26y0IgZ09QPxrFp0gx0d3OlKNqZ-KM,663
22
- common_python_tasks/data/generic/Dockerfile.j2,sha256=UrR9T794V2ESNIkSVE7K5vEbx43NQiddfsWKG_bY6b4,6301
22
+ common_python_tasks/data/generic/Dockerfile.j2,sha256=TfNzZAIn5m-VM5vB3hIrcaMyDfS0HZXgjKdKdW5WFTU,6672
23
23
  common_python_tasks/data/generic/cliff.toml,sha256=po1MnEGEEgrpyBz3XLWr0h7emXb6ASX63lrU2r6o240,77
24
24
  common_python_tasks/data/generic/pytest.ini,sha256=RHak5QrLzKHvUBjFmaaiOYFrd_8YBRQubXEOT0NJfco,134
25
25
  common_python_tasks/data/generic/ruff.toml,sha256=njvd-5inSGmgY865SWCT4SR9IrKlzS7JQFZmAG2UT_E,53
26
- common_python_tasks-0.13.1.dist-info/METADATA,sha256=QcBLQj3eEZpU-AQ13DqqBQgTSa3OIMHuucXwdj4EefQ,3212
27
- common_python_tasks-0.13.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
28
- common_python_tasks-0.13.1.dist-info/licenses/LICENSE,sha256=RsSweM-DyzxFPx38fQOJqHrKyeT9Fiz8rO7yox-fOsw,1070
29
- common_python_tasks-0.13.1.dist-info/RECORD,,
26
+ common_python_tasks-0.14.0.dist-info/METADATA,sha256=RyMsmyLieXsgfevFiL1oQBkiQkdhVXS2hx2zUBM_XbQ,3212
27
+ common_python_tasks-0.14.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
28
+ common_python_tasks-0.14.0.dist-info/licenses/LICENSE,sha256=RsSweM-DyzxFPx38fQOJqHrKyeT9Fiz8rO7yox-fOsw,1070
29
+ common_python_tasks-0.14.0.dist-info/RECORD,,