Skip to content

Commit 1bea2c9

Browse files
undo support for simplified enabling
1 parent 2bfc568 commit 1bea2c9

File tree

5 files changed

+37
-57
lines changed

5 files changed

+37
-57
lines changed

src/setuptools_scm/_integration/pyproject_reading.py

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -85,39 +85,14 @@ def should_infer(self) -> bool:
8585
"""
8686
Determine if setuptools_scm should infer version based on configuration.
8787
88-
This method only considers the pyproject.toml configuration state.
89-
It does not consider version_keyword context (overrides always infer).
88+
Only infer when an explicit [tool.setuptools_scm] section is present.
89+
The presence of setuptools-scm in build-system.requires or
90+
project.dynamic does NOT auto-enable inference.
9091
9192
Returns:
92-
True if version inference should proceed based on configuration
93-
94-
Raises:
95-
ValueError: If setuptools-scm is required but dynamic=['version'] is missing
93+
True if [tool.setuptools_scm] is present, otherwise False
9694
"""
97-
# If there's a tool section, always infer
98-
if self.section_present:
99-
return True
100-
101-
# If not required, don't auto-activate for infer_version
102-
if not self.is_required:
103-
return False
104-
105-
# setuptools-scm is required but no tool section
106-
if not self.project_present:
107-
# No project section - don't auto-activate
108-
return False
109-
110-
# Project section exists - check for dynamic=['version']
111-
dynamic = self.project.get("dynamic", [])
112-
if "version" not in dynamic:
113-
raise ValueError(
114-
f"{self.path}: setuptools-scm is present in [build-system].requires "
115-
f"but dynamic=['version'] is not set in [project]. "
116-
f"Either add dynamic=['version'] to [project] or add a [tool.{self.tool_name}] section."
117-
)
118-
119-
# All conditions met
120-
return True
95+
return self.section_present
12196

12297

12398
def has_build_package(

src/setuptools_scm/_integration/setuptools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def infer_version(
138138
log.debug("Configuration issue in pyproject.toml: %s", e)
139139
return
140140

141+
# Only infer when tool section present per get_version_inference_config
141142
result = _get_version_inference_config(
142143
dist_name=dist_name,
143144
current_version=legacy_data.version or pyproject_data.project.get("version"),

src/setuptools_scm/_integration/version_inference.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,10 @@ def get_version_inference_config(
149149
dist_name=dist_name, pyproject_data=pyproject_data, overrides=overrides
150150
)
151151

152-
# infer_version path: decide based on pyproject configuration only
153-
try:
154-
if pyproject_data.should_infer():
155-
return VersionInferenceConfig(
156-
dist_name=dist_name, pyproject_data=pyproject_data, overrides=None
157-
)
158-
except ValueError:
159-
# Auto-activation should not error in infer_version context → skip silently
160-
return VersionInferenceNoOp()
152+
# infer_version path: only infer when [tool.setuptools_scm] section is present
153+
if pyproject_data.should_infer():
154+
return VersionInferenceConfig(
155+
dist_name=dist_name, pyproject_data=pyproject_data, overrides=None
156+
)
161157

162158
return VersionInferenceNoOp()

testing/test_integration.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ def test_git_archival_plugin_ignored(tmp_path: Path, ep_name: str) -> None:
739739

740740

741741
def test_pyproject_build_system_requires_setuptools_scm(wd: WorkDir) -> None:
742-
"""Test that setuptools_scm is enabled when present in build-system.requires"""
742+
"""With only build-system.requires and dynamic version, no auto-enable without tool section."""
743743
if sys.version_info < (3, 11):
744744
pytest.importorskip("tomli")
745745

@@ -761,13 +761,13 @@ def test_pyproject_build_system_requires_setuptools_scm(wd: WorkDir) -> None:
761761
wd.write("setup.py", "__import__('setuptools').setup()")
762762

763763
res = wd([sys.executable, "setup.py", "--version"])
764-
assert res.endswith("0.1.dev0+d20090213")
764+
assert res == "0.0.0"
765765

766766

767767
def test_pyproject_build_system_requires_setuptools_scm_dash_variant(
768768
wd: WorkDir,
769769
) -> None:
770-
"""Test that setuptools-scm (dash variant) is also detected in build-system.requires"""
770+
"""Dash variant also does not auto-enable without tool section."""
771771
if sys.version_info < (3, 11):
772772
pytest.importorskip("tomli")
773773

@@ -789,9 +789,12 @@ def test_pyproject_build_system_requires_setuptools_scm_dash_variant(
789789
wd.write("setup.py", "__import__('setuptools').setup()")
790790

791791
res = wd([sys.executable, "setup.py", "--version"])
792-
assert res.endswith("0.1.dev0+d20090213")
792+
assert res == "0.0.0"
793793

794794

795+
@pytest.mark.xfail(
796+
reason="we currently dont support dynamic version without tool section"
797+
)
795798
def test_pyproject_build_system_requires_with_extras(wd: WorkDir) -> None:
796799
"""Test that setuptools_scm[toml] is detected in build-system.requires"""
797800
if sys.version_info < (3, 11):
@@ -847,7 +850,7 @@ def test_pyproject_build_system_requires_not_present(wd: WorkDir) -> None:
847850
def test_pyproject_build_system_requires_priority_over_tool_section(
848851
wd: WorkDir,
849852
) -> None:
850-
"""Test that both build-system.requires and [tool.setuptools_scm] section work together"""
853+
"""Tool section controls enablement; build-system.requires may coexist."""
851854
if sys.version_info < (3, 11):
852855
pytest.importorskip("tomli")
853856

@@ -887,7 +890,7 @@ def test_extract_package_name(base_name: str, requirements: str) -> None:
887890

888891

889892
def test_build_requires_integration_with_config_reading(wd: WorkDir) -> None:
890-
"""Test that Configuration.from_file handles build-system.requires automatically"""
893+
"""Configuration.from_file still accepts build-system.requires without tool section."""
891894
if sys.version_info < (3, 11):
892895
pytest.importorskip("tomli")
893896

@@ -1092,6 +1095,9 @@ def test_integration_function_call_order(
10921095
)
10931096

10941097

1098+
@pytest.mark.xfail(
1099+
reason="we currently dont support dynamic version without tool section"
1100+
)
10951101
def test_infer_version_with_build_requires_no_tool_section(
10961102
wd: WorkDir, monkeypatch: pytest.MonkeyPatch
10971103
) -> None:
@@ -1119,14 +1125,14 @@ def test_infer_version_with_build_requires_no_tool_section(
11191125
# Call infer_version with direct data injection - no file I/O!
11201126
infer_version(dist, _given_pyproject_data=pyproject_data)
11211127

1122-
# Verify that version was set
1123-
assert dist.metadata.version is not None
11241128
assert dist.metadata.version == "1.0.0"
11251129

1126-
# Verify that the marker was set
11271130
assert getattr(dist, "_setuptools_scm_version_set_by_infer", False) is True
11281131

11291132

1133+
@pytest.mark.xfail(
1134+
reason="we currently dont support dynamic version without tool section"
1135+
)
11301136
def test_infer_version_with_build_requires_dash_variant_no_tool_section(
11311137
wd: WorkDir, monkeypatch: pytest.MonkeyPatch
11321138
) -> None:
@@ -1154,11 +1160,8 @@ def test_infer_version_with_build_requires_dash_variant_no_tool_section(
11541160
# Call infer_version with direct data injection - no file I/O!
11551161
infer_version(dist, _given_pyproject_data=pyproject_data)
11561162

1157-
# Verify that version was set
1158-
assert dist.metadata.version is not None
11591163
assert dist.metadata.version == "1.0.0"
11601164

1161-
# Verify that the marker was set
11621165
assert getattr(dist, "_setuptools_scm_version_set_by_infer", False) is True
11631166

11641167

@@ -1221,6 +1224,9 @@ def test_version_keyword_no_scm_dependency_works(
12211224
assert dist.metadata.version == "1.0.0"
12221225

12231226

1227+
@pytest.mark.xfail(
1228+
reason="we currently dont support dynamic version without tool section"
1229+
)
12241230
def test_verify_dynamic_version_when_required_missing_dynamic() -> None:
12251231
"""Test that should_infer raises ValueError when setuptools-scm is in build-system.requires but dynamic=['version'] is missing"""
12261232
from setuptools_scm._integration.pyproject_reading import PyProjectData
@@ -1261,6 +1267,9 @@ def test_verify_dynamic_version_when_required_with_tool_section() -> None:
12611267
assert pyproject_data.should_infer() is True
12621268

12631269

1270+
@pytest.mark.xfail(
1271+
reason="we currently dont support dynamic version without tool section"
1272+
)
12641273
def test_verify_dynamic_version_when_required_with_dynamic() -> None:
12651274
"""Test that verification passes when setuptools-scm is in build-system.requires and dynamic=['version'] is set"""
12661275
from setuptools_scm._integration.pyproject_reading import PyProjectData

testing/test_version_inference.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_no_setuptools_scm_config_infer_version(self) -> None:
8989
assert isinstance(result, VersionInferenceNoOp)
9090

9191
def test_no_setuptools_scm_config_version_keyword(self) -> None:
92-
"""Test that we DO infer when setuptools-scm is not configured but use_scm_version=True."""
92+
"""We infer when setuptools-scm is not configured but use_scm_version=True."""
9393
result = get_version_inference_config(
9494
dist_name="test_package",
9595
current_version=None,
@@ -102,7 +102,7 @@ def test_no_setuptools_scm_config_version_keyword(self) -> None:
102102
assert result.overrides == {}
103103

104104
def test_setuptools_scm_required_no_project_section_infer_version(self) -> None:
105-
"""Test that we don't infer when setuptools-scm is required but no project section and infer_version called."""
105+
"""We don't infer without tool section even if required: infer_version path."""
106106
result = get_version_inference_config(
107107
dist_name="test_package",
108108
current_version=None,
@@ -142,18 +142,17 @@ def test_setuptools_scm_required_no_project_section_version_keyword_with_config(
142142
assert result.overrides == overrides
143143

144144
def test_setuptools_scm_required_with_project_section(self) -> None:
145-
"""Test that we infer when setuptools-scm is required and project section exists."""
145+
"""We only infer when tool section present, regardless of required/project presence."""
146146
result = get_version_inference_config(
147147
dist_name="test_package",
148148
current_version=None,
149149
pyproject_data=PyProjectData.for_testing(True, False, True),
150150
)
151151

152-
assert isinstance(result, VersionInferenceConfig)
153-
assert result.dist_name == "test_package"
152+
assert isinstance(result, VersionInferenceNoOp)
154153

155154
def test_tool_section_present(self) -> None:
156-
"""Test that we infer when tool section is present."""
155+
"""We infer when tool section is present."""
157156
result = get_version_inference_config(
158157
dist_name="test_package",
159158
current_version=None,

0 commit comments

Comments
 (0)