1
1
2
- # Version: 0.22
2
+ # Version: 0.23
3
3
4
4
"""The Versioneer - like a rocketeer, but for versions.
5
5
9
9
* like a rocketeer, but for versions!
10
10
* https://github.com/python-versioneer/python-versioneer
11
11
* Brian Warner
12
- * License: Public Domain
13
- * Compatible with: Python 3.6, 3. 7, 3.8, 3.9, 3.10 and pypy3
12
+ * License: Public Domain (CC0-1.0)
13
+ * Compatible with: Python 3.7, 3.8, 3.9, 3.10 and pypy3
14
14
* [![Latest Version][pypi-image]][pypi-url]
15
15
* [![Build Status][travis-image]][travis-url]
16
16
@@ -355,7 +355,7 @@ def get_config_from_root(root):
355
355
cfg .versionfile_source = section .get ("versionfile_source" )
356
356
cfg .versionfile_build = section .get ("versionfile_build" )
357
357
cfg .tag_prefix = section .get ("tag_prefix" )
358
- if cfg .tag_prefix in ("''" , '""' ):
358
+ if cfg .tag_prefix in ("''" , '""' , None ):
359
359
cfg .tag_prefix = ""
360
360
cfg .parentdir_prefix = section .get ("parentdir_prefix" )
361
361
cfg .verbose = section .get ("verbose" )
@@ -431,7 +431,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
431
431
# that just contains the computed version number.
432
432
433
433
# This file is released into the public domain. Generated by
434
- # versioneer-0.22 (https://github.com/python-versioneer/python-versioneer)
434
+ # versioneer-0.23 (https://github.com/python-versioneer/python-versioneer)
435
435
436
436
"""Git implementation of _version.py."""
437
437
@@ -679,13 +679,12 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
679
679
print("Directory %%s not under git control" %% root)
680
680
raise NotThisMethod("'git rev-parse --git-dir' returned error")
681
681
682
- MATCH_ARGS = ["--match", "%%s*" %% tag_prefix] if tag_prefix else []
683
-
684
682
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
685
683
# if there isn't one, this yields HEX[-dirty] (no NUM)
686
- describe_out, rc = runner(GITS, ["describe", "--tags", "--dirty",
687
- "--always", "--long", *MATCH_ARGS],
688
- cwd=root)
684
+ describe_out, rc = runner(GITS, [
685
+ "describe", "--tags", "--dirty", "--always", "--long",
686
+ "--match", f"{tag_prefix}[[:digit:]]*"
687
+ ], cwd=root)
689
688
# --long was added in git-1.5.5
690
689
if describe_out is None:
691
690
raise NotThisMethod("'git describe' failed")
@@ -774,8 +773,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
774
773
else:
775
774
# HEX: no tags
776
775
pieces["closest-tag"] = None
777
- count_out , rc = runner(GITS, ["rev-list", "HEAD", "--count "], cwd=root)
778
- pieces["distance"] = int(count_out ) # total number of commits
776
+ out , rc = runner(GITS, ["rev-list", "HEAD", "--left-right "], cwd=root)
777
+ pieces["distance"] = len(out.split() ) # total number of commits
779
778
780
779
# commit date: see ISO-8601 comment in git_versions_from_keywords()
781
780
date = runner(GITS, ["show", "-s", "--format=%%ci", "HEAD"], cwd=root)[0].strip()
@@ -871,7 +870,7 @@ def render_pep440_pre(pieces):
871
870
tag_version, post_version = pep440_split_post(pieces["closest-tag"])
872
871
rendered = tag_version
873
872
if post_version is not None:
874
- rendered += ".post%%d.dev%%d" %% (post_version+ 1, pieces["distance"])
873
+ rendered += ".post%%d.dev%%d" %% (post_version + 1, pieces["distance"])
875
874
else:
876
875
rendered += ".post0.dev%%d" %% (pieces["distance"])
877
876
else:
@@ -1202,13 +1201,12 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
1202
1201
print ("Directory %s not under git control" % root )
1203
1202
raise NotThisMethod ("'git rev-parse --git-dir' returned error" )
1204
1203
1205
- MATCH_ARGS = ["--match" , "%s*" % tag_prefix ] if tag_prefix else []
1206
-
1207
1204
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
1208
1205
# if there isn't one, this yields HEX[-dirty] (no NUM)
1209
- describe_out , rc = runner (GITS , ["describe" , "--tags" , "--dirty" ,
1210
- "--always" , "--long" , * MATCH_ARGS ],
1211
- cwd = root )
1206
+ describe_out , rc = runner (GITS , [
1207
+ "describe" , "--tags" , "--dirty" , "--always" , "--long" ,
1208
+ "--match" , f"{ tag_prefix } [[:digit:]]*"
1209
+ ], cwd = root )
1212
1210
# --long was added in git-1.5.5
1213
1211
if describe_out is None :
1214
1212
raise NotThisMethod ("'git describe' failed" )
@@ -1297,8 +1295,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
1297
1295
else :
1298
1296
# HEX: no tags
1299
1297
pieces ["closest-tag" ] = None
1300
- count_out , rc = runner (GITS , ["rev-list" , "HEAD" , "--count " ], cwd = root )
1301
- pieces ["distance" ] = int ( count_out ) # total number of commits
1298
+ out , rc = runner (GITS , ["rev-list" , "HEAD" , "--left-right " ], cwd = root )
1299
+ pieces ["distance" ] = len ( out . split () ) # total number of commits
1302
1300
1303
1301
# commit date: see ISO-8601 comment in git_versions_from_keywords()
1304
1302
date = runner (GITS , ["show" , "-s" , "--format=%ci" , "HEAD" ], cwd = root )[0 ].strip ()
@@ -1310,7 +1308,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
1310
1308
return pieces
1311
1309
1312
1310
1313
- def do_vcs_install (manifest_in , versionfile_source , ipy ):
1311
+ def do_vcs_install (versionfile_source , ipy ):
1314
1312
"""Git-specific installation logic for Versioneer.
1315
1313
1316
1314
For Git, this means creating/changing .gitattributes to mark _version.py
@@ -1319,7 +1317,7 @@ def do_vcs_install(manifest_in, versionfile_source, ipy):
1319
1317
GITS = ["git" ]
1320
1318
if sys .platform == "win32" :
1321
1319
GITS = ["git.cmd" , "git.exe" ]
1322
- files = [manifest_in , versionfile_source ]
1320
+ files = [versionfile_source ]
1323
1321
if ipy :
1324
1322
files .append (ipy )
1325
1323
try :
@@ -1372,7 +1370,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
1372
1370
1373
1371
1374
1372
SHORT_VERSION_PY = """
1375
- # This file was generated by 'versioneer.py' (0.22 ) from
1373
+ # This file was generated by 'versioneer.py' (0.23 ) from
1376
1374
# revision-control system data, or from the parent directory name of an
1377
1375
# unpacked source archive. Distribution tarballs contain a pre-generated copy
1378
1376
# of this file.
@@ -1501,7 +1499,7 @@ def render_pep440_pre(pieces):
1501
1499
tag_version , post_version = pep440_split_post (pieces ["closest-tag" ])
1502
1500
rendered = tag_version
1503
1501
if post_version is not None :
1504
- rendered += ".post%d.dev%d" % (post_version + 1 , pieces ["distance" ])
1502
+ rendered += ".post%d.dev%d" % (post_version + 1 , pieces ["distance" ])
1505
1503
else :
1506
1504
rendered += ".post0.dev%d" % (pieces ["distance" ])
1507
1505
else :
@@ -1753,7 +1751,7 @@ def get_version():
1753
1751
1754
1752
1755
1753
def get_cmdclass (cmdclass = None ):
1756
- """Get the custom setuptools/distutils subclasses used by Versioneer.
1754
+ """Get the custom setuptools subclasses used by Versioneer.
1757
1755
1758
1756
If the package uses a different cmdclass (e.g. one from numpy), it
1759
1757
should be provide as an argument.
@@ -1775,11 +1773,8 @@ def get_cmdclass(cmdclass=None):
1775
1773
1776
1774
cmds = {} if cmdclass is None else cmdclass .copy ()
1777
1775
1778
- # we add "version" to both distutils and setuptools
1779
- try :
1780
- from setuptools import Command
1781
- except ImportError :
1782
- from distutils .core import Command
1776
+ # we add "version" to setuptools
1777
+ from setuptools import Command
1783
1778
1784
1779
class cmd_version (Command ):
1785
1780
description = "report generated version string"
@@ -1802,7 +1797,7 @@ def run(self):
1802
1797
print (" error: %s" % vers ["error" ])
1803
1798
cmds ["version" ] = cmd_version
1804
1799
1805
- # we override "build_py" in both distutils and setuptools
1800
+ # we override "build_py" in setuptools
1806
1801
#
1807
1802
# most invocation pathways end up running build_py:
1808
1803
# distutils/build -> build_py
@@ -1817,20 +1812,25 @@ def run(self):
1817
1812
# then does setup.py bdist_wheel, or sometimes setup.py install
1818
1813
# setup.py egg_info -> ?
1819
1814
1815
+ # pip install -e . and setuptool/editable_wheel will invoke build_py
1816
+ # but the build_py command is not expected to copy any files.
1817
+
1820
1818
# we override different "build_py" commands for both environments
1821
1819
if 'build_py' in cmds :
1822
1820
_build_py = cmds ['build_py' ]
1823
- elif "setuptools" in sys .modules :
1824
- from setuptools .command .build_py import build_py as _build_py
1825
1821
else :
1826
- from distutils .command .build_py import build_py as _build_py
1822
+ from setuptools .command .build_py import build_py as _build_py
1827
1823
1828
1824
class cmd_build_py (_build_py ):
1829
1825
def run (self ):
1830
1826
root = get_root ()
1831
1827
cfg = get_config_from_root (root )
1832
1828
versions = get_versions ()
1833
1829
_build_py .run (self )
1830
+ if getattr (self , "editable_mode" , False ):
1831
+ # During editable installs `.py` and data files are
1832
+ # not copied to build_lib
1833
+ return
1834
1834
# now locate _version.py in the new build/ directory and replace
1835
1835
# it with an updated value
1836
1836
if cfg .versionfile_build :
@@ -1842,10 +1842,8 @@ def run(self):
1842
1842
1843
1843
if 'build_ext' in cmds :
1844
1844
_build_ext = cmds ['build_ext' ]
1845
- elif "setuptools" in sys .modules :
1846
- from setuptools .command .build_ext import build_ext as _build_ext
1847
1845
else :
1848
- from distutils .command .build_ext import build_ext as _build_ext
1846
+ from setuptools .command .build_ext import build_ext as _build_ext
1849
1847
1850
1848
class cmd_build_ext (_build_ext ):
1851
1849
def run (self ):
@@ -1863,6 +1861,11 @@ def run(self):
1863
1861
# it with an updated value
1864
1862
target_versionfile = os .path .join (self .build_lib ,
1865
1863
cfg .versionfile_build )
1864
+ if not os .path .exists (target_versionfile ):
1865
+ print (f"Warning: { target_versionfile } does not exist, skipping "
1866
+ "version update. This can happen if you are running build_ext "
1867
+ "without first running build_py." )
1868
+ return
1866
1869
print ("UPDATING %s" % target_versionfile )
1867
1870
write_to_version_file (target_versionfile , versions )
1868
1871
cmds ["build_ext" ] = cmd_build_ext
@@ -1924,13 +1927,48 @@ def run(self):
1924
1927
})
1925
1928
cmds ["py2exe" ] = cmd_py2exe
1926
1929
1930
+ # sdist farms its file list building out to egg_info
1931
+ if 'egg_info' in cmds :
1932
+ _sdist = cmds ['egg_info' ]
1933
+ else :
1934
+ from setuptools .command .egg_info import egg_info as _egg_info
1935
+
1936
+ class cmd_egg_info (_egg_info ):
1937
+ def find_sources (self ):
1938
+ # egg_info.find_sources builds the manifest list and writes it
1939
+ # in one shot
1940
+ super ().find_sources ()
1941
+
1942
+ # Modify the filelist and normalize it
1943
+ root = get_root ()
1944
+ cfg = get_config_from_root (root )
1945
+ self .filelist .append ('versioneer.py' )
1946
+ if cfg .versionfile_source :
1947
+ # There are rare cases where versionfile_source might not be
1948
+ # included by default, so we must be explicit
1949
+ self .filelist .append (cfg .versionfile_source )
1950
+ self .filelist .sort ()
1951
+ self .filelist .remove_duplicates ()
1952
+
1953
+ # The write method is hidden in the manifest_maker instance that
1954
+ # generated the filelist and was thrown away
1955
+ # We will instead replicate their final normalization (to unicode,
1956
+ # and POSIX-style paths)
1957
+ from setuptools import unicode_utils
1958
+ normalized = [unicode_utils .filesys_decode (f ).replace (os .sep , '/' )
1959
+ for f in self .filelist .files ]
1960
+
1961
+ manifest_filename = os .path .join (self .egg_info , 'SOURCES.txt' )
1962
+ with open (manifest_filename , 'w' ) as fobj :
1963
+ fobj .write ('\n ' .join (normalized ))
1964
+
1965
+ cmds ['egg_info' ] = cmd_egg_info
1966
+
1927
1967
# we override different "sdist" commands for both environments
1928
1968
if 'sdist' in cmds :
1929
1969
_sdist = cmds ['sdist' ]
1930
- elif "setuptools" in sys .modules :
1931
- from setuptools .command .sdist import sdist as _sdist
1932
1970
else :
1933
- from distutils .command .sdist import sdist as _sdist
1971
+ from setuptools .command .sdist import sdist as _sdist
1934
1972
1935
1973
class cmd_sdist (_sdist ):
1936
1974
def run (self ):
@@ -2055,42 +2093,10 @@ def do_setup():
2055
2093
print (" %s doesn't exist, ok" % ipy )
2056
2094
ipy = None
2057
2095
2058
- # Make sure both the top-level "versioneer.py" and versionfile_source
2059
- # (PKG/_version.py, used by runtime code) are in MANIFEST.in, so
2060
- # they'll be copied into source distributions. Pip won't be able to
2061
- # install the package without this.
2062
- manifest_in = os .path .join (root , "MANIFEST.in" )
2063
- simple_includes = set ()
2064
- try :
2065
- with open (manifest_in , "r" ) as f :
2066
- for line in f :
2067
- if line .startswith ("include " ):
2068
- for include in line .split ()[1 :]:
2069
- simple_includes .add (include )
2070
- except OSError :
2071
- pass
2072
- # That doesn't cover everything MANIFEST.in can do
2073
- # (http://docs.python.org/2/distutils/sourcedist.html#commands), so
2074
- # it might give some false negatives. Appending redundant 'include'
2075
- # lines is safe, though.
2076
- if "versioneer.py" not in simple_includes :
2077
- print (" appending 'versioneer.py' to MANIFEST.in" )
2078
- with open (manifest_in , "a" ) as f :
2079
- f .write ("include versioneer.py\n " )
2080
- else :
2081
- print (" 'versioneer.py' already in MANIFEST.in" )
2082
- if cfg .versionfile_source not in simple_includes :
2083
- print (" appending versionfile_source ('%s') to MANIFEST.in" %
2084
- cfg .versionfile_source )
2085
- with open (manifest_in , "a" ) as f :
2086
- f .write ("include %s\n " % cfg .versionfile_source )
2087
- else :
2088
- print (" versionfile_source already in MANIFEST.in" )
2089
-
2090
2096
# Make VCS-specific changes. For git, this means creating/changing
2091
2097
# .gitattributes to mark _version.py for export-subst keyword
2092
2098
# substitution.
2093
- do_vcs_install (manifest_in , cfg .versionfile_source , ipy )
2099
+ do_vcs_install (cfg .versionfile_source , ipy )
2094
2100
return 0
2095
2101
2096
2102
0 commit comments