Skip to content

Commit 3a1609f

Browse files
Upgrade tooling (#247)
1 parent f707b0c commit 3a1609f

26 files changed

+115
-136
lines changed

Diff for: .coveragerc_dj22

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[report]
2+
exclude_lines =
3+
pragma: no cover
4+
pragma: nodj22

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,4 @@ venv.bak/
107107
*.sqlite3
108108

109109
.idea/
110+
.ruff_cache/

Diff for: Makefile

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1+
.PHONY: docs
2+
13
venv = venv
24
bin = ${venv}/bin/
35
pysources = src/ test_project/ tests/
46

57
build:
6-
${bin}python setup.py sdist bdist_wheel
7-
${bin}twine check dist/*
8-
rm -r build
8+
${bin}python -m build
99

1010
check:
11-
${bin}black --check --diff --target-version=py36 ${pysources}
12-
${bin}flake8 ${pysources}
11+
${bin}ruff check ${pysources}
12+
${bin}black --check --diff ${pysources}
1313
${bin}mypy ${pysources}
14-
${bin}isort --check --diff ${pysources}
1514
make migrations-check
1615

1716
docs:
@@ -23,16 +22,20 @@ docs-serve:
2322
docs-deploy:
2423
${bin}mkdocs gh-deploy
2524

26-
install:
25+
install: install-python
26+
27+
venv:
2728
python3 -m venv ${venv}
29+
30+
install-python: venv
2831
${bin}pip install -U pip wheel
32+
${bin}pip install -U build
2933
${bin}pip install -r requirements.txt
3034
./tools/install_django.sh ${bin}pip
3135

3236
format:
33-
${bin}autoflake --in-place --recursive ${pysources}
34-
${bin}isort ${pysources}
35-
${bin}black --target-version=py36 ${pysources}
37+
${bin}ruff check --fix ${pysources}
38+
${bin}black ${pysources}
3639

3740
migrations:
3841
${bin}python -m tools.makemigrations

Diff for: ci/azure-pipelines.yml

+11-13
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ resources:
44
type: github
55
endpoint: github
66
name: florimondmanca/azure-pipelines-templates
7-
ref: refs/tags/5.0
7+
ref: refs/tags/6.0
88
containers:
9-
- container: pg11
10-
image: postgres:11
9+
- container: pg15
10+
image: postgres:15-alpine
1111
ports:
1212
- 5432:5432
1313
env:
@@ -34,36 +34,34 @@ stages:
3434
jobs:
3535
- template: job--python-check.yml@templates
3636
parameters:
37-
pythonVersion: "3.10"
37+
pythonVersion: "3.11"
3838

3939
- template: job--python-docs-build.yml@templates
4040
parameters:
41-
pythonVersion: "3.10"
41+
pythonVersion: "3.11"
4242

4343
- template: job--python-test.yml@templates
4444
parameters:
4545
jobs:
46-
py37_dj22:
46+
py38_dj22:
4747
variables:
4848
DJANGO_VERSION: "2.2.*"
49+
PYTEST_ADDOPTS: "--cov-config=.coveragerc_dj22"
4950

5051
py38_dj32:
51-
variables:
52-
DJANGO_VERSION: "3.2.*"
53-
54-
py310_dj32:
5552
coverage: true
5653
variables:
5754
DJANGO_VERSION: "3.2.*"
5855

59-
py310_dj42:
56+
py311_dj42:
6057
coverage: true
6158
variables:
6259
DJANGO_VERSION: "4.2.*"
60+
PYTEST_ADDOPTS: "--cov=tests"
6361

64-
py310_postgres:
62+
py311_postgres:
6563
services:
66-
postgres: pg11
64+
postgres: pg15
6765
variables:
6866
DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/default"
6967

Diff for: docs/guide.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
### Installation
66

7-
Install from PyPI:
7+
Install with `pip`:
88

99
```bash
10-
pip install djangorestframework-api-key
10+
pip install "djangorestframework-api-key==2.*"
1111
```
1212

13-
**Note**: this package requires Python 3.7+, Django 2.0+ and Django REST Framework 3.8+.
13+
_**Note**: It is highly recommended to **pin your dependency** to the latest major version (as depicted above), as breaking changes may and will happen between major releases._
1414

1515
### Project setup
1616

Diff for: pyproject.toml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[build-system]
2+
requires = ["setuptools", "setuptools-scm", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "djangorestframework-api-key"
7+
description = "API key permissions for the Django REST Framework"
8+
requires-python = ">=3.8"
9+
license = { text = "MIT" }
10+
authors = [
11+
{ name = "Florimond Manca", email = "[email protected]" },
12+
]
13+
classifiers = [
14+
"Development Status :: 4 - Beta",
15+
"Operating System :: OS Independent",
16+
"Intended Audience :: Developers",
17+
"Programming Language :: Python :: 3 :: Only",
18+
"Programming Language :: Python :: 3.8",
19+
"Programming Language :: Python :: 3.9",
20+
"Programming Language :: Python :: 3.10",
21+
"Programming Language :: Python :: 3.11",
22+
"Environment :: Web Environment",
23+
"Topic :: Software Development :: Libraries :: Python Modules",
24+
"Framework :: Django",
25+
"Framework :: Django :: 2.2",
26+
"Framework :: Django :: 3.2",
27+
"Framework :: Django :: 4.2",
28+
]
29+
dependencies = [
30+
"packaging",
31+
]
32+
dynamic = ["version", "readme"]
33+
34+
[project.urls]
35+
"Homepage" = "https://github.com/florimondmanca/djangorestframework-api-key"
36+
"Documentation" = "https://florimondmanca.github.io/djangorestframework-api-key/"
37+
38+
[tool.setuptools.dynamic]
39+
version = { attr = "rest_framework_api_key.__version__" }
40+
readme = { file = ["README.md", "CHANGELOG.md"], content-type = "text/markdown" }
41+
42+
[tool.ruff]
43+
select = ["E", "F", "I"]
44+
line-length = 88
45+
src = ["src", "test_project", "tests"]

Diff for: requirements.txt

+8-13
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,13 @@ twine
1414
wheel
1515

1616
# Tooling.
17-
autoflake
18-
black==22.3.0
19-
flake8
20-
flake8-bugbear
21-
flake8-comprehensions
22-
django-test-migrations==1.2.0
23-
isort==5.*
24-
mkdocs==1.3.0
25-
mkdocs-material==8.3.1
26-
pymdown-extensions==10.0
27-
mypy
28-
pytest==7.1.2
17+
black==23.9.1
18+
django-test-migrations==1.3.0
19+
mkdocs==1.5.2
20+
mkdocs-material==9.3.1
21+
pymdown-extensions==10.3
22+
mypy==1.5.1
23+
pytest==7.4.2
2924
pytest-django==4.5.2
3025
pytest-cov
31-
seed-isort-config
26+
ruff==0.0.289

Diff for: setup.cfg

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
[flake8]
2-
ignore = W503, E203, B305
3-
max-line-length = 88
4-
51
[mypy]
62
disallow_untyped_defs = True
73
ignore_missing_imports = True
84

9-
[tool:isort]
10-
profile = black
11-
known_third_party = test_project
12-
135
[tool:pytest]
146
testpaths = tests
157
addopts =
168
-rxXs
17-
--cov=rest_framework_api_key
18-
--cov=tests
9+
--cov=src
1910
--cov-report=term-missing
2011
--cov-fail-under=100

Diff for: setup.py

+2-54
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,3 @@
1-
import re
2-
from pathlib import Path
1+
from setuptools import setup
32

4-
from setuptools import find_packages, setup
5-
6-
7-
def get_version(package: str) -> str:
8-
version = (Path("src") / package / "__version__.py").read_text()
9-
match = re.search("__version__ = ['\"]([^'\"]+)['\"]", version)
10-
assert match is not None
11-
return match.group(1)
12-
13-
14-
def get_long_description() -> str:
15-
with open("README.md", encoding="utf8") as readme:
16-
with open("CHANGELOG.md", encoding="utf8") as changelog:
17-
return readme.read() + "\n\n" + changelog.read()
18-
19-
20-
setup(
21-
name="djangorestframework-api-key",
22-
version=get_version("rest_framework_api_key"),
23-
description="API key permissions for the Django REST Framework",
24-
long_description=get_long_description(),
25-
long_description_content_type="text/markdown",
26-
url="http://github.com/florimondmanca/djangorestframework-api-key",
27-
project_urls={
28-
"Documentation": "https://florimondmanca.github.io/djangorestframework-api-key/"
29-
},
30-
author="Florimond Manca",
31-
author_email="[email protected]",
32-
packages=find_packages("src"),
33-
package_dir={"": "src"},
34-
include_package_data=True,
35-
zip_safe=False,
36-
install_requires=["packaging"],
37-
python_requires=">=3.7",
38-
license="MIT",
39-
classifiers=[
40-
"Development Status :: 4 - Beta",
41-
"Operating System :: OS Independent",
42-
"Intended Audience :: Developers",
43-
"Programming Language :: Python :: 3 :: Only",
44-
"Programming Language :: Python :: 3.7",
45-
"Programming Language :: Python :: 3.8",
46-
"Programming Language :: Python :: 3.9",
47-
"Programming Language :: Python :: 3.10",
48-
"Environment :: Web Environment",
49-
"Topic :: Software Development :: Libraries :: Python Modules",
50-
"Framework :: Django",
51-
"Framework :: Django :: 2.2",
52-
"Framework :: Django :: 3.2",
53-
"Framework :: Django :: 4.2",
54-
],
55-
)
3+
setup() # Editable installs.

Diff for: src/rest_framework_api_key/__init__.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import django
1+
try:
2+
import django
3+
except ImportError: # pragma: no cover
4+
pass
5+
else:
6+
if django.VERSION < (3, 2): # pragma: no cover
7+
default_app_config = "rest_framework_api_key.apps.RestFrameworkApiKeyConfig"
28

3-
from .__version__ import __version__
4-
5-
if django.VERSION < (3, 2): # pragma: no cover
6-
default_app_config = "rest_framework_api_key.apps.RestFrameworkApiKeyConfig"
9+
__version__ = "2.3.0"
710

811
__all__ = ["__version__", "default_app_config"]

Diff for: src/rest_framework_api_key/__version__.py

-1
This file was deleted.

Diff for: src/rest_framework_api_key/crypto.py

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def verify(self, password: str, encoded: str) -> bool:
4545

4646

4747
class KeyGenerator:
48-
4948
preferred_hasher = Sha512ApiKeyHasher()
5049

5150
def __init__(self, prefix_length: int = 8, secret_key_length: int = 32):

Diff for: src/rest_framework_api_key/migrations/0001_initial.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class Migration(migrations.Migration):
7-
87
initial = True
98

109
dependencies = [] # type: ignore

Diff for: src/rest_framework_api_key/migrations/0002_auto_20190529_2243.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class Migration(migrations.Migration):
7-
87
dependencies = [("rest_framework_api_key", "0001_initial")]
98

109
operations = [

Diff for: src/rest_framework_api_key/migrations/0003_auto_20190623_1952.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class Migration(migrations.Migration):
7-
87
dependencies = [("rest_framework_api_key", "0002_auto_20190529_2243")]
98

109
operations = [

Diff for: src/rest_framework_api_key/migrations/0004_prefix_hashed_key.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
def populate_prefix_hashed_key(apps, schema_editor) -> None: # type: ignore
1111
model = apps.get_model(APP_NAME, MODEL_NAME)
1212

13-
for api_key in model.objects.using(schema_editor.connection.alias).all():
13+
for api_key in model.objects.using(
14+
schema_editor.connection.alias
15+
).all(): # pragma: nodj22
1416
prefix, _, hashed_key = api_key.id.partition(".")
1517
api_key.prefix = prefix
1618
api_key.hashed_key = hashed_key
1719
api_key.save()
1820

1921

2022
class Migration(migrations.Migration):
21-
2223
dependencies = DEPENDENCIES
2324

2425
operations = [

Diff for: src/rest_framework_api_key/migrations/0005_auto_20220110_1102.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class Migration(migrations.Migration):
7-
87
dependencies = [
98
("rest_framework_api_key", "0004_prefix_hashed_key"),
109
]

Diff for: test_project/heroes/migrations/0001_initial.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
class Migration(migrations.Migration):
8-
98
initial = True
109

1110
operations = [

Diff for: test_project/heroes/migrations/0002_prefix_hashed_key.py

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def populate_prefix_hashed_key(apps, schema_editor): # type: ignore
1818

1919

2020
class Migration(migrations.Migration):
21-
2221
dependencies = DEPENDENCIES
2322

2423
operations = [

Diff for: test_project/heroes/migrations/0003_alter_hero_id.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class Migration(migrations.Migration):
7-
87
dependencies = [
98
("heroes", "0002_prefix_hashed_key"),
109
]

Diff for: test_project/heroes/migrations/0004_auto_20220110_1102.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class Migration(migrations.Migration):
7-
87
dependencies = [
98
("heroes", "0003_alter_hero_id"),
109
]

0 commit comments

Comments
 (0)