File tree 6 files changed +36
-5
lines changed
6 files changed +36
-5
lines changed Original file line number Diff line number Diff line change 3
3
4
4
bugfix
5
5
------
6
+
7
+ * fix #919: restore legacy version-file behaviour for external callers + add Deprecation warning
8
+ * fix #918: use packaging from setuptools for self-build
6
9
* fix #914: ignore the deprecated git archival plugin as its integrated now
7
10
* fix #912: ensure mypy safety of the version template + regression test
8
11
* fix #913: use 240s timeout instead of 20 for git unshallow
Original file line number Diff line number Diff line change 4
4
build-backend = " _own_version_helper"
5
5
requires = [
6
6
' importlib-metadata>=4.6; python_version < "3.10"' ,
7
- " packaging>=20" ,
8
7
" rich" ,
9
8
" setuptools>=61" ,
10
9
' tomli; python_version < "3.11"' ,
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ def main(args: list[str] | None = None) -> None:
31
31
)
32
32
config = Configuration (inferred_root )
33
33
34
- version = _get_version (config )
34
+ version = _get_version (config , force_write_version_files = False )
35
35
if version is None :
36
36
raise SystemExit ("ERROR: no version found for" , opts )
37
37
if opts .strip_dev :
Original file line number Diff line number Diff line change @@ -84,12 +84,20 @@ def write_version_files(
84
84
85
85
86
86
def _get_version (
87
- config : Configuration , force_write_version_files : bool = False
87
+ config : Configuration , force_write_version_files : bool | None = None
88
88
) -> str | None :
89
89
parsed_version = parse_version (config )
90
90
if parsed_version is None :
91
91
return None
92
92
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
+
93
101
if force_write_version_files :
94
102
write_version_files (config , version = version_string , scm_version = parsed_version )
95
103
Original file line number Diff line number Diff line change 5
5
from typing import Type
6
6
from typing import Union
7
7
8
- from packaging .version import InvalidVersion
9
- from packaging .version import Version as Version
8
+ try :
9
+ from packaging .version import InvalidVersion
10
+ from packaging .version import Version as Version
11
+ except ImportError :
12
+ from setuptools .extern .packaging .version import InvalidVersion # type: ignore
13
+ from setuptools .extern .packaging .version import Version as Version # type: ignore
10
14
11
15
12
16
class NonNormalizedVersion (Version ):
Original file line number Diff line number Diff line change @@ -242,3 +242,20 @@ def __repr__(self) -> str:
242
242
# to create a test?
243
243
# monkeypatch.setenv(setuptools_scm.PRETEND_KEY, "1.0.1")
244
244
# 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
You can’t perform that action at this time.
0 commit comments