Skip to content

Commit 8dc76f8

Browse files
committed
Remove remnants of setuptools
We also move stuff around pyproject.toml to keep related things together and allow users to use the package without installing it or having setuptools_scm installed.. Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent ba2871b commit 8dc76f8

File tree

4 files changed

+54
-52
lines changed

4 files changed

+54
-52
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ jobs:
3232
3333
- name: Install dependencies
3434
run: |
35-
python -m pip install --upgrade pip
36-
python -m pip install --upgrade setuptools wheel setuptools_scm
35+
python -m pip install --upgrade pip wheel
3736
python -m pip install sphinx
3837
python -m pip install ".[test,twisted,dev]"
3938

pyproject.toml

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
[tool.mypy]
2-
warn_redundant_casts = true
3-
warn_unused_configs = true
4-
check_untyped_defs = true
5-
6-
[[tool.mypy.overrides]]
7-
module = [
8-
"fixtures.*",
9-
"testresources.*",
10-
"testscenarios.*",
11-
]
12-
ignore_missing_imports = true
13-
141
[build-system]
15-
requires = ["setuptools>=61", "hatchling", "hatch_vcs"]
2+
requires = ["hatchling", "hatch_vcs"]
163
build-backend = "hatchling.build"
174

185
[project]
@@ -38,22 +25,16 @@ classifiers = [
3825
"Topic :: Software Development :: Libraries :: Python Modules",
3926
"Topic :: Software Development :: Testing",
4027
]
41-
dependencies = ["setuptools; python_version>='3.12'"]
4228
dynamic = ["version"]
4329
requires-python = ">=3.9"
4430

4531
[project.urls]
4632
Homepage = "https://github.com/testing-cabal/testtools"
4733

48-
[tool.setuptools]
49-
include-package-data = false
50-
51-
[tool.setuptools.packages.find]
52-
include = ["testtools*"]
53-
exclude = ["man*"]
54-
55-
[tool.files]
56-
packages = "testtools"
34+
[project.optional-dependencies]
35+
test = ["testscenarios", "testresources"]
36+
twisted = ["Twisted", "fixtures"]
37+
dev = ["ruff==0.11.2"]
5738

5839
[tool.hatch.version]
5940
source = "vcs"
@@ -67,7 +48,15 @@ version = {version!r}
6748
__version__ = {version_tuple!r}
6849
"""
6950

70-
[project.optional-dependencies]
71-
test = ["testscenarios", "testresources"]
72-
twisted = ["Twisted", "fixtures"]
73-
dev = ["ruff==0.11.2"]
51+
[tool.mypy]
52+
warn_redundant_casts = true
53+
warn_unused_configs = true
54+
check_untyped_defs = true
55+
56+
[[tool.mypy.overrides]]
57+
module = [
58+
"fixtures.*",
59+
"testresources.*",
60+
"testscenarios.*",
61+
]
62+
ignore_missing_imports = true

setup.py

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

testtools/__init__.py

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,32 @@
9696
iterate_tests,
9797
)
9898

99+
100+
def __get_git_version():
101+
import os
102+
import subprocess
103+
104+
cwd = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir)
105+
106+
try:
107+
out = subprocess.check_output(
108+
["git", "describe"], stderr=subprocess.STDOUT, cwd=cwd
109+
)
110+
except (OSError, subprocess.CalledProcessError):
111+
return None
112+
113+
try:
114+
version = out.strip().decode("utf-8")
115+
except UnicodeDecodeError:
116+
return None
117+
118+
if "-" in version: # after tag
119+
# convert version-N-githash to version.postN+githash
120+
return version.replace("-", ".post", 1).replace("-g", "+git", 1)
121+
else:
122+
return version
123+
124+
99125
# same format as sys.version_info: "A tuple containing the five components of
100126
# the version number: major, minor, micro, releaselevel, and serial. All
101127
# values except releaselevel are integers; the release level is 'alpha',
@@ -109,21 +135,13 @@
109135
# Otherwise it is major.minor.micro~$(revno).
110136

111137
try:
112-
# If setuptools_scm is installed (e.g. in a development environment with
113-
# an editable install), then use it to determine the version dynamically.
114-
from setuptools_scm import get_version
115-
116-
# This will fail with LookupError if the package is not installed in
117-
# editable mode or if Git is not installed.
118-
version = get_version(root="..", relative_to=__file__)
119-
__version__ = tuple([int(v) if v.isdigit() else v for v in version.split(".")])
120-
except (ImportError, LookupError):
121-
# As a fallback, use the version that is hard-coded in the file.
122-
try:
123-
from ._version import __version__, version
124-
except ModuleNotFoundError:
125-
# The user is probably trying to run this without having installed
126-
# the package, so complain.
127-
raise RuntimeError(
128-
"Testtools is not correctly installed. Please install it with pip."
129-
)
138+
from ._version import __version__, version
139+
except ModuleNotFoundError:
140+
# package is not installed
141+
if version := __get_git_version():
142+
# we're in a git repo
143+
__version__ = tuple([int(v) if v.isdigit() else v for v in version.split(".")])
144+
else:
145+
# we're working with a tarball or similar
146+
version = "0.0.0"
147+
__version__ = (0, 0, 0)

0 commit comments

Comments
 (0)