Skip to content

Fix(sonatype): Stop uv using the checkout's Python - #181

Merged
askb merged 1 commit into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:fix/isolate-python-invocations
Nov 2, 2026
Merged

askb merged 1 commit into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:fix/isolate-python-invocations

Conversation

@ModeSevenIndustrialSolutions

Copy link
Copy Markdown
Member

Summary

The Python path of the Sonatype Lifecycle scan job used two uv steps that took their interpreter from the checked-out project.

setup-uv worked in the workspace, its default working-directory, which holds the checkout. There it ran 'uv python find' and then executed the interpreter found, which a .venv or a .python-version in the checkout chooses, and it read cache-dir from a uv.toml or pyproject.toml there with its own code. Nothing it does needs the project, so it now works in runner.temp, with UV_NO_CONFIG, UV_SYSTEM_PYTHON and UV_NO_PROJECT on the step. The python-version input is not used: it would export UV_PYTHON to every later step.

'uv venv' in the resolve step had no --no-config, so with python_version empty a .python-version in the checkout chose the interpreter, and a uv.toml there could stop the step. It now passes --no-config. The project's requires-python still applies, so the python_version description, which promised only that, holds; it now says a .python-version is not read.

tests/workflow-steps.sh checks the setup-uv step's working-directory and env, and runs the resolve step against a stub uv to check the arguments 'uv venv' really receives. Neither the lane nor setup-uv can run in that offline job, and testing.yaml cannot place files in a checkout the lane itself makes. All five new cases fail against the previous workflow.

Replayed locally with the real setup-uv v10.3.3 and uv 0.13.4 on the test-python-project fixture, planted with a .venv and a .python-version whose interpreters only append to a marker file: the old steps executed the planted .python-version interpreter in setup-uv and again in 'uv venv'; the new ones did not, and the requirements.txt branch resolved as before. Unplanted, old and new resolve the same artefacts (7 from uv.lock, 1 from requirements.txt).

This is not the whole of it. The job still runs the project's own build code ('pip download .' and sdist builds) before the scan step that holds nexus_iq_password; splitting resolution from the scan is tracked in issue #180 and left for that. Measured meanwhile: 'uv export' in the uv.lock branch executes a checkout .venv even with --no-config or --python, unless UV_PROJECT_ENVIRONMENT points elsewhere, so it belongs with that work too.

Validation

Local, before push:

  • tests/workflow-steps.sh: 119 cases pass; the 5 new cases fail against the previous workflow.
  • The planted-file check was replayed locally with real uv (0.11.21 and 0.13.4): with the previous steps a planted interpreter ran (a marker file it writes on start appeared); with these steps none did.
  • prek hooks pass; the aislop gate adds no findings; zizmor --persona auditor reports nothing.

The new CI checks have not run anywhere yet: this pull request is their first run.

For the reviewer

Splitting dependency resolution from the scan job is issue #180 and is not part of this change. uv export in the uv.lock branch also uses a checkout .venv; it belongs with that work.

The Python path of the Sonatype Lifecycle scan job used two uv steps
that took their interpreter from the checked-out project.

setup-uv worked in the workspace, its default working-directory,
which holds the checkout. There it ran 'uv python find' and then
executed the interpreter found, which a .venv or a .python-version in
the checkout chooses, and it read cache-dir from a uv.toml or
pyproject.toml there with its own code. Nothing it does needs the
project, so it now works in runner.temp, with UV_NO_CONFIG,
UV_SYSTEM_PYTHON and UV_NO_PROJECT on the step. The python-version
input is not used: it would export UV_PYTHON to every later step.

'uv venv' in the resolve step had no --no-config, so with
python_version empty a .python-version in the checkout chose the
interpreter, and a uv.toml there could stop the step. It now passes
--no-config. The project's requires-python still applies, so the
python_version description, which promised only that, holds; it now
says a .python-version is not read.

tests/workflow-steps.sh checks the setup-uv step's working-directory
and env, and runs the resolve step against a stub uv to check the
arguments 'uv venv' really receives. Neither the lane nor setup-uv
can run in that offline job, and testing.yaml cannot place files in
a checkout the lane itself makes. All five new cases fail against
the previous workflow.

Replayed locally with the real setup-uv v10.3.3 and uv 0.13.4 on the
test-python-project fixture, planted with a .venv and a
.python-version whose interpreters only append to a marker file: the
old steps executed the planted .python-version interpreter in
setup-uv and again in 'uv venv'; the new ones did not, and the
requirements.txt branch resolved as before. Unplanted, old and new
resolve the same artefacts (7 from uv.lock, 1 from requirements.txt).

This is not the whole of it. The job still runs the project's own
build code ('pip download .' and sdist builds) before the scan step
that holds nexus_iq_password; splitting resolution from the scan is
tracked in issue lfreleng-actions#180 and left for that. Measured meanwhile: 'uv
export' in the uv.lock branch executes a checkout .venv even with
--no-config or --python, unless UV_PROJECT_ENVIRONMENT points
elsewhere, so it belongs with that work too.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions requested review from a team and a balanced review from Copilot October 30, 2026 08:35
@github-actions github-actions Bot added the bug Something isn't working label Oct 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block approval of the Python dependency setup hardening.

No open issues 🎉

What changed in this PR

This PR hardens Python dependency setup in the Sonatype Lifecycle workflow by preventing the changed uv steps from selecting an interpreter through checkout-local settings. Separating resolution from the credential-bearing scan job remains deferred to issue #180.

Changes:

  • Runs setup-uv in runner.temp with environment flags that disable configuration and project discovery and require system Python.
  • Adds --no-config to uv venv and clarifies the python_version input description.
  • Adds regression checks for setup-uv isolation settings and the arguments passed to uv venv.
File Description
tests/​workflow-steps.sh Adds setup-uv configuration checks and a stub-based uv venv argument check.
.github/​workflows/​sonatype-lifecycle.yaml Isolates setup-uv from the checkout and disables configuration discovery during environment creation.

Review effort: Balanced

@askb askb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed together with the other setup-uv workdir PRs. I checked setup-uv v10.3.3: its JS reads uv.toml and pyproject.toml only from working-directory, and the UV_* step env covers 'uv python find' when a parent directory holds a .venv. I also reproduced with uv 0.13.4 against a planted .venv, .python-version and uv.toml: nothing planted runs with this change, and uvx and uv tool install ignore a workspace uv.toml (index-url included). LGTM.

@askb
askb merged commit 090a4fa into lfreleng-actions:main Nov 2, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants