Skip to content

Commit b388a1d

Browse files
Merge upstream main: adapt #1231 fix for refactored architecture
Merged upstream/main which includes: - fix: don't warn about tool.setuptools.dynamic.version when only using file finder (#1231) - docs: update changelog for v9.2.2 patch release Adapted the fix for our refactored architecture where: - _check_setuptools_dynamic_version_conflict moved to setuptools-scm layer - should_infer() converted from method to standalone function - Conflict check now uses PyProjectData.definition field Changes: - Updated _check_setuptools_dynamic_version_conflict to only warn when should_infer() returns True - Simplified function signature to take PyProjectData instead of separate parameters - Fixed test to use should_infer(pyproject_data) function instead of method - All pyproject reading tests pass
2 parents 5d61c5b + e56b78f commit b388a1d

File tree

3 files changed

+54
-8
lines changed

3 files changed

+54
-8
lines changed

setuptools-scm/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
<!-- towncrier release notes start -->
44

5+
## v9.2.2
6+
7+
### Fixed
8+
9+
- fix #1231: don't warn about `tool.setuptools.dynamic.version` when only using file finder.
10+
The warning about combining version guessing with setuptools dynamic versions should only
11+
be issued when setuptools-scm is performing version inference, not when it's only being
12+
used for its file finder functionality.
13+
14+
515
## v9.2.1
616

717
### Fixed

setuptools-scm/src/setuptools_scm/_integration/pyproject_reading.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,19 @@ def has_build_package_with_extra(
8787

8888

8989
def _check_setuptools_dynamic_version_conflict(
90-
path: Path, build_requires: Sequence[str], definition: TOML_RESULT
90+
path: Path, pyproject_data: PyProjectData
9191
) -> None:
92-
"""Warn if tool.setuptools.dynamic.version conflicts with setuptools-scm."""
93-
# Check if setuptools-scm[simple] is in build requirements
94-
if not has_build_package_with_extra(build_requires, "setuptools-scm", "simple"):
92+
"""Warn if tool.setuptools.dynamic.version conflicts with setuptools-scm.
93+
94+
Only warns if setuptools-scm is being used for version inference (not just file finding).
95+
When only file finders are used, it's valid to use tool.setuptools.dynamic.version.
96+
"""
97+
# Only warn if setuptools-scm is performing version inference
98+
if not should_infer(pyproject_data):
9599
return
96100

97101
# Check if tool.setuptools.dynamic.version exists
98-
tool = definition.get("tool", {})
102+
tool = pyproject_data.definition.get("tool", {})
99103
if not isinstance(tool, dict):
100104
return
101105

@@ -140,9 +144,7 @@ def read_pyproject(
140144

141145
# Check for conflicting tool.setuptools.dynamic configuration
142146
# Use the definition from pyproject_data (read by vcs_versioning)
143-
_check_setuptools_dynamic_version_conflict(
144-
path, pyproject_data.build_requires, pyproject_data.definition
145-
)
147+
_check_setuptools_dynamic_version_conflict(path, pyproject_data)
146148

147149
return pyproject_data
148150

setuptools-scm/testing_scm/test_pyproject_reading.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def test_read_pyproject_with_given_definition(monkeypatch: pytest.MonkeyPatch) -
130130

131131

132132
def test_read_pyproject_with_setuptools_dynamic_version_warns() -> None:
133+
"""Test that warning is issued when version inference is enabled."""
133134
with pytest.warns(
134135
UserWarning,
135136
match=r"pyproject\.toml: at \[tool\.setuptools\.dynamic\]",
@@ -146,3 +147,36 @@ def test_read_pyproject_with_setuptools_dynamic_version_warns() -> None:
146147
}
147148
)
148149
assert pyproject_data.project_version is None
150+
151+
152+
def test_read_pyproject_with_setuptools_dynamic_version_no_warn_when_file_finder_only() -> (
153+
None
154+
):
155+
"""Test that no warning is issued when only file finder is used (no version inference)."""
156+
# When setuptools-scm is used only for file finding (no [tool.setuptools_scm] section,
157+
# no [simple] extra, version not in dynamic), it's valid to use tool.setuptools.dynamic.version
158+
import warnings
159+
160+
with warnings.catch_warnings(record=True) as warning_list:
161+
warnings.simplefilter("always")
162+
pyproject_data = read_pyproject(
163+
_given_definition={
164+
"build-system": {"requires": ["setuptools-scm"]},
165+
"project": {"name": "test-package", "version": "1.0.0"},
166+
"tool": {
167+
"setuptools": {
168+
"dynamic": {"version": {"attr": "test_package.__version__"}}
169+
}
170+
},
171+
}
172+
)
173+
174+
# Filter to check for the dynamic version warning specifically
175+
relevant_warnings = [
176+
w for w in warning_list if "tool.setuptools.dynamic" in str(w.message)
177+
]
178+
assert len(relevant_warnings) == 0, (
179+
"Should not warn about tool.setuptools.dynamic when only using file finder"
180+
)
181+
assert pyproject_data.project_version == "1.0.0"
182+
assert not should_infer(pyproject_data)

0 commit comments

Comments
 (0)