Skip to content

Commit ce7c2dc

Browse files
minimize bootstrap - fixes #722 and #723
enable self-bootstrap without typing_extensions and importlib_metadata they are still install requirements however
1 parent f807bfe commit ce7c2dc

File tree

14 files changed

+67
-32
lines changed

14 files changed

+67
-32
lines changed

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
[build-system]
22
requires = [
33
"setuptools>=45",
4-
"tomli>=1.0",
54
"packaging>=20.0",
6-
"typing_extensions",
7-
"importlib_metadata",
85
]
96
build-backend = "setuptools.build_meta"

src/setuptools_scm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from typing import Callable
1111
from typing import TYPE_CHECKING
1212

13-
from . import _types as _t
1413
from ._entrypoints import _call_entrypoint_fn
1514
from ._entrypoints import _version_from_entrypoints
1615
from ._overrides import _read_pretended_version_for
@@ -33,6 +32,7 @@
3332
if TYPE_CHECKING:
3433
from typing import NoReturn
3534

35+
from . import _types as _t
3636

3737
TEMPLATES = {
3838
".py": """\

src/setuptools_scm/_entrypoints.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66
from typing import overload
77
from typing import TYPE_CHECKING
88

9-
from typing_extensions import Protocol
10-
11-
from . import _types as _t
129
from .utils import function_has_arg
1310
from .utils import trace
1411
from .version import ScmVersion
1512

1613
if TYPE_CHECKING:
1714
from .config import Configuration
15+
from typing_extensions import Protocol
16+
from . import _types as _t
1817
else:
1918
Configuration = Any
2019

20+
class Protocol:
21+
pass
22+
2123

2224
class MaybeConfigFunction(Protocol):
2325
__name__: str
@@ -71,7 +73,17 @@ def _version_from_entrypoints(
7173
try:
7274
from importlib.metadata import entry_points # type: ignore
7375
except ImportError:
74-
from importlib_metadata import entry_points
76+
try:
77+
from importlib_metadata import entry_points
78+
except ImportError:
79+
from collections import defaultdict
80+
81+
def entry_points() -> dict[str, list[_t.EntrypointProtocol]]:
82+
warnings.warn(
83+
"importlib metadata missing, "
84+
"this may happen at build time for python3.7"
85+
)
86+
return defaultdict(list)
7587

7688

7789
def iter_entry_points(

src/setuptools_scm/_types.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import Any
44
from typing import Callable
55
from typing import List
6-
from typing import NamedTuple
76
from typing import TYPE_CHECKING
87
from typing import TypeVar
98
from typing import Union
@@ -22,12 +21,6 @@
2221
VERSION_SCHEME = Union[str, Callable[["version.ScmVersion"], str]]
2322

2423

25-
class CmdResult(NamedTuple):
26-
out: str
27-
err: str
28-
returncode: int
29-
30-
3124
class EntrypointProtocol(Protocol):
3225
name: str
3326

src/setuptools_scm/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
from typing import TYPE_CHECKING
1313
from typing import Union
1414

15-
from . import _types as _t
1615
from ._version_cls import NonNormalizedVersion
1716
from ._version_cls import Version
1817
from .utils import trace
1918

2019

2120
if TYPE_CHECKING:
21+
from . import _types as _t
2222
from setuptools_scm.version import ScmVersion
2323

2424
DEFAULT_TAG_REGEX = r"^(?:[\w-]+-)?(?P<version>[vV]?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)?$"

src/setuptools_scm/discover.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import os
44
from typing import Iterable
55
from typing import Iterator
6+
from typing import TYPE_CHECKING
67

7-
from . import _types as _t
8+
if TYPE_CHECKING:
9+
from . import _types as _t
810
from .config import Configuration
911
from .utils import trace
1012

src/setuptools_scm/git.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from typing import Callable
1212
from typing import TYPE_CHECKING
1313

14-
from . import _types as _t
1514
from .config import Configuration
1615
from .scm_workdir import Workdir
16+
from .utils import _CmdResult
1717
from .utils import data_from_mime
1818
from .utils import do_ex
1919
from .utils import require_command
@@ -23,6 +23,8 @@
2323
from .version import tags_to_versions
2424

2525
if TYPE_CHECKING:
26+
from . import _types as _t
27+
2628
from setuptools_scm.hg_git import GitWorkdirHgClient
2729

2830
REF_TAG_RE = re.compile(r"(?<=\btag: )([^,]+)\b")
@@ -72,7 +74,7 @@ def from_potential_worktree(cls, wd: _t.PathT) -> GitWorkdir | None:
7274

7375
return cls(real_wd)
7476

75-
def do_ex_git(self, cmd: list[str]) -> _t.CmdResult:
77+
def do_ex_git(self, cmd: list[str]) -> _CmdResult:
7678
return self.do_ex(["git", "--git-dir", join(self.path, ".git")] + cmd)
7779

7880
def is_dirty(self) -> bool:
@@ -120,7 +122,7 @@ def count_all_nodes(self) -> int:
120122
revs, _, _ = self.do_ex_git(["rev-list", "HEAD"])
121123
return revs.count("\n") + 1
122124

123-
def default_describe(self) -> _t.CmdResult:
125+
def default_describe(self) -> _CmdResult:
124126
git_dir = join(self.path, ".git")
125127
return self.do_ex(
126128
DEFAULT_DESCRIBE[:1] + ["--git-dir", git_dir] + DEFAULT_DESCRIBE[1:]

src/setuptools_scm/hacks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from __future__ import annotations
22

33
import os
4+
from typing import TYPE_CHECKING
45

5-
from . import _types as _t
6+
if TYPE_CHECKING:
7+
from . import _types as _t
68
from .config import Configuration
79
from .utils import data_from_mime
810
from .utils import trace

src/setuptools_scm/hg.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import datetime
44
import os
55
from pathlib import Path
6+
from typing import TYPE_CHECKING
67

7-
from . import _types as _t
88
from ._version_cls import Version
99
from .config import Configuration
1010
from .scm_workdir import Workdir
@@ -16,6 +16,9 @@
1616
from .version import ScmVersion
1717
from .version import tag_to_version
1818

19+
if TYPE_CHECKING:
20+
from . import _types as _t
21+
1922

2023
class HgWorkdir(Workdir):
2124

src/setuptools_scm/hg_git.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
from . import _types as _t
99
from .git import GitWorkdir
1010
from .hg import HgWorkdir
11+
from .utils import _CmdResult
1112
from .utils import do_ex
1213
from .utils import require_command
1314
from .utils import trace
1415

1516

16-
_FAKE_GIT_DESCRIBE_ERROR = _t.CmdResult("<>hg git failed", "", 1)
17+
_FAKE_GIT_DESCRIBE_ERROR = _CmdResult("<>hg git failed", "", 1)
1718

1819

1920
class GitWorkdirHgClient(GitWorkdir, HgWorkdir):
@@ -94,7 +95,7 @@ def count_all_nodes(self) -> int:
9495
revs, _, _ = self.do_ex(["hg", "log", "-r", "ancestors(.)", "-T", "."])
9596
return len(revs)
9697

97-
def default_describe(self) -> _t.CmdResult:
98+
def default_describe(self) -> _CmdResult:
9899
"""
99100
Tentative to reproduce the output of
100101
@@ -142,4 +143,4 @@ def default_describe(self) -> _t.CmdResult:
142143
if self.is_dirty():
143144
desc += "-dirty"
144145
trace("desc", desc)
145-
return _t.CmdResult(desc, "", 0)
146+
return _CmdResult(desc, "", 0)

0 commit comments

Comments
 (0)