Skip to content

Sync blacken-docs additional_dependencies from uv.lock#40

Merged
tsvikas merged 1 commit into
mainfrom
feat/sync-blacken-docs-deps
May 25, 2026
Merged

Sync blacken-docs additional_dependencies from uv.lock#40
tsvikas merged 1 commit into
mainfrom
feat/sync-blacken-docs-deps

Conversation

@tsvikas
Copy link
Copy Markdown
Owner

@tsvikas tsvikas commented May 25, 2026

Summary

  • Add a _sync-blacken-docs just recipe that reads the black version from uv.lock and rewrites blacken-docs' additional_dependencies in-place in .pre-commit-config.yaml, preserving file formatting (unlike sync-pre-commit-deps, which reformats).
  • Wire it into deps-update before the existing sync-pre-commit-deps step. The latter is kept as a safety net for any other hooks that may carry additional_dependencies in the future.
  • Replace the literal black==26.5.1 pin in project_name/.pre-commit-config.yaml.jinja with black==<placeholder_until_update_deps>, matching the convention used for all rev: fields. The new recipe resolves it on first deps-update.

Test plan

  • just test (ctt snapshot regeneration) passes locally
  • Render the template with format_tool=black and confirm deps-update populates additional_dependencies to the same version as the psf/black-pre-commit-mirror rev
  • Render the template with format_tool=ruff and confirm deps-update still resolves the placeholder (via sync-pre-commit-deps fallback, since black may not be in uv.lock)
  • Confirm .pre-commit-config.yaml is not reformatted on the happy path (no spurious whitespace diff)

🤖 Generated with Claude Code

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>
@tsvikas tsvikas merged commit 3efc8e8 into main May 25, 2026
5 checks passed
@tsvikas tsvikas deleted the feat/sync-blacken-docs-deps branch May 25, 2026 20:41
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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; \
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

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