From f74eec60a5315b0aac5a4288bd3e8459421af47c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Wed, 1 Nov 2023 20:27:53 +0000 Subject: [PATCH 1/3] Migrate from pbr to hatch --- .github/workflows/test.yml | 2 +- .gitignore | 3 ++ pyproject.toml | 70 +++++++++++++++++++++++++++++++++++++- requirements.txt | 1 - setup.cfg | 41 ---------------------- setup.py | 5 +-- testtools/__init__.py | 25 +++++++++++--- tox.ini | 2 ++ 8 files changed, 97 insertions(+), 52 deletions(-) delete mode 100644 setup.cfg diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b74bba09..d80333df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: - name: Install dependencies run: | python3 -m pip install --upgrade pip - python3 -m pip install --upgrade setuptools wheel + python3 -m pip install --upgrade setuptools wheel setuptools_scm python3 -m pip install sphinx python3 -m pip install ".[test,twisted]" diff --git a/.gitignore b/.gitignore index 08224721..9f196a82 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ AUTHORS ChangeLog .idea .tox +testtools/_version.py +man/testtools.1 +man diff --git a/pyproject.toml b/pyproject.toml index e6c10209..7f95d278 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,74 @@ module = [ "fixtures.*", "testresources.*", "testscenarios.*", - "pbr.*", ] ignore_missing_imports = true + +[build-system] +requires = ["setuptools>=61"] +build-backend = "setuptools.build_meta" + +[project] +name = "testtools" +description = "Extensions to the Python standard library unit testing framework" +readme = "doc/overview.rst" +authors = [{name = "Jonathan M. Lange", email = "jml+testtools@mumak.net"}] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Software Development :: Testing", +] +dependencies = ["setuptools; python_version>='3.12'"] +dynamic = ["version"] +requires-python = ">=3.7" + +[project.urls] +Homepage = "https://github.com/testing-cabal/testtools" + +[tool.setuptools] +include-package-data = false + +[tool.setuptools.packages.find] +include = ["testtools"] +exclude = ["man*"] + +[tool.extras] +test = """ +testscenarios +testresources""" +twisted = """ +Twisted""" + +[tool.files] +packages = "testtools" + +[tool.hatch.version] +source = "vcs" + +[tool.hatch.build.hooks.vcs] +version-file = "testtools/_version.py" +tag-pattern = "^(testtools-)?(?P[0-9]+(\\.[0-9]+)*(-[0-9]+)?)(\\.post(?P[0-9]+))?$" +template = """\ +# This file is automatically generated by hatch. +version = {version!r} +__version__ = {version_tuple!r} +""" + +[project.optional-dependencies] +test = ["testscenarios", "testresources"] +twisted = ["Twisted"] diff --git a/requirements.txt b/requirements.txt index 4891b640..811aeed9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -pbr>=0.11 fixtures>=2.0 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index b501b2b2..00000000 --- a/setup.cfg +++ /dev/null @@ -1,41 +0,0 @@ -[metadata] -name = testtools -summary = Extensions to the Python standard library unit testing framework -home_page = https://github.com/testing-cabal/testtools -description_file = doc/overview.rst -author = Jonathan M. Lange -author_email = jml+testtools@mumak.net -classifier = - Development Status :: 5 - Production/Stable - Intended Audience :: Developers - License :: OSI Approved :: MIT License - Operating System :: OS Independent - Programming Language :: Python - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.11 - Programming Language :: Python :: 3.12 - Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: Implementation :: CPython - Programming Language :: Python :: Implementation :: PyPy - Topic :: Software Development :: Libraries - Topic :: Software Development :: Libraries :: Python Modules - Topic :: Software Development :: Testing - -[options] -install_requires = - # Purely to support the deprecated `TestCommand` until 3.0. - setuptools; python_version>='3.12' - -[extras] -test = - testscenarios - testresources -twisted = - Twisted - -[files] -packages = testtools diff --git a/setup.py b/setup.py index 52ba04de..61cc244b 100755 --- a/setup.py +++ b/setup.py @@ -1,7 +1,4 @@ #!/usr/bin/env python import setuptools -setuptools.setup( - python_requires='>=3.7', - setup_requires=['pbr'], - pbr=True) +setuptools.setup() diff --git a/testtools/__init__.py b/testtools/__init__.py index c36308d5..00b1920e 100644 --- a/testtools/__init__.py +++ b/testtools/__init__.py @@ -42,6 +42,8 @@ 'TimestampingStreamResult', 'try_import', 'unique_text_generator', + 'version', + '__version__', ] from testtools.helpers import try_import @@ -107,7 +109,22 @@ # established at this point, and setup.py will use a version of next-$(revno). # If the releaselevel is 'final', then the tarball will be major.minor.micro. # Otherwise it is major.minor.micro~$(revno). -from pbr.version import VersionInfo -_version = VersionInfo('testtools') -__version__ = _version.semantic_version().version_tuple() -version = _version.release_string() + +try: + # If setuptools_scm is installed (e.g. in a development environment with + # an editable install), then use it to determine the version dynamically. + from setuptools_scm import get_version + + # This will fail with LookupError if the package is not installed in + # editable mode or if Git is not installed. + version = get_version(root="..", relative_to=__file__) + __version__ = tuple(version.split('.')) +except (ImportError, LookupError): + # As a fallback, use the version that is hard-coded in the file. + try: + from ._version import (__version__, version) + except ModuleNotFoundError: + # The user is probably trying to run this without having installed + # the package, so complain. + raise RuntimeError( + "Testtools is not correctly installed. Please install it with pip.") diff --git a/tox.ini b/tox.ini index f7fa884b..5c529e86 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,8 @@ minversion = 1.6 usedevelop = True deps = sphinx + setuptools>=61 + setuptools-scm extras = test twisted From 34176e1647ef0d29be231bdf68b8ef30037a89c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Wed, 1 Nov 2023 20:49:39 +0000 Subject: [PATCH 2/3] Don't use try_import to make errors easier to debug --- testtools/tests/twistedsupport/test_matchers.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/testtools/tests/twistedsupport/test_matchers.py b/testtools/tests/twistedsupport/test_matchers.py index 1d02df2a..d7a7df47 100644 --- a/testtools/tests/twistedsupport/test_matchers.py +++ b/testtools/tests/twistedsupport/test_matchers.py @@ -3,7 +3,6 @@ """Tests for Deferred matchers.""" from testtools.content import TracebackContent -from testtools.helpers import try_import from testtools.matchers import ( AfterPreprocessing, Equals, @@ -13,13 +12,10 @@ from ._helpers import NeedsTwistedTestCase -has_no_result = try_import('testtools.twistedsupport.has_no_result') -failed = try_import('testtools.twistedsupport.failed') -succeeded = try_import('testtools.twistedsupport.succeeded') +from testtools.twistedsupport import has_no_result, failed, succeeded - -defer = try_import('twisted.internet.defer') -Failure = try_import('twisted.python.failure.Failure') +from twisted.internet import defer +from twisted.python.failure import Failure def mismatches(description, details=None): From 87cbf964b46f3bf2646983c4291596f315781a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Wed, 1 Nov 2023 20:55:21 +0000 Subject: [PATCH 3/3] Install fixtures --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7f95d278..66caf6f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,4 +78,4 @@ __version__ = {version_tuple!r} [project.optional-dependencies] test = ["testscenarios", "testresources"] -twisted = ["Twisted"] +twisted = ["Twisted", "fixtures"]