Skip to content

Commit

Permalink
Merge pull request #924 from RonnyPfannschmidt/fix-919-version-file-l…
Browse files Browse the repository at this point in the history
…egacy

Fix 919 version file legacy
  • Loading branch information
RonnyPfannschmidt authored Sep 21, 2023
2 parents 4bc06ac + 39c91e7 commit 7b668cc
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ 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
* fix #913: use 240s timeout instead of 20 for git unshallow
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
build-backend = "_own_version_helper"
requires = [
'importlib-metadata>=4.6; python_version < "3.10"',
"packaging>=20",
"rich",
"setuptools>=61",
'tomli; python_version < "3.11"',
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
8 changes: 6 additions & 2 deletions src/setuptools_scm/_version_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
from typing import Type
from typing import Union

from packaging.version import InvalidVersion
from packaging.version import Version as Version
try:
from packaging.version import InvalidVersion
from packaging.version import Version as Version
except ImportError:
from setuptools.extern.packaging.version import InvalidVersion # type: ignore
from setuptools.extern.packaging.version import Version as Version # type: ignore


class NonNormalizedVersion(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 7b668cc

Please sign in to comment.