Skip to content

refactor(uv): expand templates instead of .format() strings in uv_hub - #1496

Open
xangcastle wants to merge 1 commit into
mainfrom
xangcastle/expand-templates-instead-of-format-strings-in-uv_hub
Open

xangcastle wants to merge 1 commit into
mainfrom
xangcastle/expand-templates-instead-of-format-strings-in-uv_hub

Conversation

@xangcastle

@xangcastle xangcastle commented Aug 28, 2026

Copy link
Copy Markdown
Member

The hub repository rule was assembling its BUILD and .bzl files out of .format() strings, which meant doubling every brace in the generated Starlark and burying the skeletons inside the implementation.

This moves the static parts into five .tmpl files under uv/private/uv_hub/templates and expands them with repository_ctx.template, so the rule now only computes the dynamic bits: select arms, the group inversion, label lists.

Net effect is about ninety fewer lines, and the templates read as plain Starlark. Output is byte-for-byte identical, regenerating the snapshots produced an empty diff. Docstrings got a pass while I was in there: _hub_impl now documents the five artifacts and their invariants.


Changes are visible to end-users: no

Test plan

  • Covered by existing test cases

@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3ec66de1-9ee1-43b9-9885-5c731d406e8f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@aspect-workflows

aspect-workflows Bot commented Aug 28, 2026

Copy link
Copy Markdown

✨ Aspect Workflows Tasks

📅 Fri Aug 28 02:43:45 UTC 2026

✅ 44 successful tasks

  • ✅ buildifier · ⏱ 19s · 🐙 GitHub Actions · ☑️ Check
    💬 Format complete (clean)
  • ✅ gazelle · ⏱ 18.2s · 🐙 GitHub Actions · ☑️ Check
    💬 Gazelle complete (clean)
  • ✅ test-e2e-bazel-8 [test] · ⏱ 6m 8s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (314/314 passed)
  • ✅ test-e2e-bazel-9 [test] · ⏱ 6m 56s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (304/304 passed)
  • ✅ test-e2e-crossbuild-bazel-8 [test] · ⏱ 1m 35s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (13/13 passed)
  • ✅ test-e2e-crossbuild-bazel-9 [test] · ⏱ 2m 6s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (13/13 passed)
  • ✅ test-e2e-interpreter-build-config-bazel-8 [test] · ⏱ 21.7s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-e2e-interpreter-build-config-bazel-9 [test] · ⏱ 50.4s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-e2e-interpreter-input-validation-bazel-8 [test] · ⏱ 19.6s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-e2e-interpreter-input-validation-bazel-9 [test] · ⏱ 1m 4s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-e2e-interpreter-runtime-metadata-bazel-8 [test] · ⏱ 26.4s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (2/2 passed)
  • ✅ test-e2e-interpreter-runtime-metadata-bazel-9 [test] · ⏱ 43s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (2/2 passed)
  • ✅ test-e2e-interpreter-toolchain-settings-bazel-8 [test] · ⏱ 16s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-e2e-interpreter-toolchain-settings-bazel-9 [test] · ⏱ 41.6s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-e2e-rules-proto-grpc-python-bazel-8 [test] · ⏱ 1m 33s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-e2e-rules-proto-grpc-python-bazel-9 [test] · ⏱ 2m 14s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-e2e-rules-python-interop-bazel-8 [test] · ⏱ 54.5s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (15/15 passed)
  • ✅ test-e2e-rules-python-interop-bazel-9 [test] · ⏱ 55.9s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (15/15 passed)
  • ✅ test-e2e-rules-python-provider-compat-bazel-8 [test] · ⏱ 34.5s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (4/4 passed)
  • ✅ test-e2e-rules-python-provider-compat-bazel-9 [test] · ⏱ 54.7s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (4/4 passed)
  • ✅ test-examples-debugger-bazel-8 [test] · ⏱ 26s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-examples-debugger-bazel-9 [test] · ⏱ 38s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-examples-dev_deps-bazel-8 [test] · ⏱ 28.9s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-examples-dev_deps-bazel-9 [test] · ⏱ 52.6s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-examples-django-bazel-8 [test] · ⏱ 23.3s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed · 1 cached)
  • ✅ test-examples-django-bazel-9 [test] · ⏱ 51.1s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed · 1 cached)
  • ✅ test-examples-multi_version-bazel-8 [test] · ⏱ 26.4s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (2/2 passed)
  • ✅ test-examples-multi_version-bazel-9 [test] · ⏱ 1m 2s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (2/2 passed)
  • ✅ test-examples-protobuf-bazel-8 [test] · ⏱ 1m 39s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-examples-protobuf-bazel-9 [test] · ⏱ 1m 39s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-examples-py_binary-bazel-8 [test] · ⏱ 18.4s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed · 1 cached)
  • ✅ test-examples-py_binary-bazel-9 [test] · ⏱ 1m · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed · 1 cached)
  • ✅ test-examples-py_pex_binary-bazel-8 [test] · ⏱ 21.1s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed · 1 cached)
  • ✅ test-examples-py_pex_binary-bazel-9 [test] · ⏱ 53.7s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed · 1 cached)
  • ✅ test-examples-py_venv-bazel-8 [test] · ⏱ 25.7s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (3/3 passed · 3 cached)
  • ✅ test-examples-py_venv-bazel-9 [test] · ⏱ 47.5s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (3/3 passed)
  • ✅ test-examples-pytest-bazel-8 [test] · ⏱ 43.6s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (11/11 passed)
  • ✅ test-examples-pytest-bazel-9 [test] · ⏱ 1m 7s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (11/11 passed)
  • ✅ test-examples-uv_pip_compile-bazel-8 [test] · ⏱ 23s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-examples-uv_pip_compile-bazel-9 [test] · ⏱ 54.6s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-examples-virtual_deps-bazel-8 [test] · ⏱ 20.3s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-examples-virtual_deps-bazel-9 [test] · ⏱ 28.8s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test-root-bazel-8 [test] · ⏱ 3m 7s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (312/312 passed)
  • ✅ test-root-bazel-9 [test] · ⏱ 2m 39s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (311/311 passed)

⏱ Last updated Fri Aug 28 02:50:44 UTC 2026 · 📊 GitHub API quota 1,152/15,000 (8% used, resets in 40m)
🚀 Powered by Aspect CLI (v2026.28.2)  |  Aspect Build · X · LinkedIn · YouTube

@github-actions

Copy link
Copy Markdown

py_binary startup benchmark

Version Mean (ms) Median (ms) ± stddev vs BCR vs main Build (s)
BCR 1.11.7 (baseline) 160.649 160.735 ±1.635 1.61
HEAD main 56.854 56.622 ±1.585 -64.8% 1.76
This PR 56.325 56.232 ±0.773 -65.0% -0.7% 1.53

Measured with hyperfine --warmup 5 --runs 50 --shell=none on Linux
Gate: PR vs HEAD main median (threshold: 10%, and must exceed the 2×SE noise floor, here 0.9%). BCR is shown only as a historical baseline.
Build time: cold bazel build //:bench with isolated output base, no disk cache; external repos prefetched so network is excluded.

sys.path quality

Version sys.path entries distinct site-packages roots duplicate realpaths
BCR 1.11.7 (baseline) 6 1 0
HEAD main 7 2 0
This PR 7 2 0

sys.path quality measured by bench_syspath inside the assembled venv. Duplicate realpaths indicate symlink redundancy; many distinct site-packages roots suggest an inefficient venv layout.

Bazel analysis benchmark

Version Mean (ms) Median (ms) ± stddev vs BCR vs main Targets Actions
BCR 2.0.0-alpha.6 (baseline) 1156.913 1123.924 ±165.282 304 13746
HEAD main 1162.719 1073.843 ±199.579 -4.5% 304 13546
This PR 1167.795 1134.669 ±189.931 +1.0% +5.7% 304 13546

Measured with hyperfine --warmup 1 --runs 10 on Linux
Gate: PR vs HEAD main median (threshold: 10%, and must exceed the 2×SE noise floor, here 16.2%). BCR is shown only as a historical baseline.
Command: warm-server bazel build --nobuild //workspace/..., analysis cache discarded each run via a fresh --action_env value; no disk cache.

py_image_layer benchmark

Scenario Version Mean (s) Median (s) ± stddev Actions vs BCR vs main
Analysis BCR 2.0.0-alpha.6 (baseline) 0.71 0.64 ±0.14 747
Analysis HEAD main 0.69 0.65 ±0.14 726 +1.8%
Analysis This PR 0.67 0.61 ±0.14 726 -4.6% -6.4%
1p Source Change BCR 2.0.0-alpha.6 (baseline) 0.71 0.71 ±0.05 4
1p Source Change HEAD main 0.75 0.72 ±0.08 5 +1.9%
1p Source Change This PR 0.71 0.70 ±0.04 5 -1.9% -3.7%
3p Source Change BCR 2.0.0-alpha.6 (baseline) 0.86 0.85 ±0.04 5
3p Source Change HEAD main 0.90 0.89 ±0.02 6 +4.8%
3p Source Change This PR 0.90 0.90 ±0.03 6 +5.4% +0.6%

Measured with hyperfine on Linux, building //workspace:image_layers (10 binaries, ~30-wheel dep pool, grouped first-party/pip/interpreter tier) with isolated output base, no disk cache.
Scenarios: analysis = warm-server bazel build --nobuild, re-analyzed each run via a fresh --action_env value; incrementals run against a built state with warm analysis: source = append to the last package's lib.py, wheel = rewrite click post_install_patches content.
Actions: for Analysis, the total action count behind the image target from aquery deps(...); for incrementals, actions re-executed for the mutation, from a single instrumented run's BEP build metrics (deterministic; per-mnemonic breakdown in the *-actions.json artifacts). Informational only, not gated.
Gate: PR vs HEAD main median per scenario (threshold: 10%, and must exceed the 2×SE noise floor). BCR is shown only as a historical baseline.

@xangcastle

Copy link
Copy Markdown
Member Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 301cd977b3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@xangcastle
xangcastle marked this pull request as ready for review August 28, 2026 02:54
@xangcastle
xangcastle requested a review from jbedard August 28, 2026 02:55
@xangcastle
xangcastle enabled auto-merge (squash) August 28, 2026 02:57
package(default_visibility = ["//uv/private:__subpackages__"])

exports_files([
"defs.tmpl",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think these should be named *.tmpl.{bazel,bzl} so we actually know what type of file they are, and an IDE will render them correctly etc

@xangcastle xangcastle Aug 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

if I add .bzl at the end, gazelle will try to generate bzl_libraries

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could tell gazelle to ignore *.tmpl.* maybe?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ok, let me try

@xangcastle
xangcastle requested a review from jbedard August 28, 2026 12:36
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