Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/nightly-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ jobs:

- uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
with:
# Keep equal to the uv that generated uv.lock: another uv release can
# re-serialize the whole lockfile, which ``compile`` then refuses.
version: "0.13.1"
# Keep equal to the uv that generated uv.lock (pre-commit check-uv-version): another uv
# release can re-serialize the whole lockfile, which ``compile`` then refuses.
version: "0.12.9"

- name: Compile fragments
# Capture the compile exit code so the next step can commit/push
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ repos:
entry: tools/pre_commit/check_git_lfs_pointers.sh
language: script
pass_filenames: true
- id: check-uv-version
name: check uv version pins and uv.lock revision
entry: python tools/pre_commit/check_uv_version.py
language: python
additional_dependencies: [pyyaml]
files: ^(uv\.lock|docker/.*|source/isaaclab/test/install_ci/Dockerfile\.installci|\.github/.*\.ya?ml)$
pass_filenames: false
- id: no-print-warnings
name: use logger.warning or warnings.warn instead of print for warnings
# See "Warnings and Logging" in docs/source/refs/contributing.rst.
Expand Down
96 changes: 96 additions & 0 deletions tools/pre_commit/check_uv_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause

"""Pre-commit hook: every uv pin in the repository names one version, and ``uv.lock`` was written by it.

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.

🟡 Warning · Style Consistency — Describe the header check accurately

The hook checks a revision number, not which uv wrote the lockfile. This overstates its guarantee; describe the pin and header-revision comparison instead.


uv releases serialize ``uv.lock`` differently (its ``revision`` and some dependency lists). A lock written by one uv
and re-locked by another changes more than package versions, which the nightly changelog compile rejects.
``uv lock --check`` accepts either form, so the lock's ``revision`` is checked instead.
"""

from __future__ import annotations

import re
import sys
from pathlib import Path

import yaml

REPO_ROOT = Path(__file__).resolve().parents[2]

LOCK_REVISION = {"0.12.9": 3}
"""The ``uv.lock`` revision each pinned uv writes. Add the new entry when changing the pin."""

IMAGE_FILES = ("docker/Dockerfile.*", "docker/test/*.py", "source/isaaclab/test/install_ci/Dockerfile.installci")
IMAGE_PIN = re.compile(r"ghcr\.io/astral-sh/uv:(\d+\.\d+\.\d+)")

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.

P2 Moving image tags pass unchecked

IMAGE_PIN silently skips uv image references whose tags are not three-part versions. Changing one Dockerfile to ghcr.io/astral-sh/uv:latest removes that image from the check. The remaining pins still agree on 0.12.9, so the hook passes without checking the changed image.

Find every uv image reference first, then reject unsupported or unpinned tags.



def image_pins() -> list[tuple[str, str]]:

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.

🟡 Warning · Style Consistency — Keep file-local scanners private

These scanners and lock_revision have no callers outside this file. Their public names contradict the repository's private-function convention; prefix them with underscores and place them after main.

"""Return ``(location, version)`` for every ``ghcr.io/astral-sh/uv`` image reference."""
pins = []
for pattern in IMAGE_FILES:
for path in sorted(REPO_ROOT.glob(pattern)):
for number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):
location = f"{path.relative_to(REPO_ROOT)}:{number}"
pins += [(location, version) for version in IMAGE_PIN.findall(line)]
return pins


def workflow_pins() -> list[tuple[str, str]]:
"""Return ``(location, version)`` for every ``astral-sh/setup-uv`` step that sets ``version``.

Steps without ``version`` are skipped: they install the latest uv and do not write ``uv.lock``.
"""
pins = []
for path in sorted((REPO_ROOT / ".github").rglob("*.y*ml")):
document = yaml.safe_load(path.read_text(encoding="utf-8"))
if not isinstance(document, dict):
continue
steps = [step for job in (document.get("jobs") or {}).values() for step in job.get("steps") or []]
steps += (document.get("runs") or {}).get("steps") or [] # composite actions
for step in steps:
inputs = step.get("with") or {}
if str(step.get("uses", "")).startswith("astral-sh/setup-uv@") and "version" in inputs:
location = f"{path.relative_to(REPO_ROOT)} (step {step.get('name') or step['uses']!r})"
pins.append((location, str(inputs["version"])))
return pins


def lock_revision() -> int | None:
"""Return the ``revision`` from the ``uv.lock`` header, or ``None`` if it has none."""
with open(REPO_ROOT / "uv.lock", encoding="utf-8") as lock:
for line in lock:
if match := re.fullmatch(r"revision = (\d+)\s*", line):
return int(match[1])
if line.startswith("["):
return None
return None


def main() -> int:
"""Print every disagreement and return 1 if there is one."""

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.

🟡 Warning · Style Consistency — Correct the failure docstring

main returns on the first failed check, so it never prints every disagreement. Describe first-failure behavior or collect the errors before returning.

pins = image_pins() + workflow_pins()
versions = sorted({version for _, version in pins})
if len(versions) != 1:
listing = "\n".join(f" {location}: {version}" for location, version in pins)
print(f"uv is pinned to {len(versions)} versions; pin one everywhere:\n{listing}", file=sys.stderr)

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.

🟡 Warning · Style Consistency — Log CLI failures

All three failure branches print diagnostics, contrary to the contribution guide's CLI failure rule. Use a module-level logger.error for those messages.

return 1
version = versions[0]
if version not in LOCK_REVISION:
print(f"uv {version} has no LOCK_REVISION entry in {Path(__file__).relative_to(REPO_ROOT)}", file=sys.stderr)
return 1
revision, expected = lock_revision(), LOCK_REVISION[version]
if revision != expected:
print(
f"uv.lock has revision {revision}, but uv {version} writes revision {expected}: another uv wrote it."
f" Restore uv.lock from your base branch and re-lock with `uvx uv@{version} lock`.",
file=sys.stderr,
)
return 1
return 0


if __name__ == "__main__":
sys.exit(main())
Loading