Repository navigation
fix(python-precommit): detect repo state instead of hardcoding uv sync --frozen - #164
Conversation
|
Warning Review limit reached
More reviews will be available in 46 minutes and 47 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe workflow now branches based on detected repository state: it checks for ChangesRepository State-Aware Pre-Commit Workflow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
Updates the reusable python-precommit.yml workflow to detect the caller repository state (no pyproject.toml, Poetry, uv with uv.lock, uv without uv.lock) and then conditionally install dependencies and run pre-commit in a way that avoids hardcoded uv sync --frozen failures across downstream repos.
Changes:
- Added a
Detect repo statestep that classifies the repo asskip,poetry-not-supported,uv-locked, oruv-no-lock. - Split dependency installation into two guarded
uv syncsteps (locked vs no-lock) and added a skip notice for repos withoutpyproject.toml. - Guarded the
Run pre-commit hooksstep to only run for uv repos, and used literal--frozenwith NOSONAR annotations for--no-build.
| - name: Skip notice (no pyproject.toml) | ||
| if: steps.detect.outputs.state == 'skip' | ||
| run: | | ||
| echo "## Pre-Commit Skipped" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "No pyproject.toml at repo root, nothing to run pre-commit against." >> $GITHUB_STEP_SUMMARY |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/python-precommit.yml:
- Around line 115-120: The final summary step that uses "if: always()" can
produce contradictory messaging when the earlier "Skip notice (no
pyproject.toml)" branch set steps.detect.outputs.state == 'skip'; update the
final summary step in .github/workflows/python-precommit.yml to be skip-aware by
gating it on a condition like "if: steps.detect.outputs.state != 'skip' &&
always()" or by reading steps.detect.outputs.state and outputting a skip-aware
message (i.e., check steps.detect.outputs.state and either print pass/fail or a
single "Pre-Commit Skipped" summary), referencing the existing conditional
output steps.detect.outputs.state and the summary step currently using "if:
always()".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f404881b-7627-495a-bf01-8bf16dada58e
📒 Files selected for processing (1)
.github/workflows/python-precommit.yml
… --frozen Apply established NOSONAR detect-state pattern (see python-mutation.yml:159-169 and merged PRs #155-#160, #164-#166). Branches on pyproject.toml + lockfile presence: skip when no pyproject, fail fast on poetry repos with actionable error, use --frozen on uv-locked repos, drop --frozen on uv-no-lock repos. Apply Wave 1C strengthened pattern (docs/sonarcloud-nosonar-patterns.md strengthened 2026-05-26): only single-line run: shape reliably honors NOSONAR. Split install into two if:-guarded steps with literal flags and inline Pattern A NOSONAR. Collapse Check docstring coverage and Build MkDocs site multi-line run: | blocks to single-line run: so SonarCloud can pattern-match Pattern A. S8541 suppression is acceptable here: the \$NO_BUILD_FLAG env var is dynamic by design (consumers with PEP 517 build backends like hatchling can pass no-build: false). Step-level branching would just shuffle the finding.
… --frozen (#171) * fix(python-docs): detect repo state instead of hardcoding uv sync/run --frozen Apply established NOSONAR detect-state pattern (see python-mutation.yml:159-169 and merged PRs #155-#160, #164-#166). Branches on pyproject.toml + lockfile presence: skip when no pyproject, fail fast on poetry repos with actionable error, use --frozen on uv-locked repos, drop --frozen on uv-no-lock repos. Apply Wave 1C strengthened pattern (docs/sonarcloud-nosonar-patterns.md strengthened 2026-05-26): only single-line run: shape reliably honors NOSONAR. Split install into two if:-guarded steps with literal flags and inline Pattern A NOSONAR. Collapse Check docstring coverage and Build MkDocs site multi-line run: | blocks to single-line run: so SonarCloud can pattern-match Pattern A. S8541 suppression is acceptable here: the \$NO_BUILD_FLAG env var is dynamic by design (consumers with PEP 517 build backends like hatchling can pass no-build: false). Step-level branching would just shuffle the finding. * fix(python-docs): gate deploy on build state to avoid download-artifact failure Expose steps.detect.outputs.state as a build job-level output and require needs.build.outputs.state != 'skip' in the deploy job if: clause. Without this, the build job succeeded in skip mode (only the skip-notice step ran; the upload-artifact step was already conditionally skipped) and needs: build falsely cleared deploy to run, where actions/download-artifact then failed with "artifact not found" against the never-uploaded documentation-site. Add CHANGELOG entry under [Unreleased] / Fixed. Addresses Copilot inline review on PR #171. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
PR ReviewStatus: CI green (19/19), SonarCloud QG passed, MergeState Important (should fix)
Suggested
Positive notes
Recommended action
Generated with Claude Code |
…c --frozen Apply the split-install detect-state pattern (see python-mutation.yml:159-169 for the original NOSONAR S8541 precedent, and PR #160 / python-release.yml for the canonical split-install exemplar). Branches on pyproject.toml + lockfile presence: skip when no pyproject, fail fast on poetry repos with actionable error, install with literal --frozen on uv-locked path, install without --frozen on uv-no-lock path (uv sync generates the lockfile). Downstream pre-commit run step uses literal --frozen because the install step guaranteed uv.lock exists by then; preceding-line NOSONAR(S8541) is honored when the underlying line has a literal --frozen token (only the --no-build flag remains dynamic). Avoids the documented anti-pattern: dynamic \$FROZEN_FLAG inside run: | block scalars is not suppressed by preceding-line NOSONAR (empirical finding from PRs #157/#158/#159; see BWCPA/.github docs/sonarcloud-nosonar-patterns.md). Verification: actionlint passes (with -shellcheck= per documented embedded-shellcheck limitation in feedback_actionlint_shellcheck_embed).
When the detect step sets state=skip (no pyproject.toml), the workflow should not emit the generic "All pre-commit hooks passed" summary; the "Skip notice" step already provides the correct user-facing message and the success line is misleading because nothing ran. Gate the Pre-Commit Summary step on state != 'skip' so skipped runs render only the skip notice. Behavior on uv-locked, uv-no-lock, and poetry-not-supported paths is unchanged. Flagged independently by Copilot and CodeRabbit on PR #164 review. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
f176855 to
a4bdac7
Compare
PR Fix SummaryAddressed the Important finding from Branch rebased onto Fix applied in commit - name: Pre-Commit Summary
- if: always()
+ if: always() && steps.detect.outputs.state != 'skip'Why: When the detect step sets Replies to bot threads:
Verification:
Suggested-tier items (not blocking; deferred unless requested):
Generated with Claude Code |
|
Tip For best results, initiate chat on the files or code changes.
🐇 ✨ If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
|



Summary
python-precommit.yml(matches merged PRs fix(python-compatibility): detect repo state instead of hardcoding uv sync --frozen #156, fix(python-ci): detect repo state instead of hardcoding uv sync/run --frozen #159, fix(python-release): detect repo state instead of hardcoding uv sync/run --frozen #160).Detect repo statestep (skip / poetry-not-supported / uv-locked / uv-no-lock).Install dependenciesinto twoif:-guarded steps with literal flags (avoids the dynamic-$FROZEN_FLAG-inside-run: |anti-pattern empirically found broken in PRs fix(python-fips): detect repo state instead of hardcoding uv sync/run --frozen #157/fix(python-security-analysis): detect repo state instead of hardcoding uv sync/run --frozen #158/fix(python-ci): detect repo state instead of hardcoding uv sync/run --frozen #159).Run pre-commit hooksstep uses literal--frozen(install step guaranteesuv.lockexists) with preceding-line# NOSONAR(S8541)for--no-buildonly.python-mutation.yml:159-169.Pattern choices
# NOSONAR(S8541)(literal--frozenmakes S8544 inapplicable).# NOSONAR(S8541,S8544)(no--frozenby design).# NOSONAR(S8541)insiderun: |block, two branches both with literal--frozen).Affected downstream repos
Per
/tmp/ci-failure-inventory.tsv: pre-commit runs on most uv repos; not specifically tracked on the inventory but exercised by every uv-managed downstream caller.Test plan
actionlint -shellcheck= .github/workflows/python-precommit.ymlpasses (zero errors; embedded shellcheck-shellcheck=flag perfeedback_actionlint_shellcheck_embed)..githubpasses.Summary by CodeRabbit