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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Sensible defaults for all included tools are provided.
- Performance benchmarking with [pytest-benchmark](https://pytest-benchmark.readthedocs.io/)
- Additional pytest plugins for a better testing experience
- Code formatting with [Black](https://black.readthedocs.io/) or [Ruff formatter](https://docs.astral.sh/ruff/formatter/)
- Documentation formatting with [blacken-docs](https://github.com/adamchainz/blacken-docs/)
- Documentation formatting with [blacken-docs](https://github.com/adamchainz/blacken-docs/) (Black) or [Ruff formatter](https://docs.astral.sh/ruff/formatter/#markdown-code-formatting) (Ruff)
- Comprehensive linting with [Ruff](https://docs.astral.sh/ruff/)
- Replaces Flake8, isort, pyupgrade, yesqa, pycln, and dozens of plugins
- Static type checking with [MyPy](https://mypy-lang.org/)
Expand Down
3 changes: 2 additions & 1 deletion ctt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ _post_tasks = [
--from git+https://github.com/scientific-python/cookie \
--with repo-review[cli] \
sp-repo-review . \
--ignore PY007,RTD,PC191 \
--ignore PY007,RTD,PC111,PC191 \
--show errskip\
""",
# PY007 : Supports an easy task runner (nox, tox, pixi, etc.) : we use just
"[ -f justfile ]",
# RTD : ReadTheDocs : checked in the docs section
# PC111 : Uses blacken-docs : only used in the black variant; ruff format handles md code blocks
# PC191 : Ruff show fixes if fixes enabled : false-positive on ruff-isort

# show outdated deps
Expand Down
10 changes: 3 additions & 7 deletions project_name/.pre-commit-config.yaml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,17 @@ repos:
- id: doc8

# Python files
{%- if format_tool == "black" %}
- repo: https://github.com/psf/black-pre-commit-mirror
rev: <placeholder_until_update_deps>
hooks:
{%- if format_tool == "black" %}
- id: black{% if contains_jupyter_files %}-jupyter{% endif %}
{%- endif %}
{%- if format_tool != "black" or contains_jupyter_files %}
# used to keep the blacken-docs in sync
- id: black
stages: [manual]
{%- endif %}
- repo: https://github.com/adamchainz/blacken-docs
rev: <placeholder_until_update_deps>
hooks:
- id: blacken-docs
additional_dependencies: [black==<placeholder_until_update_deps>]
{%- endif %}
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: <placeholder_until_update_deps>
hooks:
Expand All @@ -166,6 +161,7 @@ repos:
args: [--select, I001, --fix]
{%- if format_tool == "ruff" %}
- id: ruff-format
types_or: [python, pyi, jupyter, markdown]
{%- endif %}
- id: ruff-check
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
2 changes: 1 addition & 1 deletion project_name/CONTRIBUTING.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Ready to get started? Follow the development setup below.
You can run specific tools directly:

```bash
{% if format_tool == "black" %}uv run black{% endif %}
{% if format_tool == "black" %}uv run black{% elif format_tool == "ruff" %}uv run ruff format{% endif %}
uv run ruff check
uv run mypy
uv run pytest
Expand Down
7 changes: 5 additions & 2 deletions project_name/justfile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ deps-update: && deps-list-outdated
uv sync --upgrade
uv run prek auto-update
uvx sync-with-uv
{%- if format_tool == "black" %}
just _sync-blacken-docs
{%- endif %}
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,13 +50,14 @@ deps-update: && deps-list-outdated
# Audit dependencies
deps-audit:
uv audit --locked

{% if format_tool == "black" %}
# 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; \
fi
{%- endif %}


### code quality ###
Expand Down Expand Up @@ -84,10 +87,10 @@ format:
uv run ruff check --select I001 --fix
{%- if format_tool == "black" %}
uv run black .
uv run prek run --all-files blacken-docs
{%- elif format_tool == "ruff" %}
uv run ruff format
{%- endif %}
uv run prek run --all-files blacken-docs
uv run prek run --all-files mdformat
{%- if jupyter_files == "strip_outputs" %}
uv run prek run --all-files nbstripout
Expand Down
11 changes: 11 additions & 0 deletions project_name/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ dev = [
## used in the justfile
"rust-just ~=1.0",
"prek ~=0.4.0",
{%- if format_tool == "black" %}
"black{% if contains_jupyter_files %}[jupyter]{% endif %} ~=26.1",
{%- endif %}
"ruff ~=0.15.0",
## can be used for debug
"icecream >=2",
Expand Down Expand Up @@ -216,9 +218,18 @@ enable_error_code = [
DEP002 = [
]

{% if format_tool == "ruff" %}
[tool.ruff]
# discover Markdown files so `ruff format` can format their code blocks
extend-include = ["*.md"]

{% endif %}
[tool.ruff.format]
docstring-code-format = true
{%- if format_tool == "ruff" %}
# enable preview mode to format code blocks inside Markdown files
preview = true
{%- endif %}


[tool.ruff.lint]
Expand Down
Loading