From a4b89033de5e88589ae80906c120f37bb579382a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szil=C3=A1rd=20Pfeiffer?= Date: Sat, 9 Nov 2024 12:30:52 +0100 Subject: [PATCH] chore!: Switch to pyproject.toml (#27) --- .flake8 | 2 + .gitignore | 3 +- .gitlab-ci.yml | 9 ++- .pylintrc | 13 ++-- .readthedocs.yaml | 6 +- CONTRIBUTING.md | 2 +- MANIFEST.in | 1 - cryptodatahub/__setup__.py | 16 +++-- cryptodatahub/common/stores.py | 3 +- cryptodatahub/common/types.py | 6 +- dev-requirements.txt | 4 -- docs-requirements.txt | 2 - pyproject.toml | 110 +++++++++++++++++++++++++++++ requirements.txt | 4 -- setup.py | 96 +------------------------ test/updaters/test_trust_stores.py | 12 ++-- tox.ini | 38 ---------- 17 files changed, 160 insertions(+), 167 deletions(-) create mode 100644 .flake8 delete mode 100644 dev-requirements.txt delete mode 100644 docs-requirements.txt create mode 100644 pyproject.toml delete mode 100644 requirements.txt mode change 100644 => 100755 setup.py delete mode 100644 tox.ini diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..6deafc2 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 120 diff --git a/.gitignore b/.gitignore index 76b2328..f023089 100644 --- a/.gitignore +++ b/.gitignore @@ -5,9 +5,10 @@ *.pyc +*.egg-info + /.coverage -/*.egg-info /.eggs /.tox /Pipfile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3e17bc7..6584f9f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,7 +6,7 @@ stages: - deploy before_script: -- pip install -r dev-requirements.txt +- pip install tox .[tests] pylint: image: python:3.12-slim @@ -63,7 +63,8 @@ coveralls: stage: deploy script: - pip install coveralls - - pip install -r requirements.txt + - pip install . + - pip install .[tests] - coverage run -m unittest -v -f - coveralls only: @@ -71,7 +72,9 @@ coveralls: - master obs: - image: coroner/python_obs + image: + name: coroner/python_obs + pull_policy: always stage: deploy variables: GIT_SUBMODULE_STRATEGY: recursive diff --git a/.pylintrc b/.pylintrc index 0f29cdb..957f841 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,13 +1,18 @@ -[BASIC] +[MAIN] -good-names = e,i +jobs=0 [MASTER] +load-plugins = pylint.extensions.no_self_use + [FORMAT] -max-line-length = 120 +max-line-length=120 [MESSAGES CONTROL] -disable = missing-docstring,too-few-public-methods,too-many-function-args +disable= + missing-docstring, + too-few-public-methods, + too-many-function-args, diff --git a/.readthedocs.yaml b/.readthedocs.yaml index dc0fa1e..a27f1e8 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -11,5 +11,7 @@ build: python: install: - - requirements: docs-requirements.txt - - requirements: requirements.txt + - method: pip + path: . + extra_requirements: + - docs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ac9f9e5..d22ca66 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -116,7 +116,7 @@ hosted at Bitbucket, self-hosted, or etc.) 3. `cd theproject` 4. [Create and activate a virtual environment](https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments). -5. Install the development requirements: `pip install -r dev-requirements.txt`. +5. Install the development requirements: `pip install .[tests]`. 6. Create a branch: `git checkout -b foo-the-bars 1.3`. #### Making your Changes diff --git a/MANIFEST.in b/MANIFEST.in index bb73d96..bb37a27 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1 @@ include *.rst -include requirements.txt diff --git a/cryptodatahub/__setup__.py b/cryptodatahub/__setup__.py index 801a871..a26a3f5 100644 --- a/cryptodatahub/__setup__.py +++ b/cryptodatahub/__setup__.py @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- -__title__ = 'CryptoDataHub' +import importlib.metadata + +metadata = importlib.metadata.metadata('cryptodatahub') + +__title__ = metadata['Name'] __technical_name__ = __title__.lower() -__version__ = '0.12.6' -__description__ = 'Repository of cryptography-related data' -__author__ = 'Szilárd Pfeiffer' -__author_email__ = 'coroner@pfeifferszilard.hu' +__version__ = metadata['Version'] +__description__ = metadata['Summary'] +__author__ = metadata['Author'] +__author_email__ = metadata['Author-email'] __url__ = 'https://gitlab.com/coroner/' + __technical_name__ -__license__ = 'MPL-2.0' +__license__ = metadata['License'] diff --git a/cryptodatahub/common/stores.py b/cryptodatahub/common/stores.py index dd8df4e..118f63e 100644 --- a/cryptodatahub/common/stores.py +++ b/cryptodatahub/common/stores.py @@ -41,7 +41,8 @@ class CertificateTransparencyOperator(CryptoDataParamsBase): class CertificateTransparencyLogDateTimeBase(CryptoDataParamsBase): - def _asdict_serializer(self, _, __, value): + @classmethod + def _asdict_serializer(cls, _, __, value): if isinstance(value, datetime.datetime): return value.strftime("%Y-%m-%dT%H:%M:%SZ") diff --git a/cryptodatahub/common/types.py b/cryptodatahub/common/types.py index a57baaf..94fbd7b 100644 --- a/cryptodatahub/common/types.py +++ b/cryptodatahub/common/types.py @@ -356,7 +356,8 @@ def get_init_attribute_names(cls): if attribute.init ] - def _asdict_filter(self, attribute, value): + @staticmethod + def _asdict_filter(attribute, value): if attribute.name.startswith('_'): return False @@ -365,7 +366,8 @@ def _asdict_filter(self, attribute, value): return True - def _asdict_serializer(self, _, __, value): + @classmethod + def _asdict_serializer(cls, _, __, value): if hasattr(value, '_asdict'): return getattr(value, '_asdict')() if isinstance(value, enum.Enum): diff --git a/dev-requirements.txt b/dev-requirements.txt deleted file mode 100644 index 6e2ef83..0000000 --- a/dev-requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -tox -coverage -pyfakefs -beautifulsoup4 diff --git a/docs-requirements.txt b/docs-requirements.txt deleted file mode 100644 index 8f31421..0000000 --- a/docs-requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -sphinx -sphinx-sitemap diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..3c6c71d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,110 @@ +[build-system] +requires = ['setuptools', 'setuptools-scm'] +build-backend = 'setuptools.build_meta' + +[project] +name = 'CryptoDataHub' +version = '0.12.6' +description = 'Repository of cryptography-related data' +authors = [ + {name = 'Szilárd Pfeiffer', email = 'coroner@pfeifferszilard.hu'} +] +maintainers = [ + {name = 'Szilárd Pfeiffer', email = 'coroner@pfeifferszilard.hu'} +] +classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Console', + 'Framework :: tox', + 'Intended Audience :: Information Technology', + 'Intended Audience :: Science/Research', + 'Intended Audience :: System Administrators', + 'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)', + 'Natural Language :: English', + 'Operating System :: MacOS', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', + 'Programming Language :: Python', + 'Topic :: Internet', + 'Topic :: Security', + 'Topic :: Security :: Cryptography', + 'Topic :: Software Development :: Libraries :: Python Modules', +] + +keywords=['ssl', 'tls', 'ssh', 'dns', 'dnssec'] +readme = {file = 'README.rst', content-type = 'text/x-rst'} +license = {text = 'MPL-2.0'} + +dependencies = [ + 'asn1crypto', + 'attrs', + 'python-dateutil', + 'urllib3', +] + +[project.optional-dependencies] +tests = [ + 'pyfakefs', + 'beautifulsoup4', +] +docs = [ + 'sphinx', + 'sphinx-sitemap', +] + +[project.urls] +Homepage = 'https://gitlab.com/coroner/cryptodatahub' +Changelog = 'https://cryptodatahub.readthedocs.io/en/latest/changelog' +Documentation = 'https://cryptodatahub.readthedocs.io/en/latest/' +Issues = 'https://gitlab.com/coroner/cryptodatahub/-/issues' +Source = 'https://gitlab.com/coroner/cryptodatahub' + +[tool.variables] +technical_name = 'cryptodatahub' + +[tool.setuptools] +license-files = ['LICENSE.txt'] + +[tool.setuptools.packages.find] +exclude = ['updaters'] + +[tool.setuptools.package-data] +cryptodatahub = [ + '*/*.json' +] + +[tool.tox] +envlist = [ + 'pep8', + 'pylint', + 'pypy3', + 'py39', + 'py310', + 'py311', + 'py312', + 'py313', + 'pythonrc', +] + +[tool.tox.env_run_base] +deps = ['coverage', '.[tests]'] +commands = [ + ['coverage', 'erase'], + ['coverage', 'run', '-m', 'unittest', 'discover', '-v'], + ['coverage', 'report'] +] + +[tool.tox.env.pep8] +deps = ['flake8'] +commands = [['flake8', 'cryptodatahub', 'docs', 'updaters', 'test']] + +[tool.tox.env.pylint] +deps = ['pylint', '.[tests]'] +commands = [['pylint', '--rcfile', '.pylintrc', 'cryptodatahub', 'docs', 'updaters', 'test']] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index f8962f6..0000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -asn1crypto -attrs -python-dateutil -urllib3 diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index 2133a99..5ec1dfb --- a/setup.py +++ b/setup.py @@ -1,97 +1,5 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -import codecs -import os -import unittest +import setuptools -from setuptools import setup - -from cryptodatahub import __setup__ - - -this_directory = os.getenv('REQUIREMENTS_DIR', '') -with open(os.path.join(this_directory, 'requirements.txt')) as f: - install_requirements = f.read().splitlines() -this_directory = os.path.abspath(os.path.dirname(__file__)) -with codecs.open(os.path.join(this_directory, 'README.rst'), encoding='utf-8') as f: - long_description = f.read() - - -def test_discover(): - test_loader = unittest.TestLoader() - test_suite = test_loader.discover('test', pattern='test_*.py') - return test_suite - - -setup( - name=__setup__.__title__, - version=__setup__.__version__, - description=__setup__.__description__, - long_description=long_description, - long_description_content_type='text/x-rst', - author=__setup__.__author__, - author_email=__setup__.__author_email__, - maintainer=__setup__.__author__, - maintainer_email=__setup__.__author_email__, - license=__setup__.__license__, - license_files=['LICENSE.txt', ], - project_urls={ - 'Homepage': __setup__.__url__, - 'Changelog': 'https://' + __setup__.__technical_name__ + '.readthedocs.io/en/latest/changelog', - 'Documentation': 'https://' + __setup__.__technical_name__ + '.readthedocs.io/en/latest/', - 'Issues': __setup__.__url__ + '/-/issues', - 'Source': __setup__.__url__, - }, - keywords='ssl tls ssh dns', - - install_requires=install_requirements, - extras_require={ - "test": ["coverage", ], - "pep8": ["flake8", ], - "pylint": ["pylint", ], - }, - - packages=[ - 'cryptodatahub', - 'cryptodatahub.common', - 'cryptodatahub.dnsrec', - 'cryptodatahub.ssh', - 'cryptodatahub.tls', - ], - - package_data={ - 'cryptodatahub.common': ['*.json'], - 'cryptodatahub.dnsrec': ['*.json'], - 'cryptodatahub.ssh': ['*.json'], - 'cryptodatahub.tls': ['*.json'], - }, - - test_suite='setup.test_discover', - - classifiers=[ - 'Development Status :: 4 - Beta', - 'Environment :: Console', - 'Framework :: tox', - 'Intended Audience :: Information Technology', - 'Intended Audience :: Science/Research', - 'Intended Audience :: System Administrators', - 'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)', - 'Natural Language :: English', - 'Operating System :: MacOS', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12', - 'Programming Language :: Python :: 3.13', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', - 'Programming Language :: Python', - 'Topic :: Internet', - 'Topic :: Security', - 'Topic :: Security :: Cryptography', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], -) +setuptools.setup() diff --git a/test/updaters/test_trust_stores.py b/test/updaters/test_trust_stores.py index 0748de7..14190dd 100644 --- a/test/updaters/test_trust_stores.py +++ b/test/updaters/test_trust_stores.py @@ -39,7 +39,8 @@ def setUp(self): self.public_key_x509_lets_encrypt = self._get_public_key_x509('letsencrypt_isrg_root_x1') self.public_key_x509_snakeoil_ca = self._get_public_key_x509('snakeoil_ca_cert') - def _get_mock_data_mozilla(self, public_keys=(), options=None): + @staticmethod + def _get_mock_data_mozilla(public_keys=(), options=None): mock_data = io.StringIO() dict_writer = csv.DictWriter( mock_data, FetcherRootCertificateStoreMozilla.CSV_FIELDS, @@ -55,7 +56,8 @@ def _get_mock_data_mozilla(self, public_keys=(), options=None): return mock_data.getvalue().encode('ascii') - def _get_mock_data_microsoft(self, public_keys=(), options=None): + @staticmethod + def _get_mock_data_microsoft(public_keys=(), options=None): mock_data = io.StringIO() dict_writer = csv.DictWriter( mock_data, FetcherRootCertificateStoreMicrosoft.CSV_FIELDS, @@ -72,7 +74,8 @@ def _get_mock_data_microsoft(self, public_keys=(), options=None): return mock_data.getvalue().encode('ascii') - def _get_mock_data_apple(self, public_keys=()): + @staticmethod + def _get_mock_data_apple(public_keys=()): mock_data = os.linesep.join([ '

Trusted Certificates

', '', @@ -97,7 +100,8 @@ def _get_mock_data_apple(self, public_keys=()): return mock_data.encode('ascii') - def _get_mock_data_google(self, public_keys=()): + @staticmethod + def _get_mock_data_google(public_keys=()): mock_data = io.BytesIO() with tarfile.open(fileobj=mock_data, mode='w:gz') as tar: diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 2772046..0000000 --- a/tox.ini +++ /dev/null @@ -1,38 +0,0 @@ -[metadata] -description-file = README.rst - -[tox] -envlist = - py{39,310,311,312,313} - pypy3 - pep8 - pylint - -[testenv] -extras = - test -setenv = - PYTHONPATH = {toxinidir} - REQUIREMENTS_DIR = {toxinidir} -commands = - coverage erase - coverage run -m unittest discover -v - coverage report -deps = - -rrequirements.txt - -rdev-requirements.txt - -[testenv:pep8] -extras = - pep8 -commands = - flake8 {posargs} cryptodatahub docs updaters test - -[testenv:pylint] -extras = - pylint -commands = - pylint -j0 -rn --rcfile=.pylintrc --disable=duplicate-code cryptodatahub docs updaters test - -[flake8] -max-line-length = 120