From 5bb843c7bf04946d56b72a90dc0ed5f3f06159b4 Mon Sep 17 00:00:00 2001 From: Tom Durrant Date: Fri, 5 Sep 2025 11:27:18 +1000 Subject: [PATCH 1/4] Switch from black to ruff --- .../.github/workflows/testing.yml | 12 ++++++------ .../.pre-commit-config.yaml | 9 +++++---- {{cookiecutter.project_name}}/README.rst | 15 ++++++++++++--- {{cookiecutter.project_name}}/pyproject.toml | 14 ++++++++++++-- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/{{cookiecutter.project_name}}/.github/workflows/testing.yml b/{{cookiecutter.project_name}}/.github/workflows/testing.yml index 162089e..668abb6 100644 --- a/{{cookiecutter.project_name}}/.github/workflows/testing.yml +++ b/{{cookiecutter.project_name}}/.github/workflows/testing.yml @@ -20,15 +20,15 @@ jobs: name: Install dependencies run: | python -m pip install --upgrade pip build - pip install .[dev] + pip install .[test] - name: Run tests run: pytest -s -v tests - - - name: Run linting - run: | - pip install ruff - ruff check . + # - + # name: Run linting + # run: | + # pip install ruff + # ruff check . - name: Build package run: python -m build diff --git a/{{cookiecutter.project_name}}/.pre-commit-config.yaml b/{{cookiecutter.project_name}}/.pre-commit-config.yaml index c9d352f..47cfa48 100644 --- a/{{cookiecutter.project_name}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_name}}/.pre-commit-config.yaml @@ -1,7 +1,8 @@ repos: - - repo: https://github.com/psf/black - rev: 24.4.2 # Use the latest stable version + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.12.12 # Use the latest stable version hooks: - - id: black - language_version: python3 + - id: ruff-check + args: [--fix] + - id: ruff-format args: [--check] diff --git a/{{cookiecutter.project_name}}/README.rst b/{{cookiecutter.project_name}}/README.rst index c716141..aa78f27 100644 --- a/{{cookiecutter.project_name}}/README.rst +++ b/{{cookiecutter.project_name}}/README.rst @@ -39,18 +39,27 @@ Features Code Formatting and Pre-commit Hooks ------------------------------------ -This repository enforces Python code formatting using [black](https://github.com/psf/black) via the pre-commit framework. +This repository enforces Python code formatting and linting using [Ruff](https://docs.astral.sh/ruff/) via the pre-commit framework. To set up pre-commit hooks locally (required for all contributors):: pip install pre-commit pre-commit install -This will automatically check code formatting before each commit. To format your code manually, run:: +This will automatically check code formatting and linting before each commit. To format your code manually, run:: + + ruff format . + +To check formatting and linting without making changes, run:: + + ruff check . + ruff format --check . + +Or to run all pre-commit hooks manually:: pre-commit run --all-files -All code must pass black formatting before it can be committed or merged. +All code must pass Ruff formatting and linting before it can be committed or merged. Versioning and Release ---------------------- diff --git a/{{cookiecutter.project_name}}/pyproject.toml b/{{cookiecutter.project_name}}/pyproject.toml index 0f2064e..a66a780 100644 --- a/{{cookiecutter.project_name}}/pyproject.toml +++ b/{{cookiecutter.project_name}}/pyproject.toml @@ -30,8 +30,7 @@ dev = [ "coverage", "mypy", "pytest", - "ruff" - "black" + "ruff", "requests" ] docs = [ @@ -66,3 +65,14 @@ package-dir = {"" = "src"} [tool.setuptools.dynamic] version = {attr = "{{cookiecutter.project_slug}}.__version__"} + +[tool.ruff] +line-length = 88 +indent-width = 4 + +[tool.ruff.format] +quote-style = "double" +indent-style = "space" +skip-magic-trailing-comma = false +line-ending = "auto" +docstring-code-format = false From c4e900538cb8ce61f3d509b80a2fbbe560e6929e Mon Sep 17 00:00:00 2001 From: Tom Durrant Date: Fri, 5 Sep 2025 11:29:58 +1000 Subject: [PATCH 2/4] Update {{cookiecutter.project_name}}/pyproject.toml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- {{cookiecutter.project_name}}/pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/{{cookiecutter.project_name}}/pyproject.toml b/{{cookiecutter.project_name}}/pyproject.toml index a66a780..615ad08 100644 --- a/{{cookiecutter.project_name}}/pyproject.toml +++ b/{{cookiecutter.project_name}}/pyproject.toml @@ -30,8 +30,7 @@ dev = [ "coverage", "mypy", "pytest", - "ruff", - "requests" + "requests", ] docs = [ "autodoc_pydantic", From ef49a8acf897db212dd38760dd70689d995fa403 Mon Sep 17 00:00:00 2001 From: Tom Durrant Date: Fri, 5 Sep 2025 11:30:14 +1000 Subject: [PATCH 3/4] Update {{cookiecutter.project_name}}/.github/workflows/testing.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- {{cookiecutter.project_name}}/.github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_name}}/.github/workflows/testing.yml b/{{cookiecutter.project_name}}/.github/workflows/testing.yml index 668abb6..27dac33 100644 --- a/{{cookiecutter.project_name}}/.github/workflows/testing.yml +++ b/{{cookiecutter.project_name}}/.github/workflows/testing.yml @@ -20,7 +20,7 @@ jobs: name: Install dependencies run: | python -m pip install --upgrade pip build - pip install .[test] + pip install .[dev] - name: Run tests run: pytest -s -v tests From 115795aec9691a53fbd91e4590fdd7d46c222645 Mon Sep 17 00:00:00 2001 From: Tom Durrant Date: Fri, 5 Sep 2025 11:30:48 +1000 Subject: [PATCH 4/4] Update {{cookiecutter.project_name}}/.pre-commit-config.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- {{cookiecutter.project_name}}/.pre-commit-config.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/{{cookiecutter.project_name}}/.pre-commit-config.yaml b/{{cookiecutter.project_name}}/.pre-commit-config.yaml index 47cfa48..c62ed2c 100644 --- a/{{cookiecutter.project_name}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_name}}/.pre-commit-config.yaml @@ -4,5 +4,3 @@ repos: hooks: - id: ruff-check args: [--fix] - - id: ruff-format - args: [--check]