Skip to content

Commit 39c91e7

Browse files
fix #919: restore legacy version-file behaviour for external callers + add Deprecation warning
1 parent 52d6e1f commit 39c91e7

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

CHANGELOG.rst

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ v8.0.2
33

44
bugfix
55
------
6+
7+
* fix #919: restore legacy version-file behaviour for external callers + add Deprecation warning
68
* fix #918: use packaging from setuptools for self-build
79
* fix #914: ignore the deprecated git archival plugin as its integrated now
810
* fix #912: ensure mypy safety of the version template + regression test

src/setuptools_scm/_cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def main(args: list[str] | None = None) -> None:
3131
)
3232
config = Configuration(inferred_root)
3333

34-
version = _get_version(config)
34+
version = _get_version(config, force_write_version_files=False)
3535
if version is None:
3636
raise SystemExit("ERROR: no version found for", opts)
3737
if opts.strip_dev:

src/setuptools_scm/_get_version_impl.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,20 @@ def write_version_files(
8484

8585

8686
def _get_version(
87-
config: Configuration, force_write_version_files: bool = False
87+
config: Configuration, force_write_version_files: bool | None = None
8888
) -> str | None:
8989
parsed_version = parse_version(config)
9090
if parsed_version is None:
9191
return None
9292
version_string = _format_version(parsed_version)
93+
if force_write_version_files is None:
94+
force_write_version_files = True
95+
warnings.warn(
96+
"force_write_version_files ought to be set,"
97+
" presuming the legacy True value",
98+
DeprecationWarning,
99+
)
100+
93101
if force_write_version_files:
94102
write_version_files(config, version=version_string, scm_version=parsed_version)
95103

testing/test_basic_api.py

+17
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,20 @@ def __repr__(self) -> str:
242242
# to create a test?
243243
# monkeypatch.setenv(setuptools_scm.PRETEND_KEY, "1.0.1")
244244
# assert setuptools_scm.get_version(version_cls=MyVersion) == "1"
245+
246+
247+
def test_internal_get_version_warns_for_version_files(tmp_path: Path) -> None:
248+
tmp_path.joinpath("PKG-INFO").write_text("Version: 0.1")
249+
c = Configuration(root=tmp_path, fallback_root=tmp_path)
250+
with pytest.warns(
251+
DeprecationWarning,
252+
match="force_write_version_files ought to be set,"
253+
" presuming the legacy True value",
254+
):
255+
ver = setuptools_scm._get_version(c)
256+
assert ver == "0.1"
257+
258+
# force write won't write as no version file is configured
259+
assert setuptools_scm._get_version(c, force_write_version_files=False) == ver
260+
261+
assert setuptools_scm._get_version(c, force_write_version_files=True) == ver

0 commit comments

Comments
 (0)