Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project_name/.pre-commit-config.yaml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ repos:
rev: <placeholder_until_update_deps>
hooks:
- id: blacken-docs
additional_dependencies: [black==26.5.1]
additional_dependencies: [black==<placeholder_until_update_deps>]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: <placeholder_until_update_deps>
hooks:
Expand Down
8 changes: 8 additions & 0 deletions project_name/justfile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ deps-update: && deps-list-outdated
uv sync --upgrade
uv run prek auto-update
uvx sync-with-uv
just _sync-blacken-docs
uvx sync-pre-commit-deps --yaml-mapping 2 --yaml-sequence 4 --yaml-offset 2 .pre-commit-config.yaml || { \
echo "Note: '.pre-commit-config.yaml' changed, and might lost its formatting." \
&& exit 1; \
Expand All @@ -48,6 +49,13 @@ deps-update: && deps-list-outdated
deps-audit:
uv audit --locked

# Sync blacken-docs' black additional_dependency with the version in uv.lock
_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.

fi


### code quality ###
_assert_clean_repo:
Expand Down
Loading