From 9c7bc2fc695cb532628f320271ea5df7563342c2 Mon Sep 17 00:00:00 2001 From: drodarie Date: Sun, 13 Apr 2025 22:19:18 +0200 Subject: [PATCH 1/4] feat: rebase on uv and ruff. --- .github/workflows/black.yml | 14 --------- .github/workflows/branch.yml | 6 ++-- .github/workflows/external_pr.yml | 8 ++--- .github/workflows/release.yml | 20 ++++++------ .github/workflows/{isort.yml => ruff.yml} | 6 ++-- .pre-commit-config.yaml | 16 +++++----- README.md | 3 ++ pyproject.toml | 37 +++++++++++++++++------ test_actions/__init__.py | 3 ++ 9 files changed, 58 insertions(+), 55 deletions(-) delete mode 100644 .github/workflows/black.yml rename .github/workflows/{isort.yml => ruff.yml} (62%) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml deleted file mode 100644 index 0b86fd4..0000000 --- a/.github/workflows/black.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Black - -on: [workflow_call] - -jobs: - black: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: psf/black@stable - with: - options: "--check --verbose" - version: "24.1.1" diff --git a/.github/workflows/branch.yml b/.github/workflows/branch.yml index 1fa0ebc..83b166d 100644 --- a/.github/workflows/branch.yml +++ b/.github/workflows/branch.yml @@ -7,9 +7,7 @@ on: - '!main' # ... that is not main jobs: - isort: - uses: ./.github/workflows/isort.yml - black: - uses: ./.github/workflows/black.yml + ruff: + uses: ./.github/workflows/ruff.yml build: uses: ./.github/workflows/build.yml diff --git a/.github/workflows/external_pr.yml b/.github/workflows/external_pr.yml index bae7869..3a974ce 100644 --- a/.github/workflows/external_pr.yml +++ b/.github/workflows/external_pr.yml @@ -18,15 +18,11 @@ jobs: run: | echo "LOCAL_PR=${{ env.LOCAL_PR }}" >> $GITHUB_OUTPUT - isort: + ruff: needs: variables # if PR is external, trigger the tests on push or new PR if: ${{ needs.variables.outputs.LOCAL_PR == 'false'}} - uses: ./.github/workflows/isort.yml - black: - needs: variables - if: ${{ needs.variables.outputs.LOCAL_PR == 'false' }} - uses: ./.github/workflows/black.yml + uses: ./.github/workflows/ruff.yml build: needs: variables if: ${{ needs.variables.outputs.LOCAL_PR == 'false' }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e41f53c..0091029 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Bump version, create release and deploy +name: Build, test, deploy on: push: @@ -7,15 +7,13 @@ on: jobs: - isort: - uses: ./.github/workflows/isort.yml - black: - uses: ./.github/workflows/black.yml + ruff: + uses: ./.github/workflows/ruff.yml build: uses: ./.github/workflows/build.yml bump: - needs: [isort, black, build] + needs: [ruff, build] runs-on: ubuntu-latest outputs: tag: ${{ steps.semver.outputs.next }} @@ -23,7 +21,7 @@ jobs: steps: - name: Create Github token - uses: actions/create-github-app-token@v1 + uses: actions/create-github-app-token@v2 id: app-token with: app-id: ${{ vars.CODEGEN_APP_ID }} @@ -49,7 +47,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Create Github token - uses: actions/create-github-app-token@v1 + uses: actions/create-github-app-token@v2 id: app-token with: app-id: ${{ vars.CODEGEN_APP_ID }} @@ -92,7 +90,7 @@ jobs: steps: - name: Create Github token - uses: actions/create-github-app-token@v1 + uses: actions/create-github-app-token@v2 id: app-token with: app-id: ${{ vars.CODEGEN_APP_ID }} @@ -144,7 +142,7 @@ jobs: id-token: write # IMPORTANT: this permission is mandatory for trusted publishing steps: - name: Create Github token - uses: actions/create-github-app-token@v1 + uses: actions/create-github-app-token@v2 id: app-token with: app-id: ${{ vars.CODEGEN_APP_ID }} @@ -173,3 +171,5 @@ jobs: - name: Publish package distributions to Test.PyPI uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ diff --git a/.github/workflows/isort.yml b/.github/workflows/ruff.yml similarity index 62% rename from .github/workflows/isort.yml rename to .github/workflows/ruff.yml index dc47108..4988d86 100644 --- a/.github/workflows/isort.yml +++ b/.github/workflows/ruff.yml @@ -1,10 +1,10 @@ -name: Isort +name: Ruff on: [workflow_call] jobs: - isort: + ruff: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: isort/isort-action@master + - uses: astral-sh/ruff-action@v3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 33153b1..ac2dc9c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,15 +2,15 @@ default_install_hook_types: - pre-commit - commit-msg repos: - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 24.1.1 + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.11.5 hooks: - - id: black - - repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - name: isort (python) + # Run the linter. + - id: ruff + args: [ --fix ] + # Run the formatter. + - id: ruff-format - repo: https://github.com/compilerla/conventional-pre-commit rev: v3.3.0 hooks: diff --git a/README.md b/README.md index 4104ec9..e926622 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ +[![Build Status](https://github.com/drodarie/test_actions/actions/workflows/release.yml/badge.svg)](https://github.com/drodarie/test_actions/actions/workflows/build.yml) +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) + # test_actions Test Github actions for python project diff --git a/pyproject.toml b/pyproject.toml index 494756f..e4c0fe1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] -requires = ["poetry-core>=2.0.0,<3.0.0"] -build-backend = "poetry.core.masonry.api" +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" [project] name = "test-actions" @@ -12,20 +12,37 @@ requires-python = ">=3.10" version = "1.3.0" dynamic = ["description"] dependencies = [ - "numpy (>=2.2.3,<3.0.0)", - "scipy (>=1.15.2,<2.0.0)", - "pynrrd (>=1.1.3,<2.0.0)", + "numpy>=2.2.4", + "pynrrd>=1.1.3", + "scipy>=1.15.2", ] [project.optional-dependencies] -test = ["coverage (>=7.6.12,<8.0.0)"] -dev = ["black (>=25.1.0,<26.0.0)", "isort (>=6.0.0,<7.0.0)", "pre-commit (>=4.1.0,<5.0.0)", "bump-my-version (>=0.32.1,<0.33.0)"] +test = [ + "coverage>=7.8.0", +] +dev = [ + "pre-commit>=4.2.0", + "ruff>=0.11.5", +] -[tool.black] +[tool.ruff] +exclude = [".venv"] line-length = 100 +indent-width = 4 + +[tool.ruff.lint] +select = [ "E", "F", "UP", "B", "SIM", "I" ] +ignore = [ ] +fixable = [ "ALL" ] +unfixable = [ ] -[tool.isort] -profile = "black" +[tool.ruff.format] +quote-style = "double" +indent-style = "space" +skip-magic-trailing-comma = false +line-ending = "auto" +docstring-code-line-length = "dynamic" [tool.bumpversion] current_version = "1.3.0" diff --git a/test_actions/__init__.py b/test_actions/__init__.py index 830e8bc..785614e 100644 --- a/test_actions/__init__.py +++ b/test_actions/__init__.py @@ -6,3 +6,6 @@ import nrrd import numpy as np + +np.arange(0, 10, 0.1) +print(nrrd.__version__) From da955c0fb8c4f9aa2a57c33d8c7999d36890592e Mon Sep 17 00:00:00 2001 From: drodarie Date: Mon, 14 Apr 2025 00:26:02 +0200 Subject: [PATCH 2/4] feat: use pytest instead of coverage fix badges --- .github/workflows/branch.yml | 2 +- .github/workflows/build.yml | 2 +- README.md | 4 ++-- pyproject.toml | 11 ++++++++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/branch.yml b/.github/workflows/branch.yml index 83b166d..3ada289 100644 --- a/.github/workflows/branch.yml +++ b/.github/workflows/branch.yml @@ -1,4 +1,4 @@ -name: Check branch commit +name: Ruff on: push: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a3b7c54..c35e55f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,4 +30,4 @@ jobs: pip install .[test] - name: Run tests & coverage run: | - coverage run -p -m unittest discover -v -s ./tests + pytest . diff --git a/README.md b/README.md index e926622..59841c5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![Build Status](https://github.com/drodarie/test_actions/actions/workflows/release.yml/badge.svg)](https://github.com/drodarie/test_actions/actions/workflows/build.yml) -[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) +[![Build Status](https://github.com/drodarie/test_actions/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/drodarie/test_actions/actions/workflows/build.yml?query=branch%3Amain) +[![Ruff](https://github.com/drodarie/test_actions/actions/workflows/ruff.yml/badge.svg?branch=main)](https://github.com/drodarie/test_actions/actions/workflows/ruff.yml?query=branch%3Amain) # test_actions Test Github actions for python project diff --git a/pyproject.toml b/pyproject.toml index e4c0fe1..3d70b21 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,13 +19,22 @@ dependencies = [ [project.optional-dependencies] test = [ - "coverage>=7.8.0", + "pytest>=8.3.5", + "pytest-cov>=6.1.1", + "pytest-sugar>=1.0.0", ] dev = [ "pre-commit>=4.2.0", "ruff>=0.11.5", ] +[tool.pytest.ini_options] +addopts = """ + --cov + --cov-report html:'cover/html' + --cov-report xml:'cover/coverage.xml' +""" + [tool.ruff] exclude = [".venv"] line-length = 100 From 01861daa5ded586b0c5e6dfb7a4a1e10e12ab981 Mon Sep 17 00:00:00 2001 From: drodarie Date: Mon, 14 Apr 2025 00:36:11 +0200 Subject: [PATCH 3/4] fix: use uv for build --- .github/workflows/release.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0091029..b322ef3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -163,11 +163,12 @@ jobs: with: python-version: 3.11 - - name: Install dependencies and build dist + - name: Install uv + uses: astral-sh/setup-uv@v5 + + - name: Build run: | - python -m pip install --upgrade pip - pip install build - python -m build + uv build - name: Publish package distributions to Test.PyPI uses: pypa/gh-action-pypi-publish@release/v1 From e2824112caaead57baa646bc25ef2750d8959ceb Mon Sep 17 00:00:00 2001 From: drodarie Date: Mon, 14 Apr 2025 00:48:14 +0200 Subject: [PATCH 4/4] fix: github action name --- .github/workflows/branch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/branch.yml b/.github/workflows/branch.yml index 3ada289..83b166d 100644 --- a/.github/workflows/branch.yml +++ b/.github/workflows/branch.yml @@ -1,4 +1,4 @@ -name: Ruff +name: Check branch commit on: push: