Skip to content

Commit bf3aac1

Browse files
Merge pull request #1195 from RonnyPfannschmidt/fix-1194-xmlsec-regression
handle missing pyproject config in case version keyword is used
2 parents d7f1688 + a4b755e commit bf3aac1

File tree

6 files changed

+118
-6
lines changed

6 files changed

+118
-6
lines changed

.github/workflows/python-tests.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ jobs:
121121
- name: Publish package to PyPI
122122
uses: pypa/gh-action-pypi-publish@release/v1
123123

124+
upload-release-assets:
125+
runs-on: ubuntu-latest
126+
if: github.event_name == 'release' && github.event.action == 'published'
127+
needs: [test]
128+
permissions:
129+
contents: write
130+
steps:
131+
- uses: actions/download-artifact@v4
132+
with:
133+
name: Packages
134+
path: dist
135+
- name: Upload release assets
136+
uses: softprops/action-gh-release@v2
137+
with:
138+
files: dist/*
139+
fail_on_unmatched_files: true
140+
124141
test-pypi-upload:
125142
runs-on: ubuntu-latest
126143
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v9.1.1
4+
5+
### fixed
6+
7+
- fix #1194: correctly handle version keyword when pyproject metadata is missing
8+
9+
310
## v9.0.3
411

512
### fixed

src/setuptools_scm/_integration/setuptools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ def _warn_on_old_setuptools(_version: str = setuptools.__version__) -> None:
3838

3939

4040
def _log_hookstart(hook: str, dist: setuptools.Distribution) -> None:
41-
log.debug("%s %s %s %r", hook, id(dist), id(dist.metadata), vars(dist.metadata))
41+
log.debug(
42+
"%s %s %s %r",
43+
hook,
44+
id(dist),
45+
id(dist.metadata),
46+
{**vars(dist.metadata), "long_description": ...},
47+
)
4248

4349

4450
def get_keyword_overrides(

src/setuptools_scm/_integration/version_inference.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,23 @@ def get_version_inference_config(
154154

155155
# Handle missing configuration
156156
if not pyproject_data.is_required and not pyproject_data.section_present:
157-
# If there are overrides, proceed with inference (explicit use_scm_version)
157+
# If version_keyword was called (overrides is not None), activate setuptools_scm
158+
# This handles both use_scm_version=True (empty {}) and use_scm_version={config}
158159
if overrides is not None:
159160
return VersionInferenceConfig(
160161
dist_name=dist_name,
161162
pyproject_data=pyproject_data,
162163
overrides=overrides,
163164
)
165+
# If infer_version was called (overrides is None), only activate with config
164166
return VersionInferenceNoOp()
165167

166168
# Handle missing project section when required
167169
if (
168170
pyproject_data.is_required
169171
and not pyproject_data.section_present
170172
and not pyproject_data.project_present
173+
and overrides is None # Only return NoOp for infer_version, not version_keyword
171174
):
172175
return VersionInferenceNoOp()
173176

testing/test_integration.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,3 +1305,38 @@ def test_infer_version_logs_debug_when_missing_dynamic_version(
13051305

13061306
# Verify that version was not set due to configuration issue
13071307
assert dist.metadata.version is None
1308+
1309+
1310+
@pytest.mark.issue("xmlsec-regression")
1311+
def test_xmlsec_download_regression(
1312+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1313+
) -> None:
1314+
"""Test that pip download works for xmlsec package without causing setuptools_scm regression.
1315+
1316+
This test ensures that downloading and building xmlsec from source doesn't fail
1317+
due to setuptools_scm issues when using --no-build-isolation.
1318+
"""
1319+
# Set up environment with setuptools_scm debug enabled
1320+
monkeypatch.setenv("SETUPTOOLS_SCM_DEBUG", "1")
1321+
monkeypatch.setenv("COLUMNS", "150")
1322+
1323+
# Run pip download command with no-binary and no-build-isolation
1324+
try:
1325+
subprocess.run(
1326+
[
1327+
*(sys.executable, "-m", "pip", "download"),
1328+
*("--no-binary", "xmlsec"),
1329+
"--no-build-isolation",
1330+
"-v",
1331+
"xmlsec==1.3.16",
1332+
],
1333+
cwd=tmp_path,
1334+
text=True,
1335+
timeout=300,
1336+
check=True,
1337+
)
1338+
except subprocess.CalledProcessError as e:
1339+
pytest.fail(f"pip download failed: {e}", pytrace=False)
1340+
1341+
# The success of the subprocess.run call above means the regression is fixed.
1342+
# pip download succeeded without setuptools_scm causing version conflicts.

testing/test_version_inference.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,70 @@ def test_no_pyproject_toml(self) -> None:
8181
# and not call get_version_inference_config at all.
8282
# This test is no longer needed as pyproject_data is always required.
8383

84-
def test_no_setuptools_scm_config(self) -> None:
85-
"""Test that we don't infer when setuptools-scm is not configured."""
84+
def test_no_setuptools_scm_config_infer_version(self) -> None:
85+
"""Test that we don't infer when setuptools-scm is not configured and infer_version called."""
8686
result = get_version_inference_config(
8787
dist_name="test_package",
8888
current_version=None,
8989
pyproject_data=PyProjectData.for_testing(False, False, True),
90+
overrides=None, # infer_version call
9091
)
9192

9293
assert isinstance(result, VersionInferenceNoOp)
9394

94-
def test_setuptools_scm_required_no_project_section(self) -> None:
95-
"""Test that we don't infer when setuptools-scm is required but no project section."""
95+
def test_no_setuptools_scm_config_version_keyword(self) -> None:
96+
"""Test that we DO infer when setuptools-scm is not configured but use_scm_version=True."""
97+
result = get_version_inference_config(
98+
dist_name="test_package",
99+
current_version=None,
100+
pyproject_data=PyProjectData.for_testing(False, False, True),
101+
overrides={}, # version_keyword call with use_scm_version=True
102+
)
103+
104+
assert isinstance(result, VersionInferenceConfig)
105+
assert result.dist_name == "test_package"
106+
assert result.overrides == {}
107+
108+
def test_setuptools_scm_required_no_project_section_infer_version(self) -> None:
109+
"""Test that we don't infer when setuptools-scm is required but no project section and infer_version called."""
96110
result = get_version_inference_config(
97111
dist_name="test_package",
98112
current_version=None,
99113
pyproject_data=PyProjectData.for_testing(True, False, False),
114+
overrides=None, # infer_version call
100115
)
101116

102117
assert isinstance(result, VersionInferenceNoOp)
103118

119+
def test_setuptools_scm_required_no_project_section_version_keyword(self) -> None:
120+
"""Test that we DO infer when setuptools-scm is required but no project section and use_scm_version=True."""
121+
result = get_version_inference_config(
122+
dist_name="test_package",
123+
current_version=None,
124+
pyproject_data=PyProjectData.for_testing(True, False, False),
125+
overrides={}, # version_keyword call with use_scm_version=True
126+
)
127+
128+
assert isinstance(result, VersionInferenceConfig)
129+
assert result.dist_name == "test_package"
130+
assert result.overrides == {}
131+
132+
def test_setuptools_scm_required_no_project_section_version_keyword_with_config(
133+
self,
134+
) -> None:
135+
"""Test that we DO infer when setuptools-scm is required but no project section and use_scm_version={config}."""
136+
overrides = {"version_scheme": "calver"}
137+
result = get_version_inference_config(
138+
dist_name="test_package",
139+
current_version=None,
140+
pyproject_data=PyProjectData.for_testing(True, False, False),
141+
overrides=overrides, # version_keyword call with use_scm_version={config}
142+
)
143+
144+
assert isinstance(result, VersionInferenceConfig)
145+
assert result.dist_name == "test_package"
146+
assert result.overrides == overrides
147+
104148
def test_setuptools_scm_required_with_project_section(self) -> None:
105149
"""Test that we infer when setuptools-scm is required and project section exists."""
106150
result = get_version_inference_config(

0 commit comments

Comments
 (0)