Skip to content

Commit 7e867ad

Browse files
Merge pull request #929 from RonnyPfannschmidt/fix-918-drop-importlib-metadata-to-support-messed-no-binary
fix #918: remove the need for importlib_metadata in general
2 parents 65e7c56 + 26fc104 commit 7e867ad

File tree

7 files changed

+45
-36
lines changed

7 files changed

+45
-36
lines changed

CHANGELOG.rst

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v8.0.3
2+
======
3+
4+
* fix #918 for good - remove external importlib-metadata to avoid source only loop
5+
* fix #926: ensure mypy on python3.8 works with the version file
6+
17
v8.0.2
28
======
39

pyproject.toml

-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
[build-system]
44
build-backend = "_own_version_helper"
55
requires = [
6-
'importlib-metadata>=4.6; python_version < "3.10"',
76
"rich",
87
"setuptools>=61",
98
'tomli; python_version < "3.11"',
10-
'typing_extensions; python_version < "3.8"',
119
]
1210
backend-path = [
1311
".",
@@ -42,7 +40,6 @@ dynamic = [
4240
"version",
4341
]
4442
dependencies = [
45-
'importlib-metadata>=4.6; python_version < "3.10"',
4643
"packaging>=20",
4744
"setuptools",
4845
'tomli>=1; python_version < "3.11"',

src/setuptools_scm/_entrypoints.py

+28-28
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import cast
77
from typing import Iterator
88
from typing import overload
9-
from typing import Protocol
109
from typing import TYPE_CHECKING
1110

1211
from . import _log
@@ -17,15 +16,32 @@
1716
from ._config import Configuration, ParseFunction
1817

1918

20-
log = _log.log.getChild("entrypoints")
19+
from importlib.metadata import EntryPoint as EntryPoint
20+
21+
22+
if sys.version_info[:2] < (3, 10):
23+
from importlib.metadata import entry_points as legacy_entry_points
24+
25+
class EntryPoints:
26+
_groupdata: list[EntryPoint]
27+
28+
def __init__(self, groupdata: list[EntryPoint]) -> None:
29+
self._groupdata = groupdata
30+
31+
def select(self, name: str) -> EntryPoints:
32+
return EntryPoints([x for x in self._groupdata if x.name == name])
2133

34+
def __iter__(self) -> Iterator[EntryPoint]:
35+
return iter(self._groupdata)
2236

23-
class EntrypointProtocol(Protocol):
24-
name: str
25-
value: str
37+
def entry_points(group: str) -> EntryPoints:
38+
return EntryPoints(legacy_entry_points()[group])
2639

27-
def load(self) -> Any:
28-
pass
40+
else:
41+
from importlib.metadata import entry_points, EntryPoints
42+
43+
44+
log = _log.log.getChild("entrypoints")
2945

3046

3147
def version_from_entrypoint(
@@ -43,27 +59,11 @@ def version_from_entrypoint(
4359
return None
4460

4561

46-
if sys.version_info[:2] < (3, 10):
47-
from importlib_metadata import entry_points
48-
from importlib_metadata import EntryPoint
49-
else:
50-
from importlib.metadata import entry_points
51-
from importlib.metadata import EntryPoint
52-
53-
54-
def iter_entry_points(
55-
group: str, name: str | None = None
56-
) -> Iterator[EntrypointProtocol]:
57-
eps = entry_points(group=group)
58-
res = (
59-
eps
60-
if name is None
61-
else eps.select( # type: ignore [no-untyped-call]
62-
name=name,
63-
)
64-
)
62+
def iter_entry_points(group: str, name: str | None = None) -> Iterator[EntryPoint]:
63+
eps: EntryPoints = entry_points(group=group)
64+
res = eps if name is None else eps.select(name=name)
6565

66-
return cast(Iterator[EntrypointProtocol], iter(res))
66+
return iter(res)
6767

6868

6969
def _get_ep(group: str, name: str) -> Any | None:
@@ -76,7 +76,7 @@ def _get_ep(group: str, name: str) -> Any | None:
7676

7777
def _get_from_object_reference_str(path: str, group: str) -> Any | None:
7878
# todo: remove for importlib native spelling
79-
ep: EntrypointProtocol = EntryPoint(path, path, group)
79+
ep = EntryPoint(path, path, group)
8080
try:
8181
return ep.load()
8282
except (AttributeError, ModuleNotFoundError):

src/setuptools_scm/_integration/dump_version.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
".py": """\
1616
# file generated by setuptools_scm
1717
# don't change, don't track in version control
18-
from __future__ import annotations
18+
TYPE_CHECKING = False
19+
if TYPE_CHECKING:
20+
from typing import Tuple
1921
2022
__version__ = version = {version!r} # type: str
21-
__version_tuple__ = version_tuple = {version_tuple!r} # type: tuple[int | str, ...]
23+
__version_tuple__ = version_tuple = {version_tuple!r} # type: Tuple[int | str, ...]
2224
""",
2325
".txt": "{version}",
2426
}

src/setuptools_scm/discover.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def match_entrypoint(root: _t.PathT, name: str) -> bool:
4747

4848
def iter_matching_entrypoints(
4949
root: _t.PathT, entrypoint: str, config: Configuration
50-
) -> Iterable[_entrypoints.EntrypointProtocol]:
50+
) -> Iterable[_entrypoints.EntryPoint]:
5151
"""
5252
Consider different entry-points in ``root`` and optionally its parents.
5353
:param root: File path.

testing/test_basic_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def read(name: str) -> str:
182182
assert lines[-2:] == [
183183
"__version__ = version = '1.0.dev42' # type: str",
184184
"__version_tuple__ = version_tuple = (1, 0, 'dev42')"
185-
" # type: tuple[int | str, ...]",
185+
" # type: Tuple[int | str, ...]",
186186
]
187187

188188
version = "1.0.1+g4ac9d2c"

testing/test_functions.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ def test_dump_version_mypy(tmp_path: Path) -> None:
137137
if mypy is None:
138138
pytest.skip("mypy not found")
139139
dump_a_version(tmp_path)
140-
subprocess.run([mypy, "--strict", "VERSION.py"], cwd=tmp_path, check=True)
140+
subprocess.run(
141+
[mypy, "--python-version=3.8", "--strict", "VERSION.py"],
142+
cwd=tmp_path,
143+
check=True,
144+
)
141145

142146

143147
def test_dump_version_flake8(tmp_path: Path) -> None:

0 commit comments

Comments
 (0)