From 266131f9c7f0cb5c3852621cd628d79580c95925 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 29 May 2026 20:12:22 +0000 Subject: [PATCH] Upgrade template: ruff format replaces black, ty replaces mypy, uv in CI, Python 3.10-3.13 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove black from template deps/config/CI; ruff format now handles formatting - Migrate ruff config to modern [tool.ruff.lint] sub-table (ruff 0.2+ format) - Add ty as type checker replacing mypy in dev deps and lint scripts - Add [ci] extras group (pytest + pytest-cov) for uv-based CI installs - Replace flake8/lintly linter.yml + process_linter_results.yml with ruff.yml - Remove black.yml; ruff.yml runs both format --check and ruff check - Switch all CI steps to use uv (astral-sh/setup-uv@v5 + uv pip install --system) - Update CI Python matrix: drop EOL 3.7/3.9, add 3.10/3.11/3.12/3.13 - Update minimum_python_version default in cookiecutter.json: 3.8 → 3.10 - Bump ruff pre-commit hook to v0.9.0 in both root and template configs - Update action versions: checkout@v4, setup-python@v5, upload-artifact@v4 https://claude.ai/code/session_01SQX4abPTTxWepri5fNA7qC --- .github/workflows/build.yml | 36 ++++++------- .pre-commit-config.yaml | 3 +- cookiecutter.json | 2 +- .../.github/workflows/black.yml | 16 ------ .../.github/workflows/linter.yml | 28 ---------- .../workflows/process_linter_results.yml | 54 ------------------- .../.github/workflows/ruff.yml | 20 +++++++ .../.github/workflows/test.yml | 27 +++++----- .../.pre-commit-config.yaml | 3 +- {{cookiecutter.project_slug}}/Makefile | 7 +-- {{cookiecutter.project_slug}}/pyproject.toml | 25 ++++----- 11 files changed, 68 insertions(+), 153 deletions(-) delete mode 100644 {{cookiecutter.project_slug}}/.github/workflows/black.yml delete mode 100644 {{cookiecutter.project_slug}}/.github/workflows/linter.yml delete mode 100644 {{cookiecutter.project_slug}}/.github/workflows/process_linter_results.yml create mode 100644 {{cookiecutter.project_slug}}/.github/workflows/ruff.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a968698..a38d1f0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,22 +9,16 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.12', '3.9', '3.10', '3.11'] + python-version: ['3.10', '3.11', '3.12', '3.13'] fail-fast: false - env: - # cache busting if requirements haven't changed - CACHE_EPOCH: 1 steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v5 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v6 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - name: Cache pip - uses: actions/cache@v5 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ matrix.python-version }} - name: Cache pre-commit uses: actions/cache@v5 with: @@ -32,7 +26,7 @@ jobs: key: ${{ runner.os }}-pre-commit-${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install cookiecutter build + uv pip install --system cookiecutter build git config --global user.email "you@example.com" git config --global user.name "Your Name" git config --global init.defaultBranch main @@ -42,27 +36,27 @@ jobs: GIT=$(which git) sudo chmod -x ${GIT} cookiecutter -v --no-input -f -o /tmp/cookie_python . project_slug=foo1-bar minimum_python_version=${{ matrix.python-version }} - python -m pip install /tmp/cookie_python/foo1-bar + uv pip install --system /tmp/cookie_python/foo1-bar python -c "import foo1_bar; print(foo1_bar.__version__)" - python -m pip uninstall -y foo1 + uv pip uninstall --system foo1-bar sudo chmod +x ${GIT} - name: with git only run: | cookiecutter -v --no-input -f -o /tmp/cookie_python . project_slug=foo2 minimum_python_version=${{ matrix.python-version }} - python -m pip install /tmp/cookie_python/foo2 - python -m pip uninstall -y foo2 + uv pip install --system /tmp/cookie_python/foo2 + uv pip uninstall --system foo2 - name: with git and pre-commit run: | - python -m pip install pre-commit + uv pip install --system pre-commit cookiecutter -v --no-input -f -o /tmp/cookie_python . project_slug=foo3 minimum_python_version=${{ matrix.python-version }} - python -m pip install /tmp/cookie_python/foo3 - python -m pip uninstall -y foo3 + uv pip install --system /tmp/cookie_python/foo3 + uv pip uninstall --system foo3 cd /tmp/cookie_python/foo3 python -c "import tests" - python -m pip install .[dev] + uv pip install --system .[dev] make -C docs html - name: upload generated projects - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@v4 with: name: cookie_python_${{ matrix.python-version }} path: /tmp/cookie_python diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8d70323..20b48f4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,8 +11,7 @@ repos: hooks: - id: yamlfix - repo: https://github.com/astral-sh/ruff-pre-commit - # Ruff version. - rev: v0.1.3 + rev: v0.9.0 hooks: - id: ruff - id: ruff-format diff --git a/cookiecutter.json b/cookiecutter.json index 3d7e8e3..0046454 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -8,6 +8,6 @@ "repository_url": "https://github.com/arup-group/{{cookiecutter.project_slug}}", "create_git_repository": "yes", "short_description": "One-liner to describe the package", - "minimum_python_version": "3.8", + "minimum_python_version": "3.10", "_copy_without_render": [".github/*", "docs/_templates/autoapi/*", "docs/substitutions.py" ] } diff --git a/{{cookiecutter.project_slug}}/.github/workflows/black.yml b/{{cookiecutter.project_slug}}/.github/workflows/black.yml deleted file mode 100644 index 1247533..0000000 --- a/{{cookiecutter.project_slug}}/.github/workflows/black.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -name: autoblack -on: [pull_request] -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.9 - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - name: Install Black - run: pip install black - - name: Run black --check --check --diff -v . - run: black --check --check --diff -v . diff --git a/{{cookiecutter.project_slug}}/.github/workflows/linter.yml b/{{cookiecutter.project_slug}}/.github/workflows/linter.yml deleted file mode 100644 index bf16250..0000000 --- a/{{cookiecutter.project_slug}}/.github/workflows/linter.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- -name: Linter - -on: - pull_request: - -jobs: - lint: - name: run_linter - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - - name: Install dependencies - run: pip install flake8 - - name: Run flake8 linter - run: | - mkdir -p ./linter_output - echo ${{ github.event.number }} > ./linter_output/pr_number - echo ${{ github.event.pull_request.head.sha }} > ./linter_output/head_sha - flake8 src | tee ./linter_output/flake8.out - - - uses: actions/upload-artifact@v2 - with: - name: linter_output - path: linter_output diff --git a/{{cookiecutter.project_slug}}/.github/workflows/process_linter_results.yml b/{{cookiecutter.project_slug}}/.github/workflows/process_linter_results.yml deleted file mode 100644 index 51d7ff3..0000000 --- a/{{cookiecutter.project_slug}}/.github/workflows/process_linter_results.yml +++ /dev/null @@ -1,54 +0,0 @@ ---- -name: Process linter results - -# read-write repo token -# access to secrets -on: - workflow_run: - workflows: [Linter] - types: - - completed - -jobs: - upload: - runs-on: ubuntu-latest - if: > - ${{ github.event.workflow_run.event == 'pull_request' }} - steps: - - name: Download artifact - # this breaks with current v6 - uses: actions/github-script@v5 - with: - script: | - var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: ${{github.event.workflow_run.id }}, - }); - var matchArtifact = artifacts.data.artifacts.filter((artifact) => { - return artifact.name == "linter_output" - })[0]; - var download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact.id, - archive_format: 'zip', - }); - var fs = require('fs'); - fs.writeFileSync('${{github.workspace}}/linter_output.zip', Buffer.from(download.data)); - - run: unzip linter_output.zip - - name: Set up Python - uses: actions/setup-python@v3 - # pinned to lintly 0.5.0 due to https://github.com/grantmcconnaughey/Lintly/issues/41 - - name: Install dependencies - run: pip install lintly==0.5.0 - - name: Comment on PR - run: | - cat ./flake8.out | lintly --fail-on=new \ - --use-checks \ - --exit-zero \ - --no-post-status \ - --pr="$(cat ./pr_number)" \ - --commit-sha="$(cat ./head_sha)" - env: - LINTLY_API_KEY: ${{ secrets.GITHUB_TOKEN }} diff --git a/{{cookiecutter.project_slug}}/.github/workflows/ruff.yml b/{{cookiecutter.project_slug}}/.github/workflows/ruff.yml new file mode 100644 index 0000000..ef4d5bd --- /dev/null +++ b/{{cookiecutter.project_slug}}/.github/workflows/ruff.yml @@ -0,0 +1,20 @@ +--- +name: ruff +on: [pull_request] +jobs: + ruff: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v5 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Install ruff + run: uv pip install --system ruff + - name: Run ruff format check + run: ruff format --check . + - name: Run ruff lint + run: ruff check . diff --git a/{{cookiecutter.project_slug}}/.github/workflows/test.yml b/{{cookiecutter.project_slug}}/.github/workflows/test.yml index 181b528..4687b12 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/test.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/test.yml @@ -17,39 +17,38 @@ jobs: fail-fast: false matrix: config: - - {os: windows-2022, py: '3.7'} - - {os: ubuntu-22.04, py: '3.9'} + - {os: ubuntu-22.04, py: '3.10'} + - {os: ubuntu-22.04, py: '3.11'} - {os: ubuntu-22.04, py: '3.12'} + - {os: ubuntu-22.04, py: '3.13'} env: - SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk OS: ${{ matrix.config.os }} PYTHON: ${{ matrix.config.py }} steps: - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.8.0 + uses: styfle/cancel-workflow-action@0.12.1 with: access_token: ${{ github.token }} - name: Checkout - uses: actions/checkout@v2 - - name: Setup Python - uses: actions/setup-python@v2 + uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v5 + - name: Set up Python + uses: actions/setup-python@v5 with: python-version: ${{ matrix.config.py }} - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install .[ci] + run: uv pip install --system .[ci] - name: run pytest - run: | - pytest + run: pytest - name: Upload coverage - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 with: env_vars: OS,PYTHON fail_ci_if_error: true CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - name: build docs run: | - python -m pip install .[docs] + uv pip install --system .[docs] make -C docs html diff --git a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml index a701234..4a9241e 100644 --- a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml @@ -7,8 +7,7 @@ repos: hooks: - id: yamlfix - repo: https://github.com/astral-sh/ruff-pre-commit - # Ruff version. - rev: v0.1.3 + rev: v0.9.0 hooks: - id: ruff - id: ruff-format diff --git a/{{cookiecutter.project_slug}}/Makefile b/{{cookiecutter.project_slug}}/Makefile index 5d0207f..4b80043 100644 --- a/{{cookiecutter.project_slug}}/Makefile +++ b/{{cookiecutter.project_slug}}/Makefile @@ -5,13 +5,14 @@ ENV_FILE?=.env include $(ENV_FILE) export $(shell sed 's/=.*//' $(ENV_FILE)) -.PHONY: deps black docs +.PHONY: deps format docs deps: ./dependencies.py -black: - black docs {{cookiecutter.project_slug}} tests +format: + ruff format . + ruff check --fix . docs: make -C docs html diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index b307727..c2fb53f 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -1,16 +1,14 @@ -[tool.black] -line-length = 120 -skip-string-normalization = true - [tool.ruff] target-version = "py{{ cookiecutter.minimum_python_version | replace(".", "") }}" +line-length = 120 +extend-exclude = ["_version.py", "docs/conf.py"] + +[tool.ruff.lint] select = ["ALL"] extend-ignore = ["E501", "ANN201", "ANN001", "D211", "D213"] -extend-exclude = ["_version.py", "docs/conf.py",] fix = true -line-length = 120 -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "tests/*.py" = ["S101", "D103"] [tool.pytest.ini_options] @@ -35,9 +33,9 @@ python = "{{ cookiecutter.minimum_python_version }}" [tool.hatch.envs.default.scripts] test = "pytest" lint = [ - "black .", - "ruff --fix .", - "mypy src/{{ cookiecutter.__module_name }}/", + "ruff format .", + "ruff check --fix .", + "ty check src/{{ cookiecutter.__module_name }}/", ] docs-build = "make -C docs html" @@ -66,9 +64,12 @@ docs = ["sphinx>=6", "sphinx-autoapi>=3", "myst-nb>=0.18", "furo>=2023.9.10"] +ci = [ + "pytest", + "pytest-cov", +] dev = [ - "black", - "mypy", + "ty", "ruff", "pytest", "pytest-cov",