File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -36,8 +36,12 @@ def _get_version() -> str:
36
36
version = subprocess .check_output (cmd , encoding = "utf-8" )
37
37
return _normalization .best_effort_version (version , "{safe}.dev+{sanitized}" )
38
38
except subprocess .CalledProcessError : # e.g.: git not installed or history missing
39
+ if os .path .exists ("PKG-INFO" ): # building wheel from sdist
40
+ with open ("PKG-INFO" , encoding = "utf-8" ) as fp :
41
+ if match := re .search (r"^Version: (\d+\.\d+\.\d+.*)$" , fp .read (), re .M ):
42
+ return match [1 ]
39
43
with open ("NEWS.rst" , encoding = "utf-8" ) as fp :
40
- match = re .search (r"v\d+\.\d+.\d+" , fp .read ()) # latest version
44
+ match = re .search (r"v\d+\.\d+\ .\d+" , fp .read ()) # latest version
41
45
return f"{ match [0 ] if match else '0.0.0' } .dev+{ time .strftime ('%Y%m%d' )} "
42
46
43
47
Original file line number Diff line number Diff line change @@ -265,6 +265,15 @@ def test_findall_missing_symlink(tmpdir):
265
265
assert found == []
266
266
267
267
268
+ def test_setuptools_own_dists_infers_version (setuptools_sdist , setuptools_wheel ):
269
+ # Sanity check
270
+ # Validates that `setup.py:_get_version` works as expected
271
+ assert "0.0.0" not in setuptools_sdist .name
272
+ # Validates that `setup.py:_get_version` guarantees the fallback
273
+ # code path is finding something in PKG-INFO:
274
+ assert "0.0.0" not in setuptools_wheel .name
275
+
276
+
268
277
@pytest .mark .xfail (reason = "unable to exclude tests; #4475 #3260" )
269
278
def test_its_own_wheel_does_not_contain_tests (setuptools_wheel ):
270
279
with ZipFile (setuptools_wheel ) as zipfile :
You can’t perform that action at this time.
0 commit comments