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/.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/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/.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 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..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" @@ -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", ] 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 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