Skip to content

feat: migrate to uv with lockfile for supply chain security#270

Open
viraatc wants to merge 12 commits intomainfrom
feat/viraatc-uv
Open

feat: migrate to uv with lockfile for supply chain security#270
viraatc wants to merge 12 commits intomainfrom
feat/viraatc-uv

Conversation

@viraatc
Copy link
Copy Markdown
Collaborator

@viraatc viraatc commented Apr 3, 2026

Summary

  • Replace setuptools build backend with uv_build — auto-discovers src layout, pure Python
  • Add uv.lock with cryptographic hashes for all 133 direct + transitive dependencies (Linux + macOS, x86_64 + arm64)
  • Migrate CI workflows (test.yml, pre-commit.yml) from pip to uv run --frozen for hash-verified installs
  • Migrate Dockerfile.dev to use uv binary with uv sync --frozen
  • Add uv-lock-check pre-commit hook to enforce lockfile freshness when pyproject.toml changes
  • Update README and AGENTS.md with both uv (recommended) and pip+venv install paths

Supply chain protection

Attack Before After
Version hijack (same version, different content) Vulnerable Blocked (hash mismatch)
Dependency confusion Vulnerable Blocked (single index + lockfile pins source)
Transitive dep compromise Vulnerable (not pinned) Blocked (every transitive dep hashed)
Compromised CI install No verification --frozen + hashes = reproducible

Backward compatibility

  • pip install -e ".[dev,test]" still works (pip downloads uv_build from PyPI automatically)
  • No workflow change for non-uv contributors

Test plan

  • All pre-commit hooks pass (including new uv-lock-check)
  • 705 tests pass via uv run pytest
  • pip venv install verified: pip install -e ".[test]" + import OK
  • CI workflows pass on this PR

🤖 Generated with Claude Code

viraatc and others added 10 commits April 3, 2026 04:59
Supply chain hardening via uv lockfile with cryptographic hashes
for all direct and transitive dependencies. Covers build backend
swap, CI workflows, Dockerfile, and pre-commit enforcement.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
8-task plan covering build backend, lockfile, CI workflows,
Dockerfile, pre-commit hook, and AGENTS.md updates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Swap build-system to uv_build, remove [tool.setuptools] sections,
add [tool.uv] config with platform-restricted environments
(Linux + macOS, x86_64 + arm64).
Pin Python 3.12 for uv auto-selection. Generated lockfile with
cryptographic hashes for all direct and transitive dependencies
across Linux + macOS (x86_64 + arm64). Also fix index-url field name
(default-index is not valid in [tool.uv] for uv 0.9.28).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace setup-python + pip install with setup-uv + uv run --frozen.
Lockfile hashes are now enforced in CI.
Use uv binary from official image, uv sync --frozen for
hash-verified installs, improved Docker layer caching.
Runs uv lock --check when pyproject.toml changes, fails if
lockfile is stale.
Add uv sync/run commands alongside existing pip instructions.
Document uv add for dependency management.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Show both uv (recommended) and pip+venv installation options
in README. Remove internal planning documents from branch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 3, 2026 20:29
@viraatc viraatc requested a review from a team as a code owner April 3, 2026 20:29
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

@github-actions github-actions bot requested review from arekay-nv and nvzhihanj April 3, 2026 20:29
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request migrates the project's dependency management and build system from setuptools/pip to uv. Key changes include updating pyproject.toml to use uv_build, adding a .python-version file, updating documentation (README.md, AGENTS.md) with uv-specific commands, and refactoring the development Dockerfile to utilize uv for faster, reproducible builds. Feedback focuses on correcting the build-system requirement name, fixing file exclusion paths in the build configuration, and optimizing the Dockerfile for better layer caching and volume mount compatibility.

[build-system]
requires = ["setuptools==78.1.1", "wheel==0.46.3"]
build-backend = "setuptools.build_meta"
requires = ["uv_build>=0.7.6,<0.8"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The build system requirement should be uv-build-backend, not uv_build. While the backend entry point is named uv_build, the package name on PyPI is uv-build-backend. Using the incorrect name will cause pip and other PEP 517 compatible tools to fail when attempting to build the project from source.

Suggested change
requires = ["uv_build>=0.7.6,<0.8"]
requires = ["uv-build-backend>=0.1.0"]

ENV PATH="/home/appuser/.local/bin:$PATH"

RUN pip install -e .[dev,test]
RUN uv sync --frozen --extra dev --extra test
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

When running the container with a volume mount (as suggested in the file header: -v $(pwd):/mnt/inference-endpoint), the .venv directory created here will be obscured by the host directory. This will result in the installed dependencies being unavailable in the running container. To resolve this, consider setting UV_PROJECT_ENVIRONMENT to a location outside the project root (e.g., /opt/venv) and adding that location to the PATH.

[tool.uv.build]
module-root = "src"
data = {"inference_endpoint" = ["config/templates/*.yaml"]}
exclude = ["evaluation/livecodebench/_server.py"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The exclude path should be relative to the project root to ensure the file is correctly identified and excluded from the build. Since module-root is set to src, the path should include the src/ prefix to match the actual file location.

Suggested change
exclude = ["evaluation/livecodebench/_server.py"]
exclude = ["src/inference_endpoint/evaluation/livecodebench/_server.py"]

Comment on lines +26 to 27
COPY pyproject.toml uv.lock .python-version ./
COPY src/ ./src/
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To optimize Docker layer caching, it is recommended to install dependencies before copying the full source code. This prevents the uv sync step from re-running every time a source file is modified. You can use uv sync --no-install-project to install only the dependencies first.

COPY pyproject.toml uv.lock .python-version ./
RUN uv sync --frozen --no-install-project --extra dev --extra test
COPY src/ ./src/

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Migrates the project’s packaging, local/dev environment, and CI installation flow to uv with a committed uv.lock to improve reproducibility and supply-chain integrity.

Changes:

  • Switch build backend from setuptools to uv_build and add tool.uv / tool.uv.build configuration.
  • Introduce uv.lock (+ .python-version) and update Docker/CI/pre-commit to use frozen, lockfile-verified installs.
  • Update contributor docs (README, AGENTS) with both uv and pip workflows.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
scripts/Dockerfile.dev Installs uv and uses uv sync --frozen for dev image builds.
README.md Documents uv-based setup alongside the existing pip+venv path.
pyproject.toml Moves build backend to uv_build and adds uv configuration for builds/resolution.
AGENTS.md Updates common commands and dependency guidance to include uv.
.python-version Adds a Python version hint for tooling (3.12).
.pre-commit-config.yaml Adds a uv lock --check hook to enforce lock freshness.
.github/workflows/test.yml Runs tests and pip-audit via uv run --frozen.
.github/workflows/pre-commit.yml Runs pre-commit via uv with frozen dependencies.
uv.lock Adds a hash-verified lockfile for direct + transitive dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

[tool.uv.build]
module-root = "src"
data = {"inference_endpoint" = ["config/templates/*.yaml"]}
exclude = ["evaluation/livecodebench/_server.py"]
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

tool.uv.build.exclude path looks incorrect given the actual file location is src/inference_endpoint/evaluation/livecodebench/_server.py. With module-root = "src", the exclude entry likely needs to include the inference_endpoint/ prefix; otherwise _server.py may be unintentionally packaged.

Suggested change
exclude = ["evaluation/livecodebench/_server.py"]
exclude = ["inference_endpoint/evaluation/livecodebench/_server.py"]

Copilot uses AI. Check for mistakes.
- id: uv-lock-check
name: Check uv.lock is up-to-date
entry: uv lock --check
language: system
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

This hook runs uv lock --check with language: system, so pre-commit will fail on machines that don’t have the uv binary installed on PATH (including pip-only setups). Consider switching to a hook that provisions uv automatically or ensure uv is installed as part of the documented/dev dependency setup so non-uv contributors aren’t blocked.

Suggested change
language: system
language: python
additional_dependencies:
- uv

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +9
# Copy uv binary from official image
COPY --from=ghcr.io/astral-sh/uv:0.7.6 /uv /uvx /bin/
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

For supply-chain reproducibility, copying uv from an image tag (ghcr.io/astral-sh/uv:0.7.6) is still mutable. Consider pinning the --from image to an immutable digest so builds can’t change if the tag is retargeted.

Suggested change
# Copy uv binary from official image
COPY --from=ghcr.io/astral-sh/uv:0.7.6 /uv /uvx /bin/
# Copy uv binary from an immutable official image reference
COPY --from=ghcr.io/astral-sh/uv:0.7.6@sha256:<verified-digest-for-0.7.6> /uv /uvx /bin/

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +19
- name: Install uv
uses: astral-sh/setup-uv@e58605a9b6da7c637471fab8847a5e5a6b8df081 # v5

- name: Run tests
run: |
pytest -xv -m "not slow and not performance" --cov=src --cov-report=xml --cov-report=html
run: uv run --frozen --extra test pytest -xv -m "not slow and not performance" --cov=src --cov-report=xml --cov-report=html
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

CI no longer pins/sets up a specific Python version. Since this project requires Python >=3.12 and previously enforced 3.12, consider explicitly setting up Python (or configuring the uv setup step to install/use 3.12) to keep CI reproducible and avoid breakage if the runner’s default Python changes.

Copilot uses AI. Check for mistakes.
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@e58605a9b6da7c637471fab8847a5e5a6b8df081 # v5
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

This workflow now relies on whatever Python happens to be on the runner. To avoid non-reproducible pre-commit results, explicitly set up the intended Python version (3.12) or configure the uv setup step accordingly.

Suggested change
uses: astral-sh/setup-uv@e58605a9b6da7c637471fab8847a5e5a6b8df081 # v5
uses: astral-sh/setup-uv@e58605a9b6da7c637471fab8847a5e5a6b8df081 # v5
with:
python-version: "3.12"

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants