Skip to content

Commit

Permalink
fix #919: restore legacy version-file behaviour for external callers …
Browse files Browse the repository at this point in the history
…+ add Deprecation warning
  • Loading branch information
RonnyPfannschmidt committed Sep 21, 2023
1 parent ece161a commit db90abf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ v8.0.2

bugfix
------

* fix #919: restore legacy version-file behaviour for external callers + add Deprecation warning
* fix #918: use packaging from setuptools for self-build
* fix #914: ignore the deprecated git archival plugin as its integrated now
* fix #912: ensure mypy safety of the version template + regression test
Expand Down
2 changes: 1 addition & 1 deletion src/setuptools_scm/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main(args: list[str] | None = None) -> None:
)
config = Configuration(inferred_root)

version = _get_version(config)
version = _get_version(config, force_write_version_files=False)
if version is None:
raise SystemExit("ERROR: no version found for", opts)
if opts.strip_dev:
Expand Down
10 changes: 9 additions & 1 deletion src/setuptools_scm/_get_version_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,20 @@ def write_version_files(


def _get_version(
config: Configuration, force_write_version_files: bool = False
config: Configuration, force_write_version_files: bool | None = None
) -> str | None:
parsed_version = parse_version(config)
if parsed_version is None:
return None
version_string = _format_version(parsed_version)
if force_write_version_files is None:
force_write_version_files = True
warnings.warn(
"force_write_version_files ought to be set,"
" presuming the legacy True value",
DeprecationWarning,
)

if force_write_version_files:
write_version_files(config, version=version_string, scm_version=parsed_version)

Expand Down
17 changes: 17 additions & 0 deletions testing/test_basic_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,20 @@ def __repr__(self) -> str:
# to create a test?
# monkeypatch.setenv(setuptools_scm.PRETEND_KEY, "1.0.1")
# assert setuptools_scm.get_version(version_cls=MyVersion) == "1"


def test_internal_get_version_warns_for_version_files(tmp_path: Path) -> None:
tmp_path.joinpath("PKG-INFO").write_text("Version: 0.1")
c = Configuration(root=tmp_path, fallback_root=tmp_path)
with pytest.warns(
DeprecationWarning,
match="force_write_version_files ought to be set,"
" presuming the legacy True value",
):
ver = setuptools_scm._get_version(c)
assert ver == "0.1"

# force write won't write as no version file is configured
assert setuptools_scm._get_version(c, force_write_version_files=False) == ver

assert setuptools_scm._get_version(c, force_write_version_files=True) == ver

0 comments on commit db90abf

Please sign in to comment.