Skip to content

Commit 10a96fb

Browse files
introduce DI for the inference config for theintegration points
1 parent f1ccfef commit 10a96fb

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/setuptools_scm/_integration/setuptools.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def version_keyword(
7070
value: bool | dict[str, Any] | Callable[[], dict[str, Any]],
7171
*,
7272
_given_pyproject_data: _t.GivenPyProjectResult = None,
73+
_get_version_inference_config: _t.GetVersionInferenceConfig = get_version_inference_config,
7374
) -> None:
7475
"""apply version infernce when setup(use_scm_version=...) is used
7576
this takes priority over the finalize_options based version
@@ -98,7 +99,7 @@ def version_keyword(
9899
log.debug("Configuration issue in pyproject.toml: %s", e)
99100
return
100101

101-
result = get_version_inference_config(
102+
result = _get_version_inference_config(
102103
dist_name=dist_name,
103104
current_version=dist.metadata.version,
104105
pyproject_data=pyproject_data,
@@ -113,6 +114,7 @@ def infer_version(
113114
dist: setuptools.Distribution,
114115
*,
115116
_given_pyproject_data: _t.GivenPyProjectResult = None,
117+
_get_version_inference_config: _t.GetVersionInferenceConfig = get_version_inference_config,
116118
) -> None:
117119
"""apply version inference from the finalize_options hook
118120
this is the default for pyproject.toml based projects that don't use the use_scm_version keyword
@@ -134,7 +136,7 @@ def infer_version(
134136
log.debug("Configuration issue in pyproject.toml: %s", e)
135137
return
136138

137-
result = get_version_inference_config(
139+
result = _get_version_inference_config(
138140
dist_name=dist_name,
139141
current_version=dist.metadata.version,
140142
pyproject_data=pyproject_data,

src/setuptools_scm/_types.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import TYPE_CHECKING
66
from typing import Callable
77
from typing import List
8+
from typing import Protocol
89
from typing import Sequence
910
from typing import Tuple
1011
from typing import Union
@@ -36,3 +37,24 @@
3637
GivenPyProjectResult: TypeAlias = Union[
3738
"PyProjectData", "InvalidTomlError", FileNotFoundError, None
3839
]
40+
41+
42+
class VersionInferenceApplicable(Protocol):
43+
"""A result object from version inference decision that can be applied to a dist."""
44+
45+
def apply(self, dist: object) -> None: # pragma: no cover - structural type
46+
...
47+
48+
49+
class GetVersionInferenceConfig(Protocol):
50+
"""Callable protocol for the decision function used by integration points."""
51+
52+
def __call__(
53+
self,
54+
dist_name: str | None,
55+
current_version: str | None,
56+
pyproject_data: PyProjectData,
57+
overrides: dict[str, object] | None = None,
58+
was_set_by_infer: bool = False,
59+
) -> VersionInferenceApplicable: # pragma: no cover - structural type
60+
...

0 commit comments

Comments
 (0)