Skip to content

Prescribe the uv --script shebang and test it - #38

Merged
leynos merged 1 commit into
mainfrom
fix-uv-script-shebang
Jul 18, 2026
Merged

Prescribe the uv --script shebang and test it#38
leynos merged 1 commit into
mainfrom
fix-uv-script-shebang

Conversation

@leynos

@leynos leynos commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • #!/usr/bin/env -S uv run python executes the interpreter directly and
    ignores the PEP 723 inline metadata block, so a directly invoked script
    fails at import time because its declared dependencies were never
    installed. Verified empirically: a script with dependencies = ["cyclopts>=2.9"] fails at import cyclopts under the old form and
    succeeds under -S uv run --script.
  • Fixed the three occurrences of the broken shebang heading a PEP 723 script
    block: scripts/generate_typos_config.py, its template copy
    template/scripts/generate_typos_config.py, and the
    worked example in template/docs/scripting-standards.md.
    Added a short rationale to the standards doc explaining why --script is
    required.
  • Added tests/test_scripting_shebang.py with two tests:
    a static guard asserting no file in the repository or Copier template tree
    ships the broken shebang above a PEP 723 block, and a behavioural test that
    writes a temporary script with the correct shebang and a one-dependency
    PEP 723 block, executes it directly, and asserts the dependency imports and
    the process exits 0. The behavioural test skips gracefully when uv is
    unavailable.

Test plan

  • make check-fmt — passed
  • make lint — passed (Ruff and Interrogate)
  • make typecheck — passed
  • make spelling — passed
  • make test — 46 passed, 2 skipped, 1 known pre-existing failure
    (tests/test_typos_rollout.py::test_committed_config_matches_current_shared_dictionary,
    caused by upstream shared-dictionary drift unrelated to this change)

@leynos
leynos enabled auto-merge (squash) July 18, 2026 11:04

@sourcery-ai sourcery-ai Bot 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.

Sorry @leynos, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 57 minutes

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9bc2d0fe-2d00-40b4-bdcc-2f404e45f5b8

📥 Commits

Reviewing files that changed from the base of the PR and between ee517f4 and 8fd8bfb.

📒 Files selected for processing (4)
  • scripts/generate_typos_config.py
  • template/docs/scripting-standards.md
  • template/scripts/generate_typos_config.py
  • tests/test_scripting_shebang.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-uv-script-shebang

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

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fecccd8706

ℹ️ 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".

f"{CORRECT_SHEBANG}\n"
"# /// script\n"
'# requires-python = ">=3.13"\n'
'# dependencies = ["packaging"]\n'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid resolving PyPI during this unit test

In network-restricted CI or local runs where uv is installed but PyPI is unavailable, this test fails before it can validate the shebang: the temp script declares packaging, so uv run --script has to resolve the package from the default PyPI index at execution time. I reproduced python -m pytest tests/test_scripting_shebang.py -q failing with Failed to fetch: https://pypi.org/simple/packaging/; use a local path dependency or skip when dependency resolution cannot run rather than making the parent test suite depend on live PyPI.

Useful? React with 👍 / 👎.

The scripting standards document and the two generate_typos_config.py
scripts (root and template copies) shebanged their PEP 723 script blocks
with `#!/usr/bin/env -S uv run python`. That form executes the interpreter
directly and silently ignores the inline metadata block, so a directly
invoked script fails at import time because its declared dependencies were
never installed. `#!/usr/bin/env -S uv run --script` reads the metadata
block and installs the dependencies first, which is what every PEP 723
script actually needs.

Fix all three occurrences and add a documented rationale to the scripting
standards guide. Add tests/test_scripting_shebang.py, which asserts no file
in the repository or template tree ships the broken shebang above a PEP 723
block, and behaviourally proves the correct shebang installs and imports a
declared dependency when the script is executed directly.
@leynos
leynos force-pushed the fix-uv-script-shebang branch from fecccd8 to 8fd8bfb Compare July 18, 2026 11:55
@leynos
leynos merged commit bb030cf into main Jul 18, 2026
6 checks passed
@leynos
leynos deleted the fix-uv-script-shebang branch July 18, 2026 12:15
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.

1 participant