From f420cbbbf1f3621848c5af06564c8e49f1fa6759 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Fri, 1 Mar 2024 14:11:18 +0100 Subject: [PATCH 1/3] Switch to `pyproject.toml` --- .bumpversion.cfg | 10 -- .flake8 | 4 + .github/workflows/ci.yml | 13 +- README.rst | 4 +- docs/CHANGELOG.rst | 19 --- docs/index.rst | 2 - docs/quickstart.rst | 2 +- pyproject.toml | 136 ++++++++++++++++++ setup.cfg | 111 -------------- setup.py | 3 - .../locale/nl/LC_MESSAGES/django.po | 2 +- tox.ini | 2 +- 12 files changed, 148 insertions(+), 160 deletions(-) delete mode 100644 .bumpversion.cfg create mode 100644 .flake8 delete mode 100644 docs/CHANGELOG.rst create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index b2f83c1..0000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,10 +0,0 @@ -[bumpversion] -commit = False -tag = False -current_version = 1.4.1 - -[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..7d1f091 --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +max-line-length=88 +exclude=env,.tox,doc +ignore=E203,W503 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fcb5a88..ebcd870 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,9 +18,7 @@ jobs: python: ['3.10', '3.11', '3.12'] django: ['3.2', '4.2'] exclude: - - python: '3.11' - django: '3.2' - - python: '3.12' + - python: ['3.11', '3.12'] django: '3.2' name: Run the test suite (Python ${{ matrix.python }}, Django ${{ matrix.django }}) @@ -58,13 +56,10 @@ jobs: with: python-version: '3.10' - - name: Build sdist and wheel + - name: Build 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 - with: - user: __token__ - password: ${{ secrets.PYPI_TOKEN }} diff --git a/README.rst b/README.rst index 251d666..b78b247 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,6 @@ django-simple-certmanager :Version: 1.4.1 :Source: https://github.com/maykinmedia/django-simple-certmanager :Keywords: certificates -:PythonVersion: 3.9 |build-status| |code-quality| |black| |coverage| |docs| @@ -31,8 +30,7 @@ Installation Requirements ------------ -* Python 3.7 or above -* setuptools 30.3.0 or above +* Python 3.10 or above * Django 3.2 or newer diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst deleted file mode 100644 index 52a6123..0000000 --- a/docs/CHANGELOG.rst +++ /dev/null @@ -1,19 +0,0 @@ -========= -Changelog -========= - -1.0.0 (2022-08-29) -================== - -Initial version of django-simple-certmanager. - -This library allows you to manage TLS certificates (and keys) through the Django admin, -in a secure way. Your own code can then include references to the -``simple_certmanager.Certificate`` model. - -.. note:: This library is extracted out of the `zgw-consumers`_ library. - -Credits to Silvia Amabilino for the initial work and Ewen Le Guilly for splitting it into a -separate package. - -.. _zgw-consumers: https://pypi.org/project/zgw-consumers/ diff --git a/docs/index.rst b/docs/index.rst index f8b3d0f..4e29345 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -25,7 +25,6 @@ Features quickstart commands - CHANGELOG Indices and tables @@ -61,4 +60,3 @@ Indices and tables .. |pypi-version| image:: https://img.shields.io/pypi/v/django-simple-certmanager.svg :target: https://pypi.org/project/django-simple-certmanager/ - diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 36902f0..11f144f 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -4,7 +4,7 @@ Quickstart Requirements ------------ -* Python 3.7 or newer +* Python 3.10 or newer * Django 3.2 or newer Installation diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4744f93 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,136 @@ +[build-system] +requires = ["setuptools>=61.0.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "django-simple-certmanager" +version = "1.4.1" +description = "Manage TLS certificates and keys in the Django admin" +authors = [ + {name = "Maykin Media", email = "support@maykinmedia.nl"} +] +readme = "README.rst" +license = {file = "LICENSE"} +keywords = ["django", "certificate", "security"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Framework :: Django", + "Framework :: Django :: 3.2", + "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", + "Topic :: Software Development :: Libraries :: Python Modules", +] +requires-python = ">=3.10" +dependencies = [ + "django>=3.2", + "django-privates>=1.5", + "cryptography>=35.0.0", + "certifi", +] + +[project.urls] +Homepage = "https://github.com/maykinmedia/django-simple-certmanager" +Documentation = "http://django-simple-certmanager.readthedocs.io/en/latest/" +"Bug Tracker" = "https://github.com/maykinmedia/django-simple-certmanager/issues" +"Source Code" = "https://github.com/maykinmedia/django-simple-certmanager" +Changelog = "https://github.com/maykinmedia/django-simple-certmanager/blob/main/docs/CHANGELOG.rst" + +[project.optional-dependencies] +db = [ + "psycopg2", +] +drf = [ + "djangorestframework", +] +# These are not the test requirements! They are extras to be installed when making use of `simple_certmanager.test` +testutils = [ + "factory-boy", +] +tests = [ + "pytest", + "pytest-django", + "pyquery", + "tox", + "isort", + "black", + "flake8", + "freezegun", + "django-stubs[compatible-mypy]", +] +coverage = [ + "pytest-cov", +] +docs = [ + "sphinx", + "sphinx-rtd-theme", +] +release = [ + "bump-my-version", +] + +[tool.setuptools.packages.find] +include = ["simple_certmanager*"] +namespaces = false + +[tool.isort] +profile = "black" +combine_as_imports = true +known_django = "django" +known_first_party="simple_certmanager" +sections=["FUTURE", "STDLIB", "DJANGO", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"] +skip = ["env", ".tox", ".history"] + +[tool.pytest.ini_options] +testpaths = ["tests"] +DJANGO_SETTINGS_MODULE = "testapp.settings" + +[tool.bumpversion] +current_version = "1.4.1" +files = [ + {filename = "pyproject.toml"}, + {filename = "README.rst"}, + {filename = "simple_certmanager/locale/nl/LC_MESSAGES/django.po"}, + {filename = "docs/conf.py"}, +] + +[tool.coverage.run] +branch = true +source = [ + "simple_certmanager" +] +omit = [ + "simple_certmanager/migrations/*", +] + +[tool.coverage.report] +exclude_also = [ + "if (typing\\.)?TYPE_CHECKING:", + "@(typing\\.)?overload", + "class .*\\(.*Protocol.*\\):", + "@(abc\\.)?abstractmethod", + "raise NotImplementedError", + "\\.\\.\\.", + "pass", +] +omit = [ + "simple_certmanager/migrations/*", +] + +[tool.coverage.html] +directory = "cover" + +[tool.mypy] +plugins = ["mypy_django_plugin.main"] + +[[tool.mypy.overrides]] +module = "factory" +# typing support for factory-boy *is* coming +ignore_missing_imports = true + +[tool.django-stubs] +django_settings_module = "testapp.settings" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index c905e52..0000000 --- a/setup.cfg +++ /dev/null @@ -1,111 +0,0 @@ -# setuptools config -# see http://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files -[metadata] -name = django-simple-certmanager -version = 1.4.1 -description = Manage TLS certificates and keys in the Django admin -long_description = file: README.rst -url = https://github.com/maykinmedia/django-simple-certmanager -project_urls = - Documentation = http://django-simple-certmanager.readthedocs.io/en/latest/ - Changelog = https://github.com/maykinmedia/django-simple-certmanager/blob/main/docs/CHANGELOG.rst - Bug Tracker = https://github.com/maykinmedia/django-simple-certmanager/issues - Source Code = https://github.com/maykinmedia/django-simple-certmanager -license = MIT -author = Maykin Media -author_email = support@maykinmedia.nl -keywords = certificate -classifiers = - Development Status :: 5 - Production/Stable - Framework :: Django - Framework :: Django :: 3.2 - 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.7 -install_requires = - django >= 3.2 - django-privates >= 1.5 - cryptography >= 35.0.0 - certifi -tests_require = - pytest - pytest-django - pyquery - tox - isort - black - flake8 - freezegun - django-stubs[compatible-mypy] - -[options.packages.find] -include = - simple_certmanager - simple_certmanager.* - -[options.extras_require] -testutils = - factory-boy -tests = - pytest - pytest-django - pyquery - tox - isort - black - flake8 - freezegun - django-stubs[compatible-mypy] -pep8 = flake8 -coverage = pytest-cov -docs = - sphinx - sphinx-rtd-theme -release = - bump2version - -# 3rd party configuration - -[aliases] -test=pytest - -[isort] -profile = black -combine_as_imports = true -known_django=django -known_first_party=simple_certmanager -sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER -skip = env,.tox,.history,.eggs - -[tool:pytest] -testpaths = tests -DJANGO_SETTINGS_MODULE=testapp.settings - -[pep8] -[flake8] -max-line-length=88 -exclude=env,.tox,doc -ignore=E203,W503 - -[mypy] -plugins = - mypy_django_plugin.main - -[mypy.plugins.django-stubs] -django_settings_module = "testapp.settings" - -[mypy-factory] -# typing support for factory-boy *is* coming -ignore_missing_imports = True diff --git a/setup.py b/setup.py deleted file mode 100644 index 6068493..0000000 --- a/setup.py +++ /dev/null @@ -1,3 +0,0 @@ -from setuptools import setup - -setup() diff --git a/simple_certmanager/locale/nl/LC_MESSAGES/django.po b/simple_certmanager/locale/nl/LC_MESSAGES/django.po index a18515a..8ba81eb 100644 --- a/simple_certmanager/locale/nl/LC_MESSAGES/django.po +++ b/simple_certmanager/locale/nl/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" +"Project-Id-Version: 1.4.1\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-08-29 08:08-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" diff --git a/tox.ini b/tox.ini index 0b9c851..1bc8a80 100644 --- a/tox.ini +++ b/tox.ini @@ -44,7 +44,7 @@ commands = isort --check-only --diff . [testenv:black] extras = tests skipsdist = True -commands = black --check simple_certmanager docs testapp tests setup.py +commands = black --check simple_certmanager docs testapp tests [testenv:flake8] extras = tests From 06099d31ad04248f044f9ff2718de2343f74f9a3 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Fri, 1 Mar 2024 14:35:57 +0100 Subject: [PATCH 2/3] Format with black --- tests/test_admin.py | 21 ++++++++++++--------- tests/test_certificates.py | 35 ++++++++++++++++++++--------------- tests/test_commands.py | 7 ++++--- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/tests/test_admin.py b/tests/test_admin.py index 3ea36a1..c33107e 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -44,9 +44,10 @@ def test_detail_view(temp_private_root, admin_client): The functionality for the private key is implemented and tested in django- privates, but we need to make sure that `private_media_no_download_fields` has actually been set in this library.""" - with open(TEST_FILES / "test.certificate", "r") as client_certificate_f, open( - TEST_FILES / "test.key", "r" - ) as key_f: + with ( + open(TEST_FILES / "test.certificate", "r") as client_certificate_f, + open(TEST_FILES / "test.key", "r") as key_f, + ): certificate = Certificate.objects.create( label="Test certificate", type=CertificateTypes.key_pair, @@ -101,9 +102,10 @@ def test_list_view_invalid_public_cert(temp_private_root, admin_client, caplog): def test_list_view_invalid_private_key(temp_private_root, admin_client, caplog): """Assert that `changelist_view` works if DB contains a corrupted private key""" url = reverse("admin:simple_certmanager_certificate_changelist") - with open(TEST_FILES / "test.certificate", "r") as client_certificate_f, open( - TEST_FILES / "invalid.certificate", "r" - ) as key_f: + with ( + open(TEST_FILES / "test.certificate", "r") as client_certificate_f, + open(TEST_FILES / "invalid.certificate", "r") as key_f, + ): Certificate.objects.create( label="Test certificate", type=CertificateTypes.key_pair, @@ -152,9 +154,10 @@ def test_detail_view_invalid_public_cert(temp_private_root, admin_client, caplog def test_detail_view_invalid_private_key(temp_private_root, admin_client, caplog): """Assert that `change_view` works if DB contains a corrupted private key""" - with open(TEST_FILES / "test.certificate", "r") as client_certificate_f, open( - TEST_FILES / "invalid.certificate", "r" - ) as key_f: + with ( + open(TEST_FILES / "test.certificate", "r") as client_certificate_f, + open(TEST_FILES / "invalid.certificate", "r") as key_f, + ): certificate = Certificate.objects.create( label="Test certificate", type=CertificateTypes.key_pair, diff --git a/tests/test_certificates.py b/tests/test_certificates.py index 552ee1d..c056da6 100644 --- a/tests/test_certificates.py +++ b/tests/test_certificates.py @@ -19,9 +19,10 @@ @temp_private_root() class CertificateTests(TestCase): def test_calculated_properties(self): - with open(TEST_FILES / "test.certificate", "r") as client_certificate_f, open( - TEST_FILES / "test.key", "r" - ) as key_f: + with ( + open(TEST_FILES / "test.certificate", "r") as client_certificate_f, + open(TEST_FILES / "test.key", "r") as key_f, + ): certificate = Certificate.objects.create( label="Test certificate", type=CertificateTypes.key_pair, @@ -46,9 +47,10 @@ def test_creating_empty_admin_detail(self): self.assertInHTML("Serial number:", form.as_p()) def test_creating_valid_key_pair(self): - with open(TEST_FILES / "test.certificate", "r") as client_certificate_f, open( - TEST_FILES / "test.key", "r" - ) as key_f: + with ( + open(TEST_FILES / "test.certificate", "r") as client_certificate_f, + open(TEST_FILES / "test.key", "r") as key_f, + ): form = CertificateAdminForm( data={ "label": "Test valid pair", @@ -99,9 +101,10 @@ def test_admin_validation_valid_certificate(self): self.assertTrue(form.is_valid()) def test_invalid_key_pair(self): - with open(TEST_FILES / "test.certificate", "r") as client_certificate_f, open( - TEST_FILES / "test2.key", "r" - ) as key_f: + with ( + open(TEST_FILES / "test.certificate", "r") as client_certificate_f, + open(TEST_FILES / "test2.key", "r") as key_f, + ): certificate = Certificate.objects.create( label="Test certificate", type=CertificateTypes.key_pair, @@ -112,9 +115,10 @@ def test_invalid_key_pair(self): self.assertFalse(certificate.is_valid_key_pair()) def test_valid_key_pair(self): - with open(TEST_FILES / "test.certificate", "r") as client_certificate_f, open( - TEST_FILES / "test.key", "r" - ) as key_f: + with ( + open(TEST_FILES / "test.certificate", "r") as client_certificate_f, + open(TEST_FILES / "test.key", "r") as key_f, + ): certificate = Certificate.objects.create( label="Test certificate", type=CertificateTypes.key_pair, @@ -136,9 +140,10 @@ def test_valid_key_pair_missing_key(self): def test_admin_changelist_doesnt_crash_on_missing_files(self): # Github #39 - with open(TEST_FILES / "test.certificate", "r") as client_certificate_f, open( - TEST_FILES / "test.key", "r" - ) as key_f: + with ( + open(TEST_FILES / "test.certificate", "r") as client_certificate_f, + open(TEST_FILES / "test.key", "r") as key_f, + ): certificate = Certificate.objects.create( label="Test certificate", type=CertificateTypes.key_pair, diff --git a/tests/test_commands.py b/tests/test_commands.py index 84962a3..fc9cdad 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -26,9 +26,10 @@ def remove_certs_archive(): self.addCleanup(remove_certs_archive) def test_dump_certificate_files(self): - with open(TEST_FILES / "test.certificate", "r") as client_certificate_f, open( - TEST_FILES / "test.key", "r" - ) as key_f: + with ( + open(TEST_FILES / "test.certificate", "r") as client_certificate_f, + open(TEST_FILES / "test.key", "r") as key_f, + ): certificate1 = Certificate.objects.create( label="Test certificate", type=CertificateTypes.key_pair, From 6149c288d3f24e91d925ca62fb91f05fd58ba6fa Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:27:55 +0100 Subject: [PATCH 3/3] Feedback --- .github/workflows/ci.yml | 4 +++- docs/CHANGELOG.rst | 3 +++ docs/index.rst | 1 + pyproject.toml | 10 ++-------- 4 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 docs/CHANGELOG.rst diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebcd870..d7ea763 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,9 @@ jobs: python: ['3.10', '3.11', '3.12'] django: ['3.2', '4.2'] exclude: - - python: ['3.11', '3.12'] + - python: '3.11' + django: '3.2' + - python: '3.12' django: '3.2' name: Run the test suite (Python ${{ matrix.python }}, Django ${{ matrix.django }}) diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst new file mode 100644 index 0000000..76888fe --- /dev/null +++ b/docs/CHANGELOG.rst @@ -0,0 +1,3 @@ +.. _changelog: + +.. include:: ../CHANGELOG.rst diff --git a/docs/index.rst b/docs/index.rst index 4e29345..8eefd7a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -25,6 +25,7 @@ Features quickstart commands + CHANGELOG Indices and tables diff --git a/pyproject.toml b/pyproject.toml index 4744f93..c54d35a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ classifiers = [ "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" @@ -30,7 +31,6 @@ dependencies = [ "django>=3.2", "django-privates>=1.5", "cryptography>=35.0.0", - "certifi", ] [project.urls] @@ -38,15 +38,9 @@ Homepage = "https://github.com/maykinmedia/django-simple-certmanager" Documentation = "http://django-simple-certmanager.readthedocs.io/en/latest/" "Bug Tracker" = "https://github.com/maykinmedia/django-simple-certmanager/issues" "Source Code" = "https://github.com/maykinmedia/django-simple-certmanager" -Changelog = "https://github.com/maykinmedia/django-simple-certmanager/blob/main/docs/CHANGELOG.rst" +Changelog = "https://github.com/maykinmedia/django-simple-certmanager/blob/main/CHANGELOG.rst" [project.optional-dependencies] -db = [ - "psycopg2", -] -drf = [ - "djangorestframework", -] # These are not the test requirements! They are extras to be installed when making use of `simple_certmanager.test` testutils = [ "factory-boy",