Skip to content

Commit de08279

Browse files
remove bad deferred locgic from entrypoint selection
passing concrete objects instead of the boolean makes it way more safe
1 parent ff7693b commit de08279

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/setuptools_scm/_entrypoints.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from . import version
1414

1515
if TYPE_CHECKING:
16-
from ._config import Configuration
1716
from . import _types as _t
17+
from ._config import Configuration, ParseFunction
1818

1919

2020
log = _log.log.getChild("entrypoints")
@@ -27,21 +27,14 @@ def load(self) -> Any:
2727
pass
2828

2929

30-
def _version_from_entrypoints(
31-
config: Configuration, fallback: bool = False
30+
def version_from_entrypoint(
31+
config: Configuration, entrypoint: str, root: _t.PathT
3232
) -> version.ScmVersion | None:
33-
if fallback:
34-
entrypoint = "setuptools_scm.parse_scm_fallback"
35-
root = config.fallback_root
36-
else:
37-
entrypoint = "setuptools_scm.parse_scm"
38-
root = config.absolute_root
39-
4033
from .discover import iter_matching_entrypoints
4134

4235
log.debug("version_from_ep %s in %s", entrypoint, root)
4336
for ep in iter_matching_entrypoints(root, entrypoint, config):
44-
fn = ep.load()
37+
fn: ParseFunction = ep.load()
4538
maybe_version: version.ScmVersion | None = fn(root, config=config)
4639
log.debug("%s found %r", ep, maybe_version)
4740
if maybe_version is not None:

src/setuptools_scm/_get_version.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from typing import Pattern
99

1010
from . import _config
11+
from . import _entrypoints
1112
from . import _types as _t
1213
from ._config import Configuration
13-
from ._entrypoints import _version_from_entrypoints
1414
from ._overrides import _read_pretended_version_for
1515
from ._version_cls import _validate_version_cls
1616
from .version import format_version as _format_version
@@ -27,11 +27,15 @@ def parse_scm_version(config: Configuration) -> ScmVersion | None:
2727
)
2828
return parse_result
2929
else:
30-
return _version_from_entrypoints(config)
30+
entrypoint = "setuptools_scm.parse_scm"
31+
root = config.absolute_root
32+
return _entrypoints.version_from_entrypoint(config, entrypoint, root)
3133

3234

3335
def parse_fallback_version(config: Configuration) -> ScmVersion | None:
34-
return _version_from_entrypoints(config, fallback=True)
36+
entrypoint = "setuptools_scm.parse_scm_fallback"
37+
root = config.fallback_root
38+
return _entrypoints.version_from_entrypoint(config, entrypoint, root)
3539

3640

3741
def _do_parse(config: Configuration) -> ScmVersion | None:

0 commit comments

Comments
 (0)