Skip to content

Commit df47fa4

Browse files
authored
Switch to pyproject.toml, ruff, and update build tooling (#73)
* Remove black, flake8, isort * Switch to ruff * Switch from setup.py to pyproject.toml * Update azure pipeline to Python 3.12 and PublishCodeCoverageResults@2
1 parent a49b7e4 commit df47fa4

File tree

9 files changed

+95
-98
lines changed

9 files changed

+95
-98
lines changed

azure-pipelines.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ stages:
7171
testResultsFiles: '**/test-*.xml'
7272
testRunTitle: 'Publish test results for Python $(python.version)'
7373

74-
- task: PublishCodeCoverageResults@1
74+
- task: PublishCodeCoverageResults@2
7575
displayName: 'Publish code coverage report'
7676
condition: succeededOrFailed()
7777
inputs:
78-
codeCoverageTool: Cobertura
7978
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml'
8079

8180

@@ -93,7 +92,7 @@ stages:
9392
- task: UsePythonVersion@0
9493
displayName: 'Use Python version'
9594
inputs:
96-
versionSpec: '3.11'
95+
versionSpec: '3.12'
9796
architecture: 'x64'
9897

9998
- script: python -m pip install -r requirements-dev.txt
@@ -102,14 +101,11 @@ stages:
102101
- script: codespell ./docs/ ./wagtailcache/
103102
displayName: 'CR-QC: Spell check'
104103

105-
- script: flake8 .
106-
displayName: 'CR-QC: Static analysis (flake8)'
104+
- script: ruff check .
105+
displayName: 'CR-QC: Static analysis (ruff)'
107106

108-
- script: isort --check .
109-
displayName: 'CR-QC: Format check (isort)'
110-
111-
- script: black --check .
112-
displayName: 'CR-QC: Format check (black)'
107+
- script: ruff format --check .
108+
displayName: 'CR-QC: Format check'
113109

114110
- script: mypy ./wagtailcache/
115111
displayName: 'CR-QC: Type check (mypy)'
@@ -144,7 +140,7 @@ stages:
144140
- task: UsePythonVersion@0
145141
displayName: 'Use Python version'
146142
inputs:
147-
versionSpec: '3.11'
143+
versionSpec: '3.12'
148144
architecture: 'x64'
149145

150146
- script: python -m pip install -r requirements-dev.txt

ci/compare-codecov.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ foreach ($cov in $mainCoverageJson.coverageData.coverageStats) {
6868

6969

7070
# Get current code coverage from coverage.xml file.
71-
$coveragePath = Get-ChildItem -Recurse -Filter "coverage.xml" $wd
71+
# Use the first one, if there are multiple i.e. from multiple runs.
72+
$coveragePath = (Get-ChildItem -Recurse -Filter "coverage.xml" $wd)[0]
7273
if (Test-Path -Path $coveragePath) {
7374
[xml]$BranchXML = Get-Content $coveragePath
7475
}
@@ -84,7 +85,7 @@ $branchlinerate = [math]::Round([decimal]$BranchXML.coverage.'line-rate' * 100,
8485

8586

8687
Write-Output ""
87-
Write-Output "Dev branch coverage rate: $mainlinerate%"
88+
Write-Output "Main branch coverage rate: $mainlinerate%"
8889
Write-Output "This branch coverage rate: $branchlinerate%"
8990

9091
if ($mainlinerate -eq 0) {

docs/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ the ``dist/`` directory.
5858

5959
.. code-block:: console
6060
61-
$ python setup.py sdist bdist_wheel
61+
$ python -m build

pyproject.toml

Lines changed: 78 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,79 @@
1-
[tool.black]
1+
# -- PACKAGE INFO ---------------------
2+
3+
[build-system]
4+
requires = ["setuptools >= 65.0"]
5+
build-backend = "setuptools.build_meta"
6+
7+
[project]
8+
authors = [
9+
{name = "CodeRed LLC", email = "[email protected]"}
10+
]
11+
classifiers = [
12+
"Intended Audience :: Developers",
13+
"License :: OSI Approved :: BSD License",
14+
"Natural Language :: English",
15+
"Operating System :: OS Independent",
16+
"Programming Language :: Python :: 3",
17+
"Programming Language :: Python :: 3 :: Only",
18+
"Framework :: Django",
19+
"Framework :: Wagtail",
20+
"Framework :: Wagtail :: 3",
21+
"Framework :: Wagtail :: 4",
22+
"Framework :: Wagtail :: 5",
23+
"Framework :: Wagtail :: 6",
24+
]
25+
dependencies = [
26+
"wagtail>=3.0,<7",
27+
]
28+
description = "A simple page cache for Wagtail based on the Django cache middleware."
29+
dynamic = ["version"]
30+
license = {file = "LICENSE"}
31+
name = "wagtail-cache"
32+
readme = "README.md"
33+
requires-python = ">=3.8"
34+
35+
[project.urls]
36+
Source = "https://github.com/coderedcorp/wagtail-cache"
37+
38+
[tool.setuptools]
39+
packages = ["wagtailcache"]
40+
41+
[tool.setuptools.dynamic]
42+
version = {attr = "wagtailcache.__version__"}
43+
44+
45+
# -- TOOLS ----------------------------
46+
47+
[tool.codespell]
48+
ignore-words-list = ["doubleclick"]
49+
50+
[tool.django-stubs]
51+
django_settings_module = "testproject.settings"
52+
53+
[tool.mypy]
54+
ignore_missing_imports = true
55+
check_untyped_defs = true
56+
exclude = [
57+
'^\..*',
58+
'migrations',
59+
'node_modules',
60+
'venv',
61+
]
62+
63+
[tool.pytest.ini_options]
64+
DJANGO_SETTINGS_MODULE = "testproject.settings"
65+
junit_family = "xunit2"
66+
addopts = "--cov wagtailcache --cov-report html --cov-report xml --junitxml junit/test-results.xml"
67+
python_files = "tests.py test_*.py"
68+
69+
[tool.ruff]
70+
extend-exclude = ["build", "migrations"]
271
line-length = 80
3-
target-version = ['py38', 'py39', 'py310', 'py311']
4-
# Regular expression of files to exclude.
5-
exclude = '''
6-
/(
7-
\.venv
8-
| build
9-
| migrations
10-
)/
11-
'''
12-
13-
[tool.isort]
14-
force_alphabetical_sort_within_sections = true
15-
force_single_line = true
16-
lines_after_imports = 2
17-
lines_before_imports = 0
18-
lines_between_sections = 1
19-
lines_between_types = 0
20-
line_length = 80
21-
profile = "black"
22-
skip_gitignore = true
23-
extend_skip = ["migrations"]
24-
# Specific to this project
25-
known_first_party = ["home", "wagtailcache"]
72+
73+
[tool.ruff.lint]
74+
extend-select = ["I"]
75+
76+
[tool.ruff.lint.isort]
77+
case-sensitive = false
78+
force-single-line = true
79+
lines-after-imports = 2

requirements-dev.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
-e ./
2-
black
2+
build
33
codespell
4-
flake8
5-
isort
64
mypy
75
pytest
86
pytest-cov
97
pytest-django
8+
ruff
9+
setuptools>=65.0
1010
sphinx
1111
sphinx-wagtail-theme
1212
twine
13-
wheel

setup.cfg

Lines changed: 0 additions & 16 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

testproject/home/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from django.contrib.auth.models import User
44
from django.contrib.contenttypes.models import ContentType
55
from django.core.cache import caches
6+
from django.test import TestCase
67
from django.test import modify_settings
78
from django.test import override_settings
8-
from django.test import TestCase
99
from django.urls import reverse
1010
from wagtail import hooks
1111
from wagtail.models import PageViewRestriction
@@ -17,8 +17,8 @@
1717
from home.models import CsrfPage
1818
from home.models import WagtailPage
1919
from wagtailcache.cache import CacheControl
20-
from wagtailcache.cache import clear_cache
2120
from wagtailcache.cache import Status
21+
from wagtailcache.cache import clear_cache
2222
from wagtailcache.settings import wagtailcache_settings
2323

2424

testproject/testproject/urls.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
from django.contrib import admin
33
from django.urls import include
44
from django.urls import path
5+
from home import views
56
from wagtail import urls as wagtail_urls
67
from wagtail.admin import urls as wagtailadmin_urls
78
from wagtail.documents import urls as wagtaildocs_urls
89

9-
from home import views
10-
1110

1211
urlpatterns = [
1312
path("django-admin/", admin.site.urls),

0 commit comments

Comments
 (0)