Skip to content

Commit

Permalink
Upgrade tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
florimondmanca committed Sep 12, 2023
1 parent f707b0c commit a495e8e
Show file tree
Hide file tree
Showing 23 changed files with 89 additions and 127 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@ venv.bak/
*.sqlite3

.idea/
.ruff_cache/
23 changes: 13 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
.PHONY: docs

venv = venv
bin = ${venv}/bin/
pysources = src/ test_project/ tests/

build:
${bin}python setup.py sdist bdist_wheel
${bin}twine check dist/*
rm -r build
${bin}python -m build

check:
${bin}black --check --diff --target-version=py36 ${pysources}
${bin}flake8 ${pysources}
${bin}ruff check ${pysources}
${bin}black --check --diff ${pysources}
${bin}mypy ${pysources}
${bin}isort --check --diff ${pysources}
make migrations-check

docs:
Expand All @@ -23,16 +22,20 @@ docs-serve:
docs-deploy:
${bin}mkdocs gh-deploy

install:
install: install-python

venv:
python3 -m venv ${venv}

install-python: venv
${bin}pip install -U pip wheel
${bin}pip install -U build
${bin}pip install -r requirements.txt
./tools/install_django.sh ${bin}pip

format:
${bin}autoflake --in-place --recursive ${pysources}
${bin}isort ${pysources}
${bin}black --target-version=py36 ${pysources}
${bin}ruff check --fix ${pysources}
${bin}black ${pysources}

migrations:
${bin}python -m tools.makemigrations
Expand Down
16 changes: 6 additions & 10 deletions ci/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resources:
type: github
endpoint: github
name: florimondmanca/azure-pipelines-templates
ref: refs/tags/5.0
ref: refs/tags/6.0
containers:
- container: pg11
image: postgres:11
Expand Down Expand Up @@ -34,34 +34,30 @@ stages:
jobs:
- template: job--python-check.yml@templates
parameters:
pythonVersion: "3.10"
pythonVersion: "3.11"

- template: job--python-docs-build.yml@templates
parameters:
pythonVersion: "3.10"
pythonVersion: "3.11"

- template: job--python-test.yml@templates
parameters:
jobs:
py37_dj22:
py38_dj22:
variables:
DJANGO_VERSION: "2.2.*"

py38_dj32:
variables:
DJANGO_VERSION: "3.2.*"

py310_dj32:
coverage: true
variables:
DJANGO_VERSION: "3.2.*"

py310_dj42:
py311_dj42:
coverage: true
variables:
DJANGO_VERSION: "4.2.*"

py310_postgres:
py311_postgres:
services:
postgres: pg11
variables:
Expand Down
45 changes: 45 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[build-system]
requires = ["setuptools", "setuptools-scm", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "djangorestframework-api-key"
description = "API key permissions for the Django REST Framework"
requires-python = ">=3.7"
license = { text = "MIT" }
authors = [
{ name = "Florimond Manca", email = "florimond.manca@protonmail.com" },
]
classifiers = [
"Development Status :: 4 - Beta",
"Operating System :: OS Independent",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Environment :: Web Environment",
"Topic :: Software Development :: Libraries :: Python Modules",
"Framework :: Django",
"Framework :: Django :: 2.2",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.2",
]
dependencies = [
"packaging",
]
dynamic = ["version", "readme"]

[project.urls]
"Homepage" = "https://github.com/florimondmanca/djangorestframework-api-key"
"Documentation" = "https://florimondmanca.github.io/djangorestframework-api-key/"

[tool.setuptools.dynamic]
version = { attr = "rest_framework_api_key.__version__" }
readme = { file = ["README.md", "CHANGELOG.md"], content-type = "text/markdown" }

[tool.ruff]
select = ["E", "F", "I"]
line-length = 88
src = ["src", "test_project", "tests"]
21 changes: 8 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@ twine
wheel

# Tooling.
autoflake
black==22.3.0
flake8
flake8-bugbear
flake8-comprehensions
django-test-migrations==1.2.0
isort==5.*
mkdocs==1.3.0
mkdocs-material==8.3.1
pymdown-extensions==10.0
mypy
pytest==7.1.2
black==23.9.1
django-test-migrations==1.3.0
mkdocs==1.5.2
mkdocs-material==9.3.1
pymdown-extensions==10.3
mypy==1.5.1
pytest==7.4.2
pytest-django==4.5.2
pytest-cov
seed-isort-config
ruff==0.0.289
10 changes: 1 addition & 9 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
[flake8]
ignore = W503, E203, B305
max-line-length = 88

[mypy]
disallow_untyped_defs = True
ignore_missing_imports = True

[tool:isort]
profile = black
known_third_party = test_project

[tool:pytest]
testpaths = tests
addopts =
-rxXs
--cov=rest_framework_api_key
--cov=src
--cov=tests
--cov-report=term-missing
--cov-fail-under=100
56 changes: 2 additions & 54 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,3 @@
import re
from pathlib import Path
from setuptools import setup

from setuptools import find_packages, setup


def get_version(package: str) -> str:
version = (Path("src") / package / "__version__.py").read_text()
match = re.search("__version__ = ['\"]([^'\"]+)['\"]", version)
assert match is not None
return match.group(1)


def get_long_description() -> str:
with open("README.md", encoding="utf8") as readme:
with open("CHANGELOG.md", encoding="utf8") as changelog:
return readme.read() + "\n\n" + changelog.read()


setup(
name="djangorestframework-api-key",
version=get_version("rest_framework_api_key"),
description="API key permissions for the Django REST Framework",
long_description=get_long_description(),
long_description_content_type="text/markdown",
url="http://github.com/florimondmanca/djangorestframework-api-key",
project_urls={
"Documentation": "https://florimondmanca.github.io/djangorestframework-api-key/"
},
author="Florimond Manca",
author_email="florimond.manca@gmail.com",
packages=find_packages("src"),
package_dir={"": "src"},
include_package_data=True,
zip_safe=False,
install_requires=["packaging"],
python_requires=">=3.7",
license="MIT",
classifiers=[
"Development Status :: 4 - Beta",
"Operating System :: OS Independent",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Environment :: Web Environment",
"Topic :: Software Development :: Libraries :: Python Modules",
"Framework :: Django",
"Framework :: Django :: 2.2",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.2",
],
)
setup() # Editable installs.
13 changes: 8 additions & 5 deletions src/rest_framework_api_key/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import django
try:
import django
except ImportError: # pragma: no cover
pass
else:
if django.VERSION < (3, 2): # pragma: no cover
default_app_config = "rest_framework_api_key.apps.RestFrameworkApiKeyConfig"

from .__version__ import __version__

if django.VERSION < (3, 2): # pragma: no cover
default_app_config = "rest_framework_api_key.apps.RestFrameworkApiKeyConfig"
__version__ = "2.3.0"

__all__ = ["__version__", "default_app_config"]
1 change: 0 additions & 1 deletion src/rest_framework_api_key/__version__.py

This file was deleted.

1 change: 0 additions & 1 deletion src/rest_framework_api_key/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def verify(self, password: str, encoded: str) -> bool:


class KeyGenerator:

preferred_hasher = Sha512ApiKeyHasher()

def __init__(self, prefix_length: int = 8, secret_key_length: int = 32):
Expand Down
1 change: 0 additions & 1 deletion src/rest_framework_api_key/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [] # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [("rest_framework_api_key", "0001_initial")]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [("rest_framework_api_key", "0002_auto_20190529_2243")]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def populate_prefix_hashed_key(apps, schema_editor) -> None: # type: ignore


class Migration(migrations.Migration):

dependencies = DEPENDENCIES

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("rest_framework_api_key", "0004_prefix_hashed_key"),
]
Expand Down
1 change: 0 additions & 1 deletion test_project/heroes/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

initial = True

operations = [
Expand Down
1 change: 0 additions & 1 deletion test_project/heroes/migrations/0002_prefix_hashed_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def populate_prefix_hashed_key(apps, schema_editor): # type: ignore


class Migration(migrations.Migration):

dependencies = DEPENDENCIES

operations = [
Expand Down
1 change: 0 additions & 1 deletion test_project/heroes/migrations/0003_alter_hero_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("heroes", "0002_prefix_hashed_key"),
]
Expand Down
1 change: 0 additions & 1 deletion test_project/heroes/migrations/0004_auto_20220110_1102.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("heroes", "0003_alter_hero_id"),
]
Expand Down
3 changes: 2 additions & 1 deletion test_project/project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@
# Password hashers

PASSWORD_HASHERS = [
"django.contrib.auth.hashers.Argon2PasswordHasher",
"django.contrib.auth.hashers.PBKDF2PasswordHasher",
"django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher",
"django.contrib.auth.hashers.Argon2PasswordHasher",
"django.contrib.auth.hashers.BCryptSHA256PasswordHasher",
"django.contrib.auth.hashers.ScryptPasswordHasher",
]


Expand Down
1 change: 1 addition & 0 deletions test_project/project/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView

from test_project.heroes.permissions import HasHeroAPIKey


Expand Down
Loading

0 comments on commit a495e8e

Please sign in to comment.