Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade tooling, including dealing w/ Python 3.7 EOL #247

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .coveragerc_dj22
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[report]
exclude_lines =
pragma: no cover
pragma: nodj22
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
24 changes: 11 additions & 13 deletions ci/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ 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
- container: pg15
image: postgres:15-alpine
ports:
- 5432:5432
env:
Expand All @@ -34,36 +34,34 @@ 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.*"
PYTEST_ADDOPTS: "--cov-config=.coveragerc_dj22"

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.*"
PYTEST_ADDOPTS: "--cov=tests"

py310_postgres:
py311_postgres:
services:
postgres: pg11
postgres: pg15
variables:
DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/default"

Expand Down
6 changes: 3 additions & 3 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

### Installation

Install from PyPI:
Install with `pip`:

```bash
pip install djangorestframework-api-key
pip install "djangorestframework-api-key==2.*"
```

**Note**: this package requires Python 3.7+, Django 2.0+ and Django REST Framework 3.8+.
_**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._

### Project setup

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.8"
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
11 changes: 1 addition & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
[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=tests
--cov=src
--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 @@ -10,15 +10,16 @@
def populate_prefix_hashed_key(apps, schema_editor) -> None: # type: ignore
model = apps.get_model(APP_NAME, MODEL_NAME)

for api_key in model.objects.using(schema_editor.connection.alias).all():
for api_key in model.objects.using(
schema_editor.connection.alias
).all(): # pragma: nodj22
prefix, _, hashed_key = api_key.id.partition(".")
api_key.prefix = prefix
api_key.hashed_key = hashed_key
api_key.save()


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
Loading