From 43a5352c9b007f3620c011f95c2a4b2540c504eb Mon Sep 17 00:00:00 2001 From: "Sam S. Yu" <25761223+yudataguy@users.noreply.github.com> Date: Tue, 4 Aug 2026 20:16:47 -0700 Subject: [PATCH] fix(build): pin pre-commit's Python to .python-version pre-commit builds its hook environments with whatever interpreter happens to run it. Nothing pinned that, so on a machine where uvx resolved an older Python the hooks were built against it, and `make fmt` failed with a SyntaxError that has nothing to do with the caller's changes: File "", line 195 assert updated_time > initial_time, f"Time should increase. Initial: { SyntaxError: unterminated string literal rtc_test.py:195 uses a multi-line f-string, which is valid under the project's declared Python (3.13, PEP 701) but not under 3.11, so the interrogate hook could not parse it. CI happens to resolve a new enough interpreter, so this only bites locally and only on some machines. Pin the interpreter for uvx-run tooling to .python-version, keeping one source of truth. uv downloads the pinned interpreter when it is missing, so this needs no setup from contributors. Verified with a cleared pre-commit cache: `make fmt` rebuilds every hook environment and all hooks pass. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_011kehXMi9zAAoPJ3PgfRd81 --- Makefile | 4 ++-- makelib/build-tools.mk | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index af982516..e9ed6dfe 100644 --- a/Makefile +++ b/Makefile @@ -58,11 +58,11 @@ zephyr-setup: fprime-venv ## Set up Zephyr environment .PHONY: pre-commit-install pre-commit-install: uv ## Install pre-commit hooks - @$(UVX) pre-commit install > /dev/null + @$(UVX_PINNED) pre-commit install > /dev/null .PHONY: fmt fmt: pre-commit-install ## Lint and format files - @$(UVX) pre-commit run --all-files + @$(UVX_PINNED) pre-commit run --all-files .PHONY: data-budget data-budget: fprime-venv ## Analyze telemetry data budget (use VERBOSE=1 for detailed output) diff --git a/makelib/build-tools.mk b/makelib/build-tools.mk index 9e346c8f..f2dfb4d1 100644 --- a/makelib/build-tools.mk +++ b/makelib/build-tools.mk @@ -10,10 +10,19 @@ $(TOOLS_DIR): ### Tool Versions UV_VERSION ?= 0.8.13 +### Python version used for tooling environments. Single source of truth is .python-version, so +### that tools do not silently build against whichever interpreter happens to be on the machine. +PYTHON_VERSION ?= $(shell cat .python-version) + ### uv & uvx UV_DIR ?= $(TOOLS_DIR)/uv-$(UV_VERSION) UV ?= $(UV_DIR)/uv UVX ?= $(UV_DIR)/uvx +### Pin the interpreter for uvx-run tooling. pre-commit builds its hook environments with whatever +### Python runs it, so without this a machine defaulting to an older interpreter builds hook +### environments that cannot parse project sources written for .python-version. uv downloads the +### pinned interpreter if it is missing. +UVX_PINNED ?= $(UVX) --python $(PYTHON_VERSION) .PHONY: uv uv: $(UV) ## Download uv $(UV): $(TOOLS_DIR)