Sync blacken-docs additional_dependencies from uv.lock#40
Merged
Conversation
Add a `_sync-blacken-docs` just recipe that reads the `black` version from `uv.lock` and rewrites `blacken-docs`' `additional_dependencies` in-place, preserving file formatting. Wire it into `deps-update` before the existing `sync-pre-commit-deps` step (kept as a safety net for other hooks that may have `additional_dependencies`). Replace the literal `black==26.5.1` pin in the template's `.pre-commit-config.yaml.jinja` with a `<placeholder_until_update_deps>` marker, consistent with the rev placeholders used elsewhere; the new recipe resolves it on first `deps-update`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
_sync-blacken-docsawk/sed pipeline hard-codes assumptions aboutuv.lockand.pre-commit-config.yamlformatting (TOML layout, hook order, indentation, and range/id: blacken-docs/,/^ - repo:/), which may be brittle over time; consider replacing it with a small script that parses TOML/YAML structurally (e.g., via Pythontomllib/ruamel.yaml) instead of text-range substitutions. - The in-place
sed -i -Eedit may behave differently on macOS/BSD vs GNU sed; if this template is expected to run in non-Linux environments, it would be safer to either use a portable form (sed -i ''on macOS or a wrapper) or route the replacement through a cross-platform tool.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `_sync-blacken-docs` awk/sed pipeline hard-codes assumptions about `uv.lock` and `.pre-commit-config.yaml` formatting (TOML layout, hook order, indentation, and range `/id: blacken-docs/,/^ - repo:/`), which may be brittle over time; consider replacing it with a small script that parses TOML/YAML structurally (e.g., via Python `tomllib`/`ruamel.yaml`) instead of text-range substitutions.
- The in-place `sed -i -E` edit may behave differently on macOS/BSD vs GNU sed; if this template is expected to run in non-Linux environments, it would be safer to either use a portable form (`sed -i ''` on macOS or a wrapper) or route the replacement through a cross-platform tool.
## Individual Comments
### Comment 1
<location path="project_name/justfile.jinja" line_range="56" />
<code_context>
+_sync-blacken-docs:
+ @black_ver=$(awk -F'"' '/^\[\[package\]\]/{p=0} /^name = "black"$/{p=1} p && /^version =/{print $2; exit}' uv.lock); \
+ if [ -n "$black_ver" ] && grep -q 'id: blacken-docs' .pre-commit-config.yaml; then \
+ sed -i -E "/id: blacken-docs/,/^ - repo:/ s/(black==)(<[^>]*>|[0-9][0-9a-z.+-]*)/\1$black_ver/" .pre-commit-config.yaml; \
+ fi
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider sed portability and narrowing the replacement range
1. `sed -i` without a suffix only works on GNU sed; on macOS/BSD you must pass an argument (e.g. `-i ''` or `-i.bak`). If this justfile is intended to be portable, consider a pattern like `sed -i.bak -E ... && rm .pre-commit-config.yaml.bak`.
2. The range `/id: blacken-docs/,/^ - repo:/` will rewrite every `black==...` between those lines. If any other occurrence appears in that span (comments, extra hooks, etc.), it will also be changed. You could instead limit the range (e.g. `/id: blacken-docs/,/additional_dependencies/`) or use a more specific match targeting only the intended `black==` line.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| _sync-blacken-docs: | ||
| @black_ver=$(awk -F'"' '/^\[\[package\]\]/{p=0} /^name = "black"$/{p=1} p && /^version =/{print $2; exit}' uv.lock); \ | ||
| if [ -n "$black_ver" ] && grep -q 'id: blacken-docs' .pre-commit-config.yaml; then \ | ||
| sed -i -E "/id: blacken-docs/,/^ - repo:/ s/(black==)(<[^>]*>|[0-9][0-9a-z.+-]*)/\1$black_ver/" .pre-commit-config.yaml; \ |
There was a problem hiding this comment.
suggestion (bug_risk): Consider sed portability and narrowing the replacement range
sed -iwithout a suffix only works on GNU sed; on macOS/BSD you must pass an argument (e.g.-i ''or-i.bak). If this justfile is intended to be portable, consider a pattern likesed -i.bak -E ... && rm .pre-commit-config.yaml.bak.- The range
/id: blacken-docs/,/^ - repo:/will rewrite everyblack==...between those lines. If any other occurrence appears in that span (comments, extra hooks, etc.), it will also be changed. You could instead limit the range (e.g./id: blacken-docs/,/additional_dependencies/) or use a more specific match targeting only the intendedblack==line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_sync-blacken-docsjust recipe that reads theblackversion fromuv.lockand rewritesblacken-docs'additional_dependenciesin-place in.pre-commit-config.yaml, preserving file formatting (unlikesync-pre-commit-deps, which reformats).deps-updatebefore the existingsync-pre-commit-depsstep. The latter is kept as a safety net for any other hooks that may carryadditional_dependenciesin the future.black==26.5.1pin inproject_name/.pre-commit-config.yaml.jinjawithblack==<placeholder_until_update_deps>, matching the convention used for allrev:fields. The new recipe resolves it on firstdeps-update.Test plan
just test(ctt snapshot regeneration) passes locallyformat_tool=blackand confirmdeps-updatepopulatesadditional_dependenciesto the same version as thepsf/black-pre-commit-mirrorrevformat_tool=ruffand confirmdeps-updatestill resolves the placeholder (viasync-pre-commit-depsfallback, sinceblackmay not be inuv.lock).pre-commit-config.yamlis not reformatted on the happy path (no spurious whitespace diff)🤖 Generated with Claude Code