Skip to content

Commit 1a1b913

Browse files
committed
MNT: Upgrade versioneer
1 parent cd62de6 commit 1a1b913

File tree

1 file changed

+79
-73
lines changed

1 file changed

+79
-73
lines changed

versioneer.py

Lines changed: 79 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# Version: 0.22
2+
# Version: 0.23
33

44
"""The Versioneer - like a rocketeer, but for versions.
55
@@ -9,8 +9,8 @@
99
* like a rocketeer, but for versions!
1010
* https://github.com/python-versioneer/python-versioneer
1111
* 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
1414
* [![Latest Version][pypi-image]][pypi-url]
1515
* [![Build Status][travis-image]][travis-url]
1616
@@ -355,7 +355,7 @@ def get_config_from_root(root):
355355
cfg.versionfile_source = section.get("versionfile_source")
356356
cfg.versionfile_build = section.get("versionfile_build")
357357
cfg.tag_prefix = section.get("tag_prefix")
358-
if cfg.tag_prefix in ("''", '""'):
358+
if cfg.tag_prefix in ("''", '""', None):
359359
cfg.tag_prefix = ""
360360
cfg.parentdir_prefix = section.get("parentdir_prefix")
361361
cfg.verbose = section.get("verbose")
@@ -431,7 +431,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
431431
# that just contains the computed version number.
432432
433433
# 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)
435435
436436
"""Git implementation of _version.py."""
437437
@@ -679,13 +679,12 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
679679
print("Directory %%s not under git control" %% root)
680680
raise NotThisMethod("'git rev-parse --git-dir' returned error")
681681
682-
MATCH_ARGS = ["--match", "%%s*" %% tag_prefix] if tag_prefix else []
683-
684682
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
685683
# 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)
689688
# --long was added in git-1.5.5
690689
if describe_out is None:
691690
raise NotThisMethod("'git describe' failed")
@@ -774,8 +773,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
774773
else:
775774
# HEX: no tags
776775
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
779778
780779
# commit date: see ISO-8601 comment in git_versions_from_keywords()
781780
date = runner(GITS, ["show", "-s", "--format=%%ci", "HEAD"], cwd=root)[0].strip()
@@ -871,7 +870,7 @@ def render_pep440_pre(pieces):
871870
tag_version, post_version = pep440_split_post(pieces["closest-tag"])
872871
rendered = tag_version
873872
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"])
875874
else:
876875
rendered += ".post0.dev%%d" %% (pieces["distance"])
877876
else:
@@ -1202,13 +1201,12 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
12021201
print("Directory %s not under git control" % root)
12031202
raise NotThisMethod("'git rev-parse --git-dir' returned error")
12041203

1205-
MATCH_ARGS = ["--match", "%s*" % tag_prefix] if tag_prefix else []
1206-
12071204
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
12081205
# 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)
12121210
# --long was added in git-1.5.5
12131211
if describe_out is None:
12141212
raise NotThisMethod("'git describe' failed")
@@ -1297,8 +1295,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
12971295
else:
12981296
# HEX: no tags
12991297
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
13021300

13031301
# commit date: see ISO-8601 comment in git_versions_from_keywords()
13041302
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):
13101308
return pieces
13111309

13121310

1313-
def do_vcs_install(manifest_in, versionfile_source, ipy):
1311+
def do_vcs_install(versionfile_source, ipy):
13141312
"""Git-specific installation logic for Versioneer.
13151313
13161314
For Git, this means creating/changing .gitattributes to mark _version.py
@@ -1319,7 +1317,7 @@ def do_vcs_install(manifest_in, versionfile_source, ipy):
13191317
GITS = ["git"]
13201318
if sys.platform == "win32":
13211319
GITS = ["git.cmd", "git.exe"]
1322-
files = [manifest_in, versionfile_source]
1320+
files = [versionfile_source]
13231321
if ipy:
13241322
files.append(ipy)
13251323
try:
@@ -1372,7 +1370,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
13721370

13731371

13741372
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
13761374
# revision-control system data, or from the parent directory name of an
13771375
# unpacked source archive. Distribution tarballs contain a pre-generated copy
13781376
# of this file.
@@ -1501,7 +1499,7 @@ def render_pep440_pre(pieces):
15011499
tag_version, post_version = pep440_split_post(pieces["closest-tag"])
15021500
rendered = tag_version
15031501
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"])
15051503
else:
15061504
rendered += ".post0.dev%d" % (pieces["distance"])
15071505
else:
@@ -1753,7 +1751,7 @@ def get_version():
17531751

17541752

17551753
def get_cmdclass(cmdclass=None):
1756-
"""Get the custom setuptools/distutils subclasses used by Versioneer.
1754+
"""Get the custom setuptools subclasses used by Versioneer.
17571755
17581756
If the package uses a different cmdclass (e.g. one from numpy), it
17591757
should be provide as an argument.
@@ -1775,11 +1773,8 @@ def get_cmdclass(cmdclass=None):
17751773

17761774
cmds = {} if cmdclass is None else cmdclass.copy()
17771775

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
17831778

17841779
class cmd_version(Command):
17851780
description = "report generated version string"
@@ -1802,7 +1797,7 @@ def run(self):
18021797
print(" error: %s" % vers["error"])
18031798
cmds["version"] = cmd_version
18041799

1805-
# we override "build_py" in both distutils and setuptools
1800+
# we override "build_py" in setuptools
18061801
#
18071802
# most invocation pathways end up running build_py:
18081803
# distutils/build -> build_py
@@ -1817,20 +1812,25 @@ def run(self):
18171812
# then does setup.py bdist_wheel, or sometimes setup.py install
18181813
# setup.py egg_info -> ?
18191814

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+
18201818
# we override different "build_py" commands for both environments
18211819
if 'build_py' in cmds:
18221820
_build_py = cmds['build_py']
1823-
elif "setuptools" in sys.modules:
1824-
from setuptools.command.build_py import build_py as _build_py
18251821
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
18271823

18281824
class cmd_build_py(_build_py):
18291825
def run(self):
18301826
root = get_root()
18311827
cfg = get_config_from_root(root)
18321828
versions = get_versions()
18331829
_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
18341834
# now locate _version.py in the new build/ directory and replace
18351835
# it with an updated value
18361836
if cfg.versionfile_build:
@@ -1842,10 +1842,8 @@ def run(self):
18421842

18431843
if 'build_ext' in cmds:
18441844
_build_ext = cmds['build_ext']
1845-
elif "setuptools" in sys.modules:
1846-
from setuptools.command.build_ext import build_ext as _build_ext
18471845
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
18491847

18501848
class cmd_build_ext(_build_ext):
18511849
def run(self):
@@ -1863,6 +1861,11 @@ def run(self):
18631861
# it with an updated value
18641862
target_versionfile = os.path.join(self.build_lib,
18651863
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
18661869
print("UPDATING %s" % target_versionfile)
18671870
write_to_version_file(target_versionfile, versions)
18681871
cmds["build_ext"] = cmd_build_ext
@@ -1924,13 +1927,48 @@ def run(self):
19241927
})
19251928
cmds["py2exe"] = cmd_py2exe
19261929

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+
19271967
# we override different "sdist" commands for both environments
19281968
if 'sdist' in cmds:
19291969
_sdist = cmds['sdist']
1930-
elif "setuptools" in sys.modules:
1931-
from setuptools.command.sdist import sdist as _sdist
19321970
else:
1933-
from distutils.command.sdist import sdist as _sdist
1971+
from setuptools.command.sdist import sdist as _sdist
19341972

19351973
class cmd_sdist(_sdist):
19361974
def run(self):
@@ -2055,42 +2093,10 @@ def do_setup():
20552093
print(" %s doesn't exist, ok" % ipy)
20562094
ipy = None
20572095

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-
20902096
# Make VCS-specific changes. For git, this means creating/changing
20912097
# .gitattributes to mark _version.py for export-subst keyword
20922098
# substitution.
2093-
do_vcs_install(manifest_in, cfg.versionfile_source, ipy)
2099+
do_vcs_install(cfg.versionfile_source, ipy)
20942100
return 0
20952101

20962102

0 commit comments

Comments
 (0)