From 211835ec8e8244b75a2ede16a7d00ac8c78ab3c1 Mon Sep 17 00:00:00 2001 From: zerolab Date: Mon, 5 Feb 2024 20:20:25 +0000 Subject: [PATCH 1/5] Upgrade to Ruff 0.2.0 with formatting --- .github/workflows/ruff.yml | 22 ++++++++++++++++++++++ .pre-commit-config.yaml | 13 +++---------- pyproject.toml | 23 +++++++++++------------ 3 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/ruff.yml diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml new file mode 100644 index 0000000..0e6a867 --- /dev/null +++ b/.github/workflows/ruff.yml @@ -0,0 +1,22 @@ +name: Ruff + +on: + push: + branches: + - main + - 'stable/**' + pull_request: + branches: [main] + +jobs: + ruff: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - run: python -Im pip install --user ruff + + - name: Run ruff + working-directory: ./src + run: ruff --output-format=github wagtailmedia diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 78a7fc1..b019d1d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,16 +17,9 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/psf/black - rev: 23.10.1 - hooks: - - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.1.3' + rev: 'v0.2.0' hooks: - id: ruff - - repo: https://github.com/adamchainz/blacken-docs - rev: 1.16.0 - hooks: - - id: blacken-docs - additional_dependencies: [black==23.10.1] + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format diff --git a/pyproject.toml b/pyproject.toml index 4158071..5d86d42 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,14 +59,8 @@ exclude = [ "runtests.py", ] -[tool.black] -line_length = 88 -target-version = ["py38"] - -[tool.ruff] -target-version = "py38" - -select = [ +[tool.ruff.lint] +extend-select = [ "B", # flake8-bugbear "C4", # flake8-comprehensions "E", # pycodestyle errors @@ -77,17 +71,22 @@ select = [ "UP", # pyupgrade ] -# Never enforce `E501` (line length violations). -ignore = ["E501"] +extend-ignore = [ + "E501", # no line length errors +] +fixable = ["C4", "E", "F", "I", "UP"] -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "tests/**.py" = ["S105", "S106"] -[tool.ruff.isort] +[tool.ruff.lint.isort] known-first-party = ["src"] lines-between-types = 1 lines-after-imports = 2 +[tool.ruff.format] +docstring-code-format = true + [tool.coverage.run] branch = true parallel = true From c0b1fcf85edc8696223b005c14813736a6c3a7a9 Mon Sep 17 00:00:00 2001 From: zerolab Date: Mon, 5 Feb 2024 20:22:40 +0000 Subject: [PATCH 2/5] Move ruff config to ruff.toml --- pyproject.toml | 29 +---------------------------- ruff.toml | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 28 deletions(-) create mode 100644 ruff.toml diff --git a/pyproject.toml b/pyproject.toml index 5d86d42..6604a91 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,36 +57,9 @@ exclude = [ "SPECIFICATION.md", "manage.py", "runtests.py", + "ruff.toml", ] -[tool.ruff.lint] -extend-select = [ - "B", # flake8-bugbear - "C4", # flake8-comprehensions - "E", # pycodestyle errors - "F", # pyflakes - "I", # isort - "S", # flake8-bandit - "W", # pycodestyle warnings - "UP", # pyupgrade -] - -extend-ignore = [ - "E501", # no line length errors -] -fixable = ["C4", "E", "F", "I", "UP"] - -[tool.ruff.lint.per-file-ignores] -"tests/**.py" = ["S105", "S106"] - -[tool.ruff.lint.isort] -known-first-party = ["src"] -lines-between-types = 1 -lines-after-imports = 2 - -[tool.ruff.format] -docstring-code-format = true - [tool.coverage.run] branch = true parallel = true diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..802a499 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,28 @@ +[lint] +extend-select = [ + "B", # flake8-bugbear + "C4", # flake8-comprehensions + "E", # pycodestyle errors + "F", # pyflakes + "I", # isort + "S", # flake8-bandit + "W", # pycodestyle warnings + "UP", # pyupgrade +] + +extend-ignore = [ + "E501", # no line length errors +] + +fixable = ["C4", "E", "F", "I", "UP"] + +[lint.per-file-ignores] +"tests/**.py" = ["S105", "S106"] + +[lint.isort] +known-first-party = ["src"] +lines-between-types = 1 +lines-after-imports = 2 + +[format] +docstring-code-format = true From 1f6b7f43c489dc6c3e5b094f925584a783e35b96 Mon Sep 17 00:00:00 2001 From: zerolab Date: Mon, 5 Feb 2024 20:26:37 +0000 Subject: [PATCH 3/5] Move coverage config to .coveragerc --- .coveragerc | 38 ++++++++++++++++++++++++++++++++++++++ pyproject.toml | 38 -------------------------------------- tox.ini | 4 ++-- 3 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..e557a33 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,38 @@ +[run] +branch = true +parallel = true +concurrency = multiprocessing, thread +source = wagtailmedia + +omit = **/migrations/*,tests/*,src/wagtailmedia/admin.py,src/wagtailmedia/deprecation.py + +[paths] +source = src,.tox/py*/**/site-packages + +[report] +show_missing = true +ignore_errors = true +skip_empty = true +skip_covered = true + +exclude_also = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + if self.debug + if settings.DEBUG + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: + + # Nor complain about type checking + "if TYPE_CHECKING:", + class .*\bProtocol\): + @(abc\.)?abstractmethod diff --git a/pyproject.toml b/pyproject.toml index 6604a91..ac0f687 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,41 +59,3 @@ exclude = [ "runtests.py", "ruff.toml", ] - -[tool.coverage.run] -branch = true -parallel = true -source = ["wagtailmedia"] - -omit = ["**/migrations/*", "tests/*", "src/wagtailmedia/admin.py", "src/wagtailmedia/deprecation.py"] - -[tool.coverage.paths] -source = ["src", ".tox/py*/**/site-packages"] - -[tool.coverage.report] -show_missing = true -ignore_errors = true -skip_empty = true -skip_covered = true -exclude_lines = [ - # Have to re-enable the standard pragma - "pragma: no cover", - - # Don't complain about missing debug-only code: - "def __repr__", - "if self.debug", - - # Don't complain if tests don't hit defensive assertion code: - "raise AssertionError", - "raise NotImplementedError", - - # Don't complain if non-runnable code isn't run: - "if 0:", - "if __name__ == .__main__.:", - - # Don't complain about abstract methods, they aren't run: - "@(abc.)?abstractmethod", - - # Nor complain about type checking - "if TYPE_CHECKING:", -] diff --git a/tox.ini b/tox.ini index bb83308..72ff451 100644 --- a/tox.ini +++ b/tox.ini @@ -37,7 +37,7 @@ setenv = PYTHONDEVMODE = 1 deps = - coverage[toml]>=7.0,<8.0 + coverage>=7.0,<8.0 dj32: Django>=3.2,<3.3 dj42: Django>=4.2,<5.0 dj50: Django>=5.0,<5.1 @@ -54,7 +54,7 @@ commands = base_python = python3.11 package = skip deps = - coverage[toml]>=7.0,<8.0 + coverage>=7.0,<8.0 commands = python -Im coverage combine python -Im coverage report -m From 1f2e762480758e34dd6ccb8886982a084b34f751 Mon Sep 17 00:00:00 2001 From: zerolab Date: Mon, 5 Feb 2024 20:29:43 +0000 Subject: [PATCH 4/5] Specify the optional testing/linting dependencies --- pyproject.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index ac0f687..ba9f425 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,14 @@ dependencies = [ "Django>=3.2", ] +[project.optional-dependencies] +testing = [ + "coverage>=7.4.0", +] +linting = [ + "pre-commit>=3.6.0", +] + [project.urls] Repository = "https://github.com/torchbox/wagtailmedia" Changelog = "https://github.com/torchbox/wagtailmedia/blob/main/CHANGELOG.md" From 1555e76b61d93bf51ba6d20baf3621bb8df1f118 Mon Sep 17 00:00:00 2001 From: zerolab Date: Mon, 5 Feb 2024 21:15:24 +0000 Subject: [PATCH 5/5] Update GHA runners --- .github/workflows/publish.yml | 7 +++---- .github/workflows/test.yml | 11 +++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 75967e5..4e08246 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,11 +11,11 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: '3.11' cache: "pip" @@ -23,8 +23,7 @@ jobs: - name: ⬇️ Install build dependencies run: | - python -Im pip install flit - python -Im flit install --symlink + python -Im pip install -U flit - name: 🏗️ Build run: python -Im flit build diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d61d675..442415f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,7 +32,7 @@ jobs: steps: - name: 🔒 Harden Runner - uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0 + uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 with: disable-sudo: true egress-policy: block @@ -44,7 +44,7 @@ jobs: api.github.com:443 - uses: actions/checkout@v3 - name: 🐍 Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -52,7 +52,6 @@ jobs: run: | python -Im pip install --upgrade pip python -Im pip install flit tox tox-gh-actions - python -Im flit install --symlink - name: 🏗️ Build wheel run: python -Im flit build --format wheel @@ -74,7 +73,7 @@ jobs: steps: - name: 🔒 Harden Runner - uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0 + uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 with: disable-sudo: true egress-policy: block @@ -86,12 +85,12 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: # Use latest Python, so it understands all syntax. python-version: ${{env.PYTHON_LATEST}} - - run: python -Im pip install --upgrade coverage[toml] + - run: python -Im pip install --upgrade coverage - name: Download coverage data uses: actions/download-artifact@v3