Skip to content

Commit

Permalink
Update tooling (#233)
Browse files Browse the repository at this point in the history
* Upgrade to Ruff 0.2.0 with formatting
* Move ruff config to ruff.toml
* Move coverage config to .coveragerc
* Specify the optional testing/linting dependencies
* Update GHA runner versions
  • Loading branch information
zerolab authored Feb 5, 2024
1 parent 5bdedce commit bc3cf85
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 89 deletions.
38 changes: 38 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ 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"
cache-dependency-path: "**/pyproject.toml"

- 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
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 5 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,15 +44,14 @@ 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 }}

- name: ⬇️ Install dependencies
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
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 3 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
76 changes: 9 additions & 67 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -57,71 +65,5 @@ exclude = [
"SPECIFICATION.md",
"manage.py",
"runtests.py",
]

[tool.black]
line_length = 88
target-version = ["py38"]

[tool.ruff]
target-version = "py38"

select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"E", # pycodestyle errors
"F", # pyflakes
"I", # isort
"S", # flake8-bandit
"W", # pycodestyle warnings
"UP", # pyupgrade
]

# Never enforce `E501` (line length violations).
ignore = ["E501"]

[tool.ruff.per-file-ignores]
"tests/**.py" = ["S105", "S106"]

[tool.ruff.isort]
known-first-party = ["src"]
lines-between-types = 1
lines-after-imports = 2

[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:",
"ruff.toml",
]
28 changes: 28 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit bc3cf85

Please sign in to comment.