From d3d208209dcb131b82255fa8f56311fdb9cc0278 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Fri, 23 Feb 2024 17:38:52 +0100 Subject: [PATCH 1/2] Switch to `pyproject.toml` --- .bumpversion.cfg | 10 --- .flake8 | 3 + .github/workflows/ci.yml | 4 +- pyproject.toml | 128 ++++++++++++++++++++++++++++++++++++ setup.cfg | 136 --------------------------------------- setup.py | 3 - tox.ini | 6 +- 7 files changed, 136 insertions(+), 154 deletions(-) delete mode 100644 .bumpversion.cfg create mode 100644 .flake8 create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100755 setup.py diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index d114fed..0000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,10 +0,0 @@ -[bumpversion] -commit = False -tag = False -current_version = 0.15.0 - -[bumpversion:file:setup.cfg] - -[bumpversion:file:README.rst] - -[bumpversion:file:docs/conf.py] diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..6e29ba0 --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +max-line-length=88 +exclude=env,.tox,doc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b44ed5..27560ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,8 +75,8 @@ jobs: - name: Build sdist and wheel run: | - pip install pip setuptools wheel --upgrade - python setup.py sdist bdist_wheel + pip install build --upgrade + python -m build - name: Publish a Python distribution to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a54e4f3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,128 @@ +[build-system] +requires = ["setuptools>=61.0.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "django-digid-eherkenning" +version = "0.15.0" +description = "A Django app for DigiD/eHerkenning authentication flows" +authors = [ + {name = "Maykin Media", email = "support@maykinmedia.nl"} +] +readme = "README.rst" +license = {file = "LICENSE"} +keywords = ["django", "authentication", "digid", "eherkenning", "eidas", "dutch", "nl", "netherlands"] +classifiers = [ + "Development Status :: 4 - Beta", + "Framework :: Django", + "Framework :: Django :: 4.2", + "Intended Audience :: Developers", + "Operating System :: Unix", + "Operating System :: MacOS", + "Operating System :: Microsoft :: Windows", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Software Development :: Libraries :: Python Modules", +] +requires-python = ">=3.10" +dependencies = [ + "cryptography>=40.0.0", + "django>=4.2.0", + "django-sessionprofile", + "django-simple-certmanager", + "django-solo", + "lxml>=4.7.1", + "furl", + "maykin-python3-saml>=1.16.0", +] + +[project.urls] +Homepage = "https://github.com/maykinmedia/django-digid-eherkenning" +Documentation = "https://django-digid-eherkenning.readthedocs.io/en/latest/" +"Bug Tracker" = "https://github.com/maykinmedia/django-digid-eherkenning/issues" +"Source Code" = "https://github.com/maykinmedia/django-digid-eherkenning" +Changelog = "https://github.com/maykinmedia/django-digid-eherkenning/blob/master/CHANGELOG.rst" + +[project.optional-dependencies] +oidc = [ + "mozilla-django-oidc-db>=0.18.0", +] +tests = [ + "django-test-migrations", + "pytest", + "pytest-django", + "pytest-mock", + "responses", + "freezegun", + "tox", + "isort", + "black", + "flake8", +] +coverage = [ + "pytest-cov", +] +docs = [ + "sphinx", + "sphinx-rtd-theme", + "psycopg2", +] +release = [ + "bump-my-version", + "twine", +] + +[tool.setuptools.packages.find] +include = ["digid_eherkenning*"] +namespaces = false + +[tool.isort] +profile = "black" +combine_as_imports = true +known_django = "django" +known_first_party="digid_eherkenning" +sections=["FUTURE", "STDLIB", "DJANGO", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"] +skip = ["env", "node_modules", ".tox"] +skip_glob = ["**/migrations/**"] + +[tool.pytest.ini_options] +testpaths = ["tests"] +DJANGO_SETTINGS_MODULE = "tests.project.settings" +markers = [ + "callback: additional configuration for the callback fixture", + "mock_backend: class/claims to be returned by the mock backend fixture", +] + +[tool.bumpversion] +current_version = "0.15.0" +files = [ + {filename = "pyproject.toml"}, + {filename = "README.rst"}, + {filename = "docs/conf.py"}, +] + +[tool.coverage.run] +branch = true +source = [ + "digid_eherkenning" +] +omit = [ + # migrations run while django initializes the test db + "*/migrations/*", +] + +[tool.coverage.report] +skip_covered = true +exclude_also = [ + "if (typing\\.)?TYPE_CHECKING:", + "@(typing\\.)?overload", + "class .*\\(.*Protocol.*\\):", + "@(abc\\.)?abstractmethod", + "raise NotImplementedError", + "\\.\\.\\.", + "pass", +] +omit = [ + "*/migrations/*", +] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 326b799..0000000 --- a/setup.cfg +++ /dev/null @@ -1,136 +0,0 @@ -# setuptools config -# see http://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files -[metadata] -name = django-digid-eherkenning -version = 0.15.0 -description = A Django app for DigiD/eHerkenning authentication flows -long_description = file: README.rst -url = https://github.com/maykinmedia/django-digid-eherkenning -project_urls = - Changelog = https://github.com/maykinmedia/django-digid-eherkenning/blob/master/docs/CHANGELOG.rst - Bug Tracker = https://github.com/maykinmedia/django-digid-eherkenning/issues - Source Code = https://github.com/maykinmedia/django-digid-eherkenning -license = MIT -author = Maykin Media -author_email = support@maykinmedia.nl -keywords = django, authentication, digid, eherkenning, eidas, dutch, nl, netherlands -classifiers = - Development Status :: 4 - Beta - Framework :: Django - Framework :: Django :: 4.2 - Intended Audience :: Developers - Operating System :: Unix - Operating System :: MacOS - Operating System :: Microsoft :: Windows - Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.11 - Programming Language :: Python :: 3.12 - Topic :: Software Development :: Libraries :: Python Modules - -[options] -zip_safe = False -include_package_data = True -packages = find: -python_requires = >= 3.10 -install_requires = - cryptography >= 40.0.0 - django >= 4.2.0 - django-sessionprofile - django-simple-certmanager - django-solo - lxml >= 4.7.1 - furl - maykin-python3-saml >= 1.16.0 -tests_require = - django-test-migrations - freezegun - pytest - pytest-django - pytest-mock - responses - freezegun - tox - isort - black - -[options.packages.find] -include = - digid_eherkenning - digid_eherkenning.* - -[options.extras_require] -oidc = - mozilla-django-oidc-db >= 0.18.0 -tests = - django-test-migrations - pytest - pytest-django - pytest-mock - responses - freezegun - tox - isort - black -pep8 = flake8 -coverage = pytest-cov -docs = - sphinx - sphinx-rtd-theme - psycopg2 -release = - bump2version - twine - -# 3rd party configuration - -[aliases] -test=pytest - -[isort] -combine_as_imports = true -default_section = THIRDPARTY -include_trailing_comma = true -line_length = 88 -multi_line_output = 3 -force_grid_wrap = 0 -use_parentheses = True -ensure_newline_before_comments = True -skip = env,node_modules,.tox -skip_glob = **/migrations/** -known_django=django -known_first_party=digid_eherkenning -sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER - -[tool:pytest] -testpaths = tests -DJANGO_SETTINGS_MODULE=tests.project.settings -markers = - callback: additional configuration for the callback fixture - mock_backend: class/claims to be returned by the mock backend fixture - -[pep8] -max-line-length=88 -ignore=W293,W291,E501,E261 -exclude=migrations,static,media - -[flake8] -max-line-length=88 -exclude=env,.tox,doc - -[coverage:run] -branch = True -source = digid_eherkenning -omit = - # migrations run while django initializes the test db - */migrations/* - -[coverage:report] -skip_covered = True -exclude_also = - if (typing\.)?TYPE_CHECKING: - @(typing\.)?overload - class .*\(.*Protocol.*\): - @(abc\.)?abstractmethod - raise NotImplementedError - \.\.\. - pass diff --git a/setup.py b/setup.py deleted file mode 100755 index 6068493..0000000 --- a/setup.py +++ /dev/null @@ -1,3 +0,0 @@ -from setuptools import setup - -setup() diff --git a/tox.ini b/tox.ini index 074d309..58fd0cc 100644 --- a/tox.ini +++ b/tox.ini @@ -38,7 +38,7 @@ deps = django42: Django~=4.2 oidcenabled: psycopg commands = - py.test tests \ + pytest tests \ --cov --cov-report xml:reports/coverage-{envname}.xml \ {posargs} @@ -50,7 +50,7 @@ commands = isort --check-only --diff . [testenv:black] extras = tests skipsdist = True -commands = black --check digid_eherkenning tests setup.py +commands = black --check digid_eherkenning tests [testenv:docs] basepython=python @@ -63,6 +63,6 @@ extras = deps = psycopg commands= - py.test check_sphinx.py -v \ + pytest check_sphinx.py -v \ --tb=auto \ {posargs} From d2661ef450555edd2760aba4bf61056b79376b0f Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Mon, 24 Jun 2024 22:23:26 +0200 Subject: [PATCH 2/2] Apply black and isort --- digid_eherkenning/backends.py | 2 +- .../0004_alter_eherkenningconfiguration_loa.py | 4 +++- ...figuration_eh_service_instance_uuid_and_more.py | 3 ++- ...dconfiguration_metadata_file_source_and_more.py | 1 + ...kenningconfiguration_service_description_url.py | 1 + digid_eherkenning/mock/backends.py | 2 +- digid_eherkenning/saml2/base.py | 7 ++++--- digid_eherkenning/saml2/eherkenning.py | 7 ++++--- tests/conftest.py | 14 ++++++++------ 9 files changed, 25 insertions(+), 16 deletions(-) diff --git a/digid_eherkenning/backends.py b/digid_eherkenning/backends.py index b9d40d1..23d138e 100644 --- a/digid_eherkenning/backends.py +++ b/digid_eherkenning/backends.py @@ -102,7 +102,7 @@ class DigiDBackend(BSNBackendMixin, BaseSaml2Backend): BaseSaml2Backend.error_messages, **{ "digid_no_bsn": _("Login failed due to no BSN being returned by DigiD."), - } + }, ) def authenticate(self, request, digid=None, saml_art=None, errors=[]): diff --git a/digid_eherkenning/migrations/0004_alter_eherkenningconfiguration_loa.py b/digid_eherkenning/migrations/0004_alter_eherkenningconfiguration_loa.py index da7f366..2538467 100644 --- a/digid_eherkenning/migrations/0004_alter_eherkenningconfiguration_loa.py +++ b/digid_eherkenning/migrations/0004_alter_eherkenningconfiguration_loa.py @@ -1,7 +1,9 @@ # Generated by Django 4.2.4 on 2023-08-15 13:47 -import digid_eherkenning.choices from django.db import migrations, models + +import digid_eherkenning.choices + from ..choices import AssuranceLevels diff --git a/digid_eherkenning/migrations/0005_alter_eherkenningconfiguration_eh_service_instance_uuid_and_more.py b/digid_eherkenning/migrations/0005_alter_eherkenningconfiguration_eh_service_instance_uuid_and_more.py index f33849b..cd2f44a 100644 --- a/digid_eherkenning/migrations/0005_alter_eherkenningconfiguration_eh_service_instance_uuid_and_more.py +++ b/digid_eherkenning/migrations/0005_alter_eherkenningconfiguration_eh_service_instance_uuid_and_more.py @@ -1,8 +1,9 @@ # Generated by Django 4.2.4 on 2023-09-01 09:23 -from django.db import migrations, models import uuid +from django.db import migrations, models + class Migration(migrations.Migration): dependencies = [ diff --git a/digid_eherkenning/migrations/0006_digidconfiguration_metadata_file_source_and_more.py b/digid_eherkenning/migrations/0006_digidconfiguration_metadata_file_source_and_more.py index 411f548..3104403 100644 --- a/digid_eherkenning/migrations/0006_digidconfiguration_metadata_file_source_and_more.py +++ b/digid_eherkenning/migrations/0006_digidconfiguration_metadata_file_source_and_more.py @@ -1,6 +1,7 @@ # Generated by Django 4.2.6 on 2023-10-20 08:40 from django.db import migrations, models + import privates.fields import privates.storages diff --git a/digid_eherkenning/migrations/0007_eherkenningconfiguration_service_description_url.py b/digid_eherkenning/migrations/0007_eherkenningconfiguration_service_description_url.py index ad4d532..52e31bf 100644 --- a/digid_eherkenning/migrations/0007_eherkenningconfiguration_service_description_url.py +++ b/digid_eherkenning/migrations/0007_eherkenningconfiguration_service_description_url.py @@ -1,6 +1,7 @@ # Generated by Django 4.2.10 on 2024-03-04 13:08 from django.db import migrations, models + import digid_eherkenning.models.eherkenning diff --git a/digid_eherkenning/mock/backends.py b/digid_eherkenning/mock/backends.py index d8906f5..9b31d44 100644 --- a/digid_eherkenning/mock/backends.py +++ b/digid_eherkenning/mock/backends.py @@ -19,7 +19,7 @@ class DigiDBackend(BSNBackendMixin, BaseBackend): "digid_no_bsn": _("Login failed due to no BSN being returned by DigiD."), "digid_len_bsn": _("Login failed due to no BSN having more then 9 digits."), "digid_num_bsn": _("Login failed due to no BSN not being numerical."), - } + }, ) def authenticate(self, request, bsn=None): diff --git a/digid_eherkenning/saml2/base.py b/digid_eherkenning/saml2/base.py index 8e79ae5..00cb81d 100644 --- a/digid_eherkenning/saml2/base.py +++ b/digid_eherkenning/saml2/base.py @@ -224,9 +224,10 @@ def create_config_dict(self, conf): service_description = get_service_description(conf) requested_attributes = get_requested_attributes(conf) - with conf["cert_file"].open("r") as cert_file, conf["key_file"].open( - "r" - ) as key_file: + with ( + conf["cert_file"].open("r") as cert_file, + conf["key_file"].open("r") as key_file, + ): certificate = cert_file.read() privkey = key_file.read() diff --git a/digid_eherkenning/saml2/eherkenning.py b/digid_eherkenning/saml2/eherkenning.py index 11521fb..2db7efb 100644 --- a/digid_eherkenning/saml2/eherkenning.py +++ b/digid_eherkenning/saml2/eherkenning.py @@ -469,9 +469,10 @@ def create_config_dict(self, conf: EHerkenningConfig) -> EHerkenningSAMLConfig: config_dict: EHerkenningSAMLConfig = super().create_config_dict(conf) attribute_consuming_services = create_attribute_consuming_services(conf) - with conf["cert_file"].open("r") as cert_file, conf["key_file"].open( - "r" - ) as key_file: + with ( + conf["cert_file"].open("r") as cert_file, + conf["key_file"].open("r") as key_file, + ): certificate = cert_file.read() privkey = key_file.read() acs_url = furl(conf["base_url"]) / conf["acs_path"] diff --git a/tests/conftest.py b/tests/conftest.py index aa07c2f..32c0bfc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -68,9 +68,10 @@ def temp_private_root(tmp_path, settings): @pytest.fixture def digid_certificate(temp_private_root) -> Certificate: - with DIGID_TEST_KEY_FILE.open("rb") as privkey, DIGID_TEST_CERTIFICATE_FILE.open( - "rb" - ) as cert: + with ( + DIGID_TEST_KEY_FILE.open("rb") as privkey, + DIGID_TEST_CERTIFICATE_FILE.open("rb") as cert, + ): certificate, created = Certificate.objects.get_or_create( label="DigiD Tests", defaults={"type": CertificateTypes.key_pair}, @@ -104,9 +105,10 @@ def digid_config(digid_config_defaults): @pytest.fixture def eherkenning_certificate(temp_private_root) -> Certificate: - with EHERKENNING_TEST_KEY_FILE.open( - "rb" - ) as privkey, EHERKENNING_TEST_CERTIFICATE_FILE.open("rb") as cert: + with ( + EHERKENNING_TEST_KEY_FILE.open("rb") as privkey, + EHERKENNING_TEST_CERTIFICATE_FILE.open("rb") as cert, + ): certificate, created = Certificate.objects.get_or_create( label="eHerkenning Tests", defaults={"type": CertificateTypes.key_pair},