Skip to content

Commit a1f1067

Browse files
committed
Update formatting and linting and add pre-commit
1 parent 41c2fcc commit a1f1067

15 files changed

Lines changed: 159 additions & 51 deletions

‎.github/workflows/packaging.yml‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ name: Packaging
33
on:
44
push:
55
branches: [main]
6-
tags: ["v*"] # run on version tags
6+
tags: ["v*"] # run on version tags
77
pull_request:
8-
branches: [main] # run on PRs targeting main
8+
branches: [main] # run on PRs targeting main
99
release:
10-
types: [published] # run on Github release
10+
types: [published] # run on Github release
1111

1212
jobs:
1313
check:
@@ -44,7 +44,7 @@ jobs:
4444

4545
build:
4646
name: Build source distribution
47-
needs: [check, test] # wait for checks and tests
47+
needs: [check, test] # wait for checks and tests
4848
runs-on: ubuntu-latest
4949
steps:
5050
- uses: actions/checkout@v6
@@ -62,14 +62,14 @@ jobs:
6262

6363
publish-pypi:
6464
name: Publish on PyPI
65-
needs: [build] # wait for build
66-
if: github.event_name == 'release' # only on release
65+
needs: [build] # wait for build
66+
if: github.event_name == 'release' # only on release
6767
runs-on: ubuntu-latest
6868
environment:
6969
name: pypi
7070
url: https://pypi.org/p/django-webmention
7171
permissions:
72-
id-token: write # required for trusted publishing
72+
id-token: write # required for trusted publishing
7373
steps:
7474
- uses: actions/download-artifact@v7
7575
with:
@@ -80,14 +80,14 @@ jobs:
8080

8181
publish-pypi-test:
8282
name: Publish on Test PyPI
83-
needs: [build] # wait for build
84-
if: startsWith(github.ref, 'refs/tags/') # only on tags
83+
needs: [build] # wait for build
84+
if: startsWith(github.ref, 'refs/tags/') # only on tags
8585
runs-on: ubuntu-latest
8686
environment:
8787
name: pypi-test
8888
url: https://test.pypi.org/p/django-webmention
8989
permissions:
90-
id-token: write # required for trusted publishing
90+
id-token: write # required for trusted publishing
9191
steps:
9292
- uses: actions/download-artifact@v7
9393
with:

‎.pre-commit-config.yaml‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# yaml-language-server: $shema=https://json.schemastore.org/pre-commit-config.json
2+
3+
####################################################
4+
# Checks about the pre-commit configuration itself #
5+
####################################################
6+
7+
repos:
8+
- repo: meta
9+
hooks:
10+
- id: check-hooks-apply # Ensures all defined hooks affect at least one file in the repo
11+
- id: check-useless-excludes # Ensures all defined excludes apply to at least one file in the repo
12+
13+
###########################
14+
# General use / built-ins #
15+
###########################
16+
17+
# Click through to this repository to see what other goodies are available
18+
- repo: https://github.com/pre-commit/pre-commit-hooks
19+
rev: v6.0.0
20+
hooks:
21+
- id: check-ast # Checks Python code for syntax errors
22+
- id: trailing-whitespace # Removes trailing whitespace from lines in all file types
23+
- id: end-of-file-fixer # Fixes last line of all file types
24+
- id: check-merge-conflict # Checks if you're about to commit a file that hasn't had conflicts resolved
25+
- id: no-commit-to-branch # Checks if you're committing to a disallowed branch (default is master)
26+
- id: check-toml # Checks TOML files for syntax errors
27+
- id: check-yaml # Checks YAML files for syntax errors
28+
29+
##########
30+
# Python #
31+
##########
32+
33+
- repo: https://github.com/astral-sh/ruff-pre-commit
34+
rev: v0.15.1
35+
hooks:
36+
- id: ruff-check
37+
- id: ruff-format
38+
39+
- repo: https://github.com/pre-commit/mirrors-mypy
40+
rev: v1.19.1
41+
hooks:
42+
- id: mypy
43+
additional_dependencies:
44+
[
45+
types-requests,
46+
]
47+
48+
############
49+
# Markdown #
50+
############
51+
52+
- repo: https://github.com/pre-commit/mirrors-prettier
53+
rev: v3.1.0
54+
hooks:
55+
- id: prettier

‎CHANGELOG.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,113 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
56
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
67

78
## [4.0.0] - 2026-02-19
9+
810
### Removed
11+
912
- Support for Python 3.9
1013

1114
## [3.0.0] - 2023-01-03
15+
1216
### Added
17+
1318
- Support for Django 4.0+
1419

1520
### Removed
21+
1622
- Support for Django versions less than 2.2
1723
- Support for Python versions less than 3.7
1824

1925
## [2.0.2] - 2021-02-14
26+
2027
### Fixed
28+
2129
- Store source content as a string rather than a bytes object
2230

2331
## [2.0.1] - 2020-08-25
32+
2433
### Fixed
34+
2535
- Render HTML links in the Django admin by using `format_html` instead of the now-deprecated `allow_tags` attribute
2636

2737
## [2.0.0] - 2020-08-20
38+
2839
### Removed
40+
2941
- Support for Python 3.5
3042

3143
### Added
44+
3245
- Compatibility in the `include_webmention_information` decorator for versions of Django with new-style middleware
3346

3447
## [1.1.0] - 2019-07-22
48+
3549
### Changed
50+
3651
- Use static `setup.cfg` for package metadata and tooling configuration
3752
- Use black code style
3853
- Lint with pyflakes
3954

4055
## [1.0.1] - 2018-04-12
56+
4157
### Fixed
58+
4259
- Made `setup.py` aware that the README content type is, in fact, markdown
4360

4461
## [1.0.0] - 2018-04-12
62+
4563
### Added
64+
4665
- Better documentation about testing
4766
- Coverage configuration
4867

4968
### Changed
69+
5070
- Use markdown for PyPI README
5171

5272
## [0.1.0] - 2018-01-02
73+
5374
### Added
75+
5476
- Mention use of `path()` over `url()` in README
5577
- Mention use of new-style `MIDDLEWARE` over old-style `MIDDLEWARE_CLASSES` in README
5678
- Add system check to detect presence of incorrect middleware configuration
5779
- Update imports and other syntax for forward compatibility with Django 1.10+ and Django 2.0+
5880

5981
## [0.0.4] - 2016-07-15
82+
6083
### Changed
84+
6185
- Reworked the unit tests to be runnable under Travis CI to support continuous integration
6286

6387
## [0.0.3] - 2016-01-22
88+
6489
### Changed
90+
6591
- Successful POST requests will now receive a 202 Accepted response rather than a 200 OK response
6692

6793
### Added
94+
6895
- Django 1.9 in frameworks listed in setup.py
6996

7097
### Fixed
98+
7199
- Errors in documentation
72100

73101
## [0.0.2] - 2015-07-11
102+
74103
### Added
104+
75105
- Webmentions are now available for review in the admin console
76106
- Webmentions are now updated or invalidated when a new webmention notification request is sent
77107
- Thorough unit testing
78108

79109
## [0.0.1] - 2015-07-10
110+
80111
### Added
112+
81113
- Pre-alpha initial release

‎README.md‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ This package does not currently provide functionality for [sending webmentions](
1818

1919
`$ pip install django-webmention`
2020

21-
* Add `'webmention'` to `INSTALLED_APPS`
22-
* Run `python manage.py migrate webmention`
23-
* Add the URL patterns to your top-level `urls.py`
24-
* `path('webmention/', include('webmention.urls'))` for Django >= 3.2
21+
- Add `'webmention'` to `INSTALLED_APPS`
22+
- Run `python manage.py migrate webmention`
23+
- Add the URL patterns to your top-level `urls.py`
24+
- `path('webmention/', include('webmention.urls'))` for Django >= 3.2
2525

2626
## Usage
2727

28-
* Include webmention information by either:
29-
* Installing the middleware in `settings.py` (affects all views)
30-
* Append `webmention.middleware.webmention_middleware` to your `MIDDLEWARE` settings
31-
* Decorating a specific view with `webmention.middleware.include_webmention_information`
32-
* View webmention responses in the Django admin interface and mark them as reviewed as needed
28+
- Include webmention information by either:
29+
- Installing the middleware in `settings.py` (affects all views)
30+
- Append `webmention.middleware.webmention_middleware` to your `MIDDLEWARE` settings
31+
- Decorating a specific view with `webmention.middleware.include_webmention_information`
32+
- View webmention responses in the Django admin interface and mark them as reviewed as needed
3333

3434
## Development
3535

3636
### Setup
3737

38-
* Install [tox](https://tox.readthedocs.io)
38+
- Install [tox](https://tox.readthedocs.io)
3939

4040
### Running Tests
4141

‎conftest.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
@pytest.fixture
55
def test_source():
6-
return 'http://example.com'
6+
return "http://example.com"
77

88

99
@pytest.fixture
1010
def test_target():
11-
return 'http://mysite.com'
11+
return "http://mysite.com"

‎pyproject.toml‎

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,35 @@ readme = { file = "README.md", content-type = "text/markdown" }
4545
# Tool configuration #
4646
######################
4747

48-
[tool.black]
48+
[tool.ruff]
4949
line-length = 120
50-
target-version = ["py310", "py311", "py312", "py313", "py314"]
50+
target-version = "py310"
51+
52+
[tool.ruff.lint]
53+
select = [
54+
"A",
55+
"B",
56+
"C4",
57+
"DTZ",
58+
"E",
59+
"F",
60+
"I",
61+
"ISC",
62+
"LOG",
63+
"PT",
64+
"PTH",
65+
"RUF",
66+
"S",
67+
"SIM",
68+
"UP",
69+
]
70+
ignore = [
71+
"E501",
72+
"PT019",
73+
"RUF012",
74+
"S101",
75+
"S105",
76+
]
5177

5278
[tool.mypy]
5379
python_version = "3.10"
@@ -188,16 +214,16 @@ deps = [
188214
"ruff",
189215
]
190216
commands = [
191-
["ruff", "check", { replace = "posargs", default = ["--diff", "src/webmention", "tests"], extend = true }],
217+
["ruff", "check", { replace = "posargs", default = ["src/webmention", "tests"], extend = true }],
192218
]
193219

194220
[tool.tox.env.format]
195221
skip_install = true
196222
deps = [
197-
"black",
223+
"ruff",
198224
]
199225
commands = [
200-
["black", { replace = "posargs", default = ["--check", "--diff", "src/webmention", "tests"], extend = true }],
226+
["ruff", "format", { replace = "posargs", default = ["src/webmention", "tests"], extend = true }],
201227
]
202228

203229
[tool.tox.env.typecheck]

‎src/webmention/checks.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import django
22
from django.conf import settings
3-
from django.core.checks import Error, register, Tags
3+
from django.core.checks import Error, Tags, register
44

55

66
@register(Tags.compatibility)

‎src/webmention/migrations/0001_initial.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
3-
4-
from django.db import models, migrations
1+
from django.db import migrations, models
52

63

74
class Migration(migrations.Migration):
8-
9-
dependencies = []
5+
dependencies: list[tuple[str]] = []
106

117
operations = [
128
migrations.CreateModel(

‎src/webmention/resolution.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import requests
2-
31
from urllib.parse import urlparse
42

3+
import requests
4+
55
try:
6-
from django.core.urlresolvers import resolve, Resolver404
6+
from django.core.urlresolvers import Resolver404, resolve
77
except ImportError:
8-
from django.urls import resolve, Resolver404
8+
from django.urls import Resolver404, resolve
99

1010

1111
def url_resolves(url):
@@ -17,7 +17,8 @@ def url_resolves(url):
1717

1818

1919
def fetch_and_validate_source(source, target):
20-
response = requests.get(source)
20+
# TODO: Create a sensible default timeout for this request, and make it configurable
21+
response = requests.get(source) # noqa: S113 until we have a sensible default timeout
2122
if response.status_code == 200:
2223
if target in response.text:
2324
return response.text

‎src/webmention/views.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseServerError
12
from django.views.decorators.csrf import csrf_exempt
23
from django.views.decorators.http import require_POST
3-
from django.http import HttpResponseBadRequest, HttpResponseServerError, HttpResponse
44

55
from .models import WebMentionResponse
6-
from .resolution import url_resolves, fetch_and_validate_source, SourceFetchError, TargetNotFoundError
6+
from .resolution import SourceFetchError, TargetNotFoundError, fetch_and_validate_source, url_resolves
77

88

99
@csrf_exempt

0 commit comments

Comments
 (0)