Skip to content

Commit 87ab359

Browse files
authored
Merge pull request #354 from jelmer/hatch
Migrate from pbr to hatch
2 parents 16991ea + 87cbf96 commit 87ab359

File tree

9 files changed

+100
-59
lines changed

9 files changed

+100
-59
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Install dependencies
3434
run: |
3535
python3 -m pip install --upgrade pip
36-
python3 -m pip install --upgrade setuptools wheel
36+
python3 -m pip install --upgrade setuptools wheel setuptools_scm
3737
python3 -m pip install sphinx
3838
python3 -m pip install ".[test,twisted]"
3939

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ AUTHORS
2121
ChangeLog
2222
.idea
2323
.tox
24+
testtools/_version.py
25+
man/testtools.1
26+
man

pyproject.toml

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,74 @@ module = [
88
"fixtures.*",
99
"testresources.*",
1010
"testscenarios.*",
11-
"pbr.*",
1211
]
1312
ignore_missing_imports = true
13+
14+
[build-system]
15+
requires = ["setuptools>=61"]
16+
build-backend = "setuptools.build_meta"
17+
18+
[project]
19+
name = "testtools"
20+
description = "Extensions to the Python standard library unit testing framework"
21+
readme = "doc/overview.rst"
22+
authors = [{name = "Jonathan M. Lange", email = "[email protected]"}]
23+
classifiers = [
24+
"Development Status :: 5 - Production/Stable",
25+
"Intended Audience :: Developers",
26+
"License :: OSI Approved :: MIT License",
27+
"Operating System :: OS Independent",
28+
"Programming Language :: Python",
29+
"Programming Language :: Python :: 3",
30+
"Programming Language :: Python :: 3.7",
31+
"Programming Language :: Python :: 3.8",
32+
"Programming Language :: Python :: 3.9",
33+
"Programming Language :: Python :: 3.10",
34+
"Programming Language :: Python :: 3.11",
35+
"Programming Language :: Python :: 3.12",
36+
"Programming Language :: Python :: 3 :: Only",
37+
"Programming Language :: Python :: Implementation :: CPython",
38+
"Programming Language :: Python :: Implementation :: PyPy",
39+
"Topic :: Software Development :: Libraries",
40+
"Topic :: Software Development :: Libraries :: Python Modules",
41+
"Topic :: Software Development :: Testing",
42+
]
43+
dependencies = ["setuptools; python_version>='3.12'"]
44+
dynamic = ["version"]
45+
requires-python = ">=3.7"
46+
47+
[project.urls]
48+
Homepage = "https://github.com/testing-cabal/testtools"
49+
50+
[tool.setuptools]
51+
include-package-data = false
52+
53+
[tool.setuptools.packages.find]
54+
include = ["testtools"]
55+
exclude = ["man*"]
56+
57+
[tool.extras]
58+
test = """
59+
testscenarios
60+
testresources"""
61+
twisted = """
62+
Twisted"""
63+
64+
[tool.files]
65+
packages = "testtools"
66+
67+
[tool.hatch.version]
68+
source = "vcs"
69+
70+
[tool.hatch.build.hooks.vcs]
71+
version-file = "testtools/_version.py"
72+
tag-pattern = "^(testtools-)?(?P<version>[0-9]+(\\.[0-9]+)*(-[0-9]+)?)(\\.post(?P<post>[0-9]+))?$"
73+
template = """\
74+
# This file is automatically generated by hatch.
75+
version = {version!r}
76+
__version__ = {version_tuple!r}
77+
"""
78+
79+
[project.optional-dependencies]
80+
test = ["testscenarios", "testresources"]
81+
twisted = ["Twisted", "fixtures"]

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
pbr>=0.11
21
fixtures>=2.0

setup.cfg

Lines changed: 0 additions & 41 deletions
This file was deleted.

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
#!/usr/bin/env python
22
import setuptools
33

4-
setuptools.setup(
5-
python_requires='>=3.7',
6-
setup_requires=['pbr'],
7-
pbr=True)
4+
setuptools.setup()

testtools/__init__.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
'TimestampingStreamResult',
4343
'try_import',
4444
'unique_text_generator',
45+
'version',
46+
'__version__',
4547
]
4648

4749
from testtools.helpers import try_import
@@ -107,7 +109,22 @@
107109
# established at this point, and setup.py will use a version of next-$(revno).
108110
# If the releaselevel is 'final', then the tarball will be major.minor.micro.
109111
# Otherwise it is major.minor.micro~$(revno).
110-
from pbr.version import VersionInfo
111-
_version = VersionInfo('testtools')
112-
__version__ = _version.semantic_version().version_tuple()
113-
version = _version.release_string()
112+
113+
try:
114+
# If setuptools_scm is installed (e.g. in a development environment with
115+
# an editable install), then use it to determine the version dynamically.
116+
from setuptools_scm import get_version
117+
118+
# This will fail with LookupError if the package is not installed in
119+
# editable mode or if Git is not installed.
120+
version = get_version(root="..", relative_to=__file__)
121+
__version__ = tuple(version.split('.'))
122+
except (ImportError, LookupError):
123+
# As a fallback, use the version that is hard-coded in the file.
124+
try:
125+
from ._version import (__version__, version)
126+
except ModuleNotFoundError:
127+
# The user is probably trying to run this without having installed
128+
# the package, so complain.
129+
raise RuntimeError(
130+
"Testtools is not correctly installed. Please install it with pip.")

testtools/tests/twistedsupport/test_matchers.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""Tests for Deferred matchers."""
44

55
from testtools.content import TracebackContent
6-
from testtools.helpers import try_import
76
from testtools.matchers import (
87
AfterPreprocessing,
98
Equals,
@@ -13,13 +12,10 @@
1312
from ._helpers import NeedsTwistedTestCase
1413

1514

16-
has_no_result = try_import('testtools.twistedsupport.has_no_result')
17-
failed = try_import('testtools.twistedsupport.failed')
18-
succeeded = try_import('testtools.twistedsupport.succeeded')
15+
from testtools.twistedsupport import has_no_result, failed, succeeded
1916

20-
21-
defer = try_import('twisted.internet.defer')
22-
Failure = try_import('twisted.python.failure.Failure')
17+
from twisted.internet import defer
18+
from twisted.python.failure import Failure
2319

2420

2521
def mismatches(description, details=None):

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ minversion = 1.6
66
usedevelop = True
77
deps =
88
sphinx
9+
setuptools>=61
10+
setuptools-scm
911
extras =
1012
test
1113
twisted

0 commit comments

Comments
 (0)