Skip to content

Commit 95a0c47

Browse files
fix: don't warn about tool.setuptools.dynamic.version when only using file finder
When setuptools-scm is used only for its file finder functionality (no version inference), it's valid to use tool.setuptools.dynamic.version for versioning. The warning should only be issued when setuptools-scm is actually performing version inference. Changes: - Modified pyproject_reading.py to only warn when should_infer() is True - Added test for file-finder-only case (no warning expected) - Updated existing test with clarifying documentation Fixes #1231
1 parent 338f562 commit 95a0c47

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/setuptools_scm/_integration/pyproject_reading.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ def read_pyproject(
237237
.get("dynamic", {})
238238
.get("version", None)
239239
)
240-
if setuptools_dynamic_version is not None:
240+
# Only warn if setuptools-scm is being used for version inference
241+
# (not just file finding). When only file finders are used, it's valid
242+
# to use tool.setuptools.dynamic.version for versioning.
243+
if setuptools_dynamic_version is not None and pyproject_data.should_infer():
241244
from .deprecation import warn_pyproject_setuptools_dynamic_version
242245

243246
warn_pyproject_setuptools_dynamic_version(path)

testing/test_pyproject_reading.py

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

130130

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

0 commit comments

Comments
 (0)