update versioneer

This commit is contained in:
Sebastien Bourdeauducq 2015-11-09 12:19:01 +08:00
parent 594162325b
commit 2df2e141f7
2 changed files with 232 additions and 130 deletions

View File

@ -6,7 +6,9 @@
# that just contains the computed version number. # that just contains the computed version number.
# This file is released into the public domain. Generated by # This file is released into the public domain. Generated by
# versioneer-0.15 (https://github.com/warner/python-versioneer) # versioneer-0.15+dev (https://github.com/warner/python-versioneer)
"""Git implementation of _version.py."""
import errno import errno
import os import os
@ -16,6 +18,7 @@ import sys
def get_keywords(): def get_keywords():
"""Get the keywords needed to look up the version information."""
# these strings will be replaced by git during git-archive. # these strings will be replaced by git during git-archive.
# setup.py/versioneer.py will grep for the variable names, so they must # setup.py/versioneer.py will grep for the variable names, so they must
# each be defined on a line of their own. _version.py will just call # each be defined on a line of their own. _version.py will just call
@ -27,10 +30,12 @@ def get_keywords():
class VersioneerConfig: class VersioneerConfig:
pass
"""Container for Versioneer configuration parameters."""
def get_config(): def get_config():
"""Create, populate and return the VersioneerConfig() object."""
# these strings are filled in when 'setup.py versioneer' creates # these strings are filled in when 'setup.py versioneer' creates
# _version.py # _version.py
cfg = VersioneerConfig() cfg = VersioneerConfig()
@ -44,7 +49,8 @@ def get_config():
class NotThisMethod(Exception): class NotThisMethod(Exception):
pass
"""Exception raised if a method is not valid for the current scenario."""
LONG_VERSION_PY = {} LONG_VERSION_PY = {}
@ -52,7 +58,9 @@ HANDLERS = {}
def register_vcs_handler(vcs, method): # decorator def register_vcs_handler(vcs, method): # decorator
"""Decorator to mark a method as the handler for a particular VCS."""
def decorate(f): def decorate(f):
"""Store f in HANDLERS[vcs][method]."""
if vcs not in HANDLERS: if vcs not in HANDLERS:
HANDLERS[vcs] = {} HANDLERS[vcs] = {}
HANDLERS[vcs][method] = f HANDLERS[vcs][method] = f
@ -61,6 +69,7 @@ def register_vcs_handler(vcs, method): # decorator
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False): def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
"""Call the given command(s)."""
assert isinstance(commands, list) assert isinstance(commands, list)
p = None p = None
for c in commands: for c in commands:
@ -94,8 +103,11 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
def versions_from_parentdir(parentdir_prefix, root, verbose): def versions_from_parentdir(parentdir_prefix, root, verbose):
# Source tarballs conventionally unpack into a directory that includes """Try to determine the version from the parent directory name.
# both the project name and a version string.
Source tarballs conventionally unpack into a directory that includes
both the project name and a version string.
"""
dirname = os.path.basename(root) dirname = os.path.basename(root)
if not dirname.startswith(parentdir_prefix): if not dirname.startswith(parentdir_prefix):
if verbose: if verbose:
@ -109,6 +121,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
@register_vcs_handler("git", "get_keywords") @register_vcs_handler("git", "get_keywords")
def git_get_keywords(versionfile_abs): def git_get_keywords(versionfile_abs):
"""Extract version information from the given file."""
# the code embedded in _version.py can just fetch the value of these # the code embedded in _version.py can just fetch the value of these
# keywords. When used from setup.py, we don't want to import _version.py, # keywords. When used from setup.py, we don't want to import _version.py,
# so we do it with a regexp instead. This function is not used from # so we do it with a regexp instead. This function is not used from
@ -133,6 +146,7 @@ def git_get_keywords(versionfile_abs):
@register_vcs_handler("git", "keywords") @register_vcs_handler("git", "keywords")
def git_versions_from_keywords(keywords, tag_prefix, verbose): def git_versions_from_keywords(keywords, tag_prefix, verbose):
"""Get version information from git keywords."""
if not keywords: if not keywords:
raise NotThisMethod("no keywords at all, weird") raise NotThisMethod("no keywords at all, weird")
refnames = keywords["refnames"].strip() refnames = keywords["refnames"].strip()
@ -178,11 +192,12 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
@register_vcs_handler("git", "pieces_from_vcs") @register_vcs_handler("git", "pieces_from_vcs")
def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
# this runs 'git' from the root of the source tree. This only gets called """Get version from 'git describe' in the root of the source tree.
# if the git-archive 'subst' keywords were *not* expanded, and
# _version.py hasn't already been rewritten with a short version string,
# meaning we're inside a checked out source tree.
This only gets called if the git-archive 'subst' keywords were *not*
expanded, and _version.py hasn't already been rewritten with a short
version string, meaning we're inside a checked out source tree.
"""
if not os.path.exists(os.path.join(root, ".git")): if not os.path.exists(os.path.join(root, ".git")):
if verbose: if verbose:
print("no .git in %s" % root) print("no .git in %s" % root)
@ -191,10 +206,11 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
GITS = ["git"] GITS = ["git"]
if sys.platform == "win32": if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"] GITS = ["git.cmd", "git.exe"]
# if there is a tag, this yields TAG-NUM-gHEX[-dirty] # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
# if there are no tags, this yields HEX[-dirty] (no NUM) # if there isn't one, this yields HEX[-dirty] (no NUM)
describe_out = run_command(GITS, ["describe", "--tags", "--dirty", describe_out = run_command(GITS, ["describe", "--tags", "--dirty",
"--always", "--long"], "--always", "--long",
"--match", "%s*" % tag_prefix],
cwd=root) cwd=root)
# --long was added in git-1.5.5 # --long was added in git-1.5.5
if describe_out is None: if describe_out is None:
@ -259,19 +275,21 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
def plus_or_dot(pieces): def plus_or_dot(pieces):
"""Return a + if we don't already have one, else return a ."""
if "+" in pieces.get("closest-tag", ""): if "+" in pieces.get("closest-tag", ""):
return "." return "."
return "+" return "+"
def render_pep440(pieces): def render_pep440(pieces):
# now build up version string, with post-release "local version """Build up version string, with post-release "local version identifier".
# identifier". Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
# get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
# exceptions: Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
# 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty] get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
Exceptions:
1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]: if pieces["distance"] or pieces["dirty"]:
@ -289,11 +307,11 @@ def render_pep440(pieces):
def render_pep440_pre(pieces): def render_pep440_pre(pieces):
# TAG[.post.devDISTANCE] . No -dirty """TAG[.post.devDISTANCE] -- No -dirty.
# exceptions:
# 1: no tags. 0.post.devDISTANCE
Exceptions:
1: no tags. 0.post.devDISTANCE
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"]: if pieces["distance"]:
@ -305,14 +323,15 @@ def render_pep440_pre(pieces):
def render_pep440_post(pieces): def render_pep440_post(pieces):
# TAG[.postDISTANCE[.dev0]+gHEX] . The ".dev0" means dirty. Note that """TAG[.postDISTANCE[.dev0]+gHEX] .
# .dev0 sorts backwards (a dirty tree will appear "older" than the
# corresponding clean one), but you shouldn't be releasing software with
# -dirty anyways.
# exceptions: The ".dev0" means dirty. Note that .dev0 sorts backwards
# 1: no tags. 0.postDISTANCE[.dev0] (a dirty tree will appear "older" than the corresponding clean one),
but you shouldn't be releasing software with -dirty anyways.
Exceptions:
1: no tags. 0.postDISTANCE[.dev0]
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]: if pieces["distance"] or pieces["dirty"]:
@ -331,11 +350,13 @@ def render_pep440_post(pieces):
def render_pep440_old(pieces): def render_pep440_old(pieces):
# TAG[.postDISTANCE[.dev0]] . The ".dev0" means dirty. """TAG[.postDISTANCE[.dev0]] .
# exceptions: The ".dev0" means dirty.
# 1: no tags. 0.postDISTANCE[.dev0]
Eexceptions:
1: no tags. 0.postDISTANCE[.dev0]
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]: if pieces["distance"] or pieces["dirty"]:
@ -351,12 +372,13 @@ def render_pep440_old(pieces):
def render_git_describe(pieces): def render_git_describe(pieces):
# TAG[-DISTANCE-gHEX][-dirty], like 'git describe --tags --dirty """TAG[-DISTANCE-gHEX][-dirty].
# --always'
# exceptions: Like 'git describe --tags --dirty --always'.
# 1: no tags. HEX[-dirty] (note: no 'g' prefix)
Exceptions:
1: no tags. HEX[-dirty] (note: no 'g' prefix)
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"]: if pieces["distance"]:
@ -370,12 +392,14 @@ def render_git_describe(pieces):
def render_git_describe_long(pieces): def render_git_describe_long(pieces):
# TAG-DISTANCE-gHEX[-dirty], like 'git describe --tags --dirty """TAG-DISTANCE-gHEX[-dirty].
# --always -long'. The distance/hash is unconditional.
# exceptions: Like 'git describe --tags --dirty --always -long'.
# 1: no tags. HEX[-dirty] (note: no 'g' prefix) The distance/hash is unconditional.
Exceptions:
1: no tags. HEX[-dirty] (note: no 'g' prefix)
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
@ -388,6 +412,7 @@ def render_git_describe_long(pieces):
def render(pieces, style): def render(pieces, style):
"""Render the given version pieces into the requested style."""
if pieces["error"]: if pieces["error"]:
return {"version": "unknown", return {"version": "unknown",
"full-revisionid": pieces.get("long"), "full-revisionid": pieces.get("long"),
@ -417,6 +442,7 @@ def render(pieces, style):
def get_versions(): def get_versions():
"""Get version information or return default if unable to do so."""
# I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
# __file__, we can work backwards from there to the root. Some # __file__, we can work backwards from there to the root. Some
# py2exe/bbfreeze/non-CPython implementations don't do __file__, in which # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which

View File

@ -1,7 +1,8 @@
# Version: 0.15 # Version: 0.15+dev
"""The Versioneer - like a rocketeer, but for versions.
"""
The Versioneer The Versioneer
============== ==============
@ -125,16 +126,18 @@ First, decide on values for the following configuration variables:
If this is set to None, then `setup.py build` will not attempt to rewrite If this is set to None, then `setup.py build` will not attempt to rewrite
any `_version.py` in the built tree. If your project does not have any any `_version.py` in the built tree. If your project does not have any
libraries (e.g. if it only builds a script), then you should use libraries (e.g. if it only builds a script), then you should use
`versionfile_build = None` and override `distutils.command.build_scripts` `versionfile_build = None`. To actually use the computed version string,
to explicitly insert a copy of `versioneer.get_version()` into your your `setup.py` will need to override `distutils.command.build_scripts`
generated script. with a subclass that explicitly inserts a copy of
`versioneer.get_version()` into your script file. See
`test/demoapp-script-only/setup.py` for an example.
* `tag_prefix`: * `tag_prefix`:
a string, like 'PROJECTNAME-', which appears at the start of all VCS tags. a string, like 'PROJECTNAME-', which appears at the start of all VCS tags.
If your tags look like 'myproject-1.2.0', then you should use If your tags look like 'myproject-1.2.0', then you should use
tag_prefix='myproject-'. If you use unprefixed tags like '1.2.0', this tag_prefix='myproject-'. If you use unprefixed tags like '1.2.0', this
should be an empty string. should be an empty string, using either `tag_prefix=` or `tag_prefix=''`.
* `parentdir_prefix`: * `parentdir_prefix`:
@ -159,7 +162,7 @@ To versioneer-enable your project:
style = pep440 style = pep440
versionfile_source = src/myproject/_version.py versionfile_source = src/myproject/_version.py
versionfile_build = myproject/_version.py versionfile_build = myproject/_version.py
tag_prefix = "" tag_prefix =
parentdir_prefix = myproject- parentdir_prefix = myproject-
```` ````
@ -333,9 +336,11 @@ number of intermediate scripts.
## License ## License
To make Versioneer easier to embed, all its code is hereby released into the To make Versioneer easier to embed, all its code is dedicated to the public
public domain. The `_version.py` that it creates is also in the public domain. The `_version.py` that it creates is also in the public domain.
domain. Specifically, both are released under the Creative Commons "Public Domain
Dedication" license (CC0-1.0), as described in
https://creativecommons.org/publicdomain/zero/1.0/ .
""" """
@ -353,12 +358,16 @@ import sys
class VersioneerConfig: class VersioneerConfig:
pass
"""Container for Versioneer configuration parameters."""
def get_root(): def get_root():
# we require that all commands are run from the project root, i.e. the """Get the project root directory.
# directory that contains setup.py, setup.cfg, and versioneer.py .
We require that all commands are run from the project root, i.e. the
directory that contains setup.py, setup.cfg, and versioneer.py .
"""
root = os.path.realpath(os.path.abspath(os.getcwd())) root = os.path.realpath(os.path.abspath(os.getcwd()))
setup_py = os.path.join(root, "setup.py") setup_py = os.path.join(root, "setup.py")
versioneer_py = os.path.join(root, "versioneer.py") versioneer_py = os.path.join(root, "versioneer.py")
@ -391,6 +400,7 @@ def get_root():
def get_config_from_root(root): def get_config_from_root(root):
"""Read the project setup.cfg file to determine Versioneer config."""
# This might raise EnvironmentError (if setup.cfg is missing), or # This might raise EnvironmentError (if setup.cfg is missing), or
# configparser.NoSectionError (if it lacks a [versioneer] section), or # configparser.NoSectionError (if it lacks a [versioneer] section), or
# configparser.NoOptionError (if it lacks "VCS="). See the docstring at # configparser.NoOptionError (if it lacks "VCS="). See the docstring at
@ -411,13 +421,16 @@ def get_config_from_root(root):
cfg.versionfile_source = get(parser, "versionfile_source") cfg.versionfile_source = get(parser, "versionfile_source")
cfg.versionfile_build = get(parser, "versionfile_build") cfg.versionfile_build = get(parser, "versionfile_build")
cfg.tag_prefix = get(parser, "tag_prefix") cfg.tag_prefix = get(parser, "tag_prefix")
if cfg.tag_prefix in ("''", '""'):
cfg.tag_prefix = ""
cfg.parentdir_prefix = get(parser, "parentdir_prefix") cfg.parentdir_prefix = get(parser, "parentdir_prefix")
cfg.verbose = get(parser, "verbose") cfg.verbose = get(parser, "verbose")
return cfg return cfg
class NotThisMethod(Exception): class NotThisMethod(Exception):
pass
"""Exception raised if a method is not valid for the current scenario."""
# these dictionaries contain VCS-specific tools # these dictionaries contain VCS-specific tools
LONG_VERSION_PY = {} LONG_VERSION_PY = {}
@ -425,7 +438,9 @@ HANDLERS = {}
def register_vcs_handler(vcs, method): # decorator def register_vcs_handler(vcs, method): # decorator
"""Decorator to mark a method as the handler for a particular VCS."""
def decorate(f): def decorate(f):
"""Store f in HANDLERS[vcs][method]."""
if vcs not in HANDLERS: if vcs not in HANDLERS:
HANDLERS[vcs] = {} HANDLERS[vcs] = {}
HANDLERS[vcs][method] = f HANDLERS[vcs][method] = f
@ -434,6 +449,7 @@ def register_vcs_handler(vcs, method): # decorator
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False): def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
"""Call the given command(s)."""
assert isinstance(commands, list) assert isinstance(commands, list)
p = None p = None
for c in commands: for c in commands:
@ -472,7 +488,9 @@ LONG_VERSION_PY['git'] = '''
# that just contains the computed version number. # that just contains the computed version number.
# This file is released into the public domain. Generated by # This file is released into the public domain. Generated by
# versioneer-0.15 (https://github.com/warner/python-versioneer) # versioneer-0.15+dev (https://github.com/warner/python-versioneer)
"""Git implementation of _version.py."""
import errno import errno
import os import os
@ -482,6 +500,7 @@ import sys
def get_keywords(): def get_keywords():
"""Get the keywords needed to look up the version information."""
# these strings will be replaced by git during git-archive. # these strings will be replaced by git during git-archive.
# setup.py/versioneer.py will grep for the variable names, so they must # setup.py/versioneer.py will grep for the variable names, so they must
# each be defined on a line of their own. _version.py will just call # each be defined on a line of their own. _version.py will just call
@ -493,10 +512,12 @@ def get_keywords():
class VersioneerConfig: class VersioneerConfig:
pass
"""Container for Versioneer configuration parameters."""
def get_config(): def get_config():
"""Create, populate and return the VersioneerConfig() object."""
# these strings are filled in when 'setup.py versioneer' creates # these strings are filled in when 'setup.py versioneer' creates
# _version.py # _version.py
cfg = VersioneerConfig() cfg = VersioneerConfig()
@ -510,7 +531,8 @@ def get_config():
class NotThisMethod(Exception): class NotThisMethod(Exception):
pass
"""Exception raised if a method is not valid for the current scenario."""
LONG_VERSION_PY = {} LONG_VERSION_PY = {}
@ -518,7 +540,9 @@ HANDLERS = {}
def register_vcs_handler(vcs, method): # decorator def register_vcs_handler(vcs, method): # decorator
"""Decorator to mark a method as the handler for a particular VCS."""
def decorate(f): def decorate(f):
"""Store f in HANDLERS[vcs][method]."""
if vcs not in HANDLERS: if vcs not in HANDLERS:
HANDLERS[vcs] = {} HANDLERS[vcs] = {}
HANDLERS[vcs][method] = f HANDLERS[vcs][method] = f
@ -527,6 +551,7 @@ def register_vcs_handler(vcs, method): # decorator
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False): def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
"""Call the given command(s)."""
assert isinstance(commands, list) assert isinstance(commands, list)
p = None p = None
for c in commands: for c in commands:
@ -560,8 +585,11 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
def versions_from_parentdir(parentdir_prefix, root, verbose): def versions_from_parentdir(parentdir_prefix, root, verbose):
# Source tarballs conventionally unpack into a directory that includes """Try to determine the version from the parent directory name.
# both the project name and a version string.
Source tarballs conventionally unpack into a directory that includes
both the project name and a version string.
"""
dirname = os.path.basename(root) dirname = os.path.basename(root)
if not dirname.startswith(parentdir_prefix): if not dirname.startswith(parentdir_prefix):
if verbose: if verbose:
@ -575,6 +603,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
@register_vcs_handler("git", "get_keywords") @register_vcs_handler("git", "get_keywords")
def git_get_keywords(versionfile_abs): def git_get_keywords(versionfile_abs):
"""Extract version information from the given file."""
# the code embedded in _version.py can just fetch the value of these # the code embedded in _version.py can just fetch the value of these
# keywords. When used from setup.py, we don't want to import _version.py, # keywords. When used from setup.py, we don't want to import _version.py,
# so we do it with a regexp instead. This function is not used from # so we do it with a regexp instead. This function is not used from
@ -599,6 +628,7 @@ def git_get_keywords(versionfile_abs):
@register_vcs_handler("git", "keywords") @register_vcs_handler("git", "keywords")
def git_versions_from_keywords(keywords, tag_prefix, verbose): def git_versions_from_keywords(keywords, tag_prefix, verbose):
"""Get version information from git keywords."""
if not keywords: if not keywords:
raise NotThisMethod("no keywords at all, weird") raise NotThisMethod("no keywords at all, weird")
refnames = keywords["refnames"].strip() refnames = keywords["refnames"].strip()
@ -644,11 +674,12 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
@register_vcs_handler("git", "pieces_from_vcs") @register_vcs_handler("git", "pieces_from_vcs")
def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
# this runs 'git' from the root of the source tree. This only gets called """Get version from 'git describe' in the root of the source tree.
# if the git-archive 'subst' keywords were *not* expanded, and
# _version.py hasn't already been rewritten with a short version string,
# meaning we're inside a checked out source tree.
This only gets called if the git-archive 'subst' keywords were *not*
expanded, and _version.py hasn't already been rewritten with a short
version string, meaning we're inside a checked out source tree.
"""
if not os.path.exists(os.path.join(root, ".git")): if not os.path.exists(os.path.join(root, ".git")):
if verbose: if verbose:
print("no .git in %%s" %% root) print("no .git in %%s" %% root)
@ -657,10 +688,11 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
GITS = ["git"] GITS = ["git"]
if sys.platform == "win32": if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"] GITS = ["git.cmd", "git.exe"]
# if there is a tag, this yields TAG-NUM-gHEX[-dirty] # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
# if there are no tags, this yields HEX[-dirty] (no NUM) # if there isn't one, this yields HEX[-dirty] (no NUM)
describe_out = run_command(GITS, ["describe", "--tags", "--dirty", describe_out = run_command(GITS, ["describe", "--tags", "--dirty",
"--always", "--long"], "--always", "--long",
"--match", "%%s*" %% tag_prefix],
cwd=root) cwd=root)
# --long was added in git-1.5.5 # --long was added in git-1.5.5
if describe_out is None: if describe_out is None:
@ -725,19 +757,21 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
def plus_or_dot(pieces): def plus_or_dot(pieces):
"""Return a + if we don't already have one, else return a ."""
if "+" in pieces.get("closest-tag", ""): if "+" in pieces.get("closest-tag", ""):
return "." return "."
return "+" return "+"
def render_pep440(pieces): def render_pep440(pieces):
# now build up version string, with post-release "local version """Build up version string, with post-release "local version identifier".
# identifier". Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
# get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
# exceptions: Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
# 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty] get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
Exceptions:
1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]: if pieces["distance"] or pieces["dirty"]:
@ -755,11 +789,11 @@ def render_pep440(pieces):
def render_pep440_pre(pieces): def render_pep440_pre(pieces):
# TAG[.post.devDISTANCE] . No -dirty """TAG[.post.devDISTANCE] -- No -dirty.
# exceptions:
# 1: no tags. 0.post.devDISTANCE
Exceptions:
1: no tags. 0.post.devDISTANCE
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"]: if pieces["distance"]:
@ -771,14 +805,15 @@ def render_pep440_pre(pieces):
def render_pep440_post(pieces): def render_pep440_post(pieces):
# TAG[.postDISTANCE[.dev0]+gHEX] . The ".dev0" means dirty. Note that """TAG[.postDISTANCE[.dev0]+gHEX] .
# .dev0 sorts backwards (a dirty tree will appear "older" than the
# corresponding clean one), but you shouldn't be releasing software with
# -dirty anyways.
# exceptions: The ".dev0" means dirty. Note that .dev0 sorts backwards
# 1: no tags. 0.postDISTANCE[.dev0] (a dirty tree will appear "older" than the corresponding clean one),
but you shouldn't be releasing software with -dirty anyways.
Exceptions:
1: no tags. 0.postDISTANCE[.dev0]
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]: if pieces["distance"] or pieces["dirty"]:
@ -797,11 +832,13 @@ def render_pep440_post(pieces):
def render_pep440_old(pieces): def render_pep440_old(pieces):
# TAG[.postDISTANCE[.dev0]] . The ".dev0" means dirty. """TAG[.postDISTANCE[.dev0]] .
# exceptions: The ".dev0" means dirty.
# 1: no tags. 0.postDISTANCE[.dev0]
Eexceptions:
1: no tags. 0.postDISTANCE[.dev0]
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]: if pieces["distance"] or pieces["dirty"]:
@ -817,12 +854,13 @@ def render_pep440_old(pieces):
def render_git_describe(pieces): def render_git_describe(pieces):
# TAG[-DISTANCE-gHEX][-dirty], like 'git describe --tags --dirty """TAG[-DISTANCE-gHEX][-dirty].
# --always'
# exceptions: Like 'git describe --tags --dirty --always'.
# 1: no tags. HEX[-dirty] (note: no 'g' prefix)
Exceptions:
1: no tags. HEX[-dirty] (note: no 'g' prefix)
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"]: if pieces["distance"]:
@ -836,12 +874,14 @@ def render_git_describe(pieces):
def render_git_describe_long(pieces): def render_git_describe_long(pieces):
# TAG-DISTANCE-gHEX[-dirty], like 'git describe --tags --dirty """TAG-DISTANCE-gHEX[-dirty].
# --always -long'. The distance/hash is unconditional.
# exceptions: Like 'git describe --tags --dirty --always -long'.
# 1: no tags. HEX[-dirty] (note: no 'g' prefix) The distance/hash is unconditional.
Exceptions:
1: no tags. HEX[-dirty] (note: no 'g' prefix)
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
rendered += "-%%d-g%%s" %% (pieces["distance"], pieces["short"]) rendered += "-%%d-g%%s" %% (pieces["distance"], pieces["short"])
@ -854,6 +894,7 @@ def render_git_describe_long(pieces):
def render(pieces, style): def render(pieces, style):
"""Render the given version pieces into the requested style."""
if pieces["error"]: if pieces["error"]:
return {"version": "unknown", return {"version": "unknown",
"full-revisionid": pieces.get("long"), "full-revisionid": pieces.get("long"),
@ -883,6 +924,7 @@ def render(pieces, style):
def get_versions(): def get_versions():
"""Get version information or return default if unable to do so."""
# I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
# __file__, we can work backwards from there to the root. Some # __file__, we can work backwards from there to the root. Some
# py2exe/bbfreeze/non-CPython implementations don't do __file__, in which # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which
@ -929,6 +971,7 @@ def get_versions():
@register_vcs_handler("git", "get_keywords") @register_vcs_handler("git", "get_keywords")
def git_get_keywords(versionfile_abs): def git_get_keywords(versionfile_abs):
"""Extract version information from the given file."""
# the code embedded in _version.py can just fetch the value of these # the code embedded in _version.py can just fetch the value of these
# keywords. When used from setup.py, we don't want to import _version.py, # keywords. When used from setup.py, we don't want to import _version.py,
# so we do it with a regexp instead. This function is not used from # so we do it with a regexp instead. This function is not used from
@ -953,6 +996,7 @@ def git_get_keywords(versionfile_abs):
@register_vcs_handler("git", "keywords") @register_vcs_handler("git", "keywords")
def git_versions_from_keywords(keywords, tag_prefix, verbose): def git_versions_from_keywords(keywords, tag_prefix, verbose):
"""Get version information from git keywords."""
if not keywords: if not keywords:
raise NotThisMethod("no keywords at all, weird") raise NotThisMethod("no keywords at all, weird")
refnames = keywords["refnames"].strip() refnames = keywords["refnames"].strip()
@ -998,11 +1042,12 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
@register_vcs_handler("git", "pieces_from_vcs") @register_vcs_handler("git", "pieces_from_vcs")
def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
# this runs 'git' from the root of the source tree. This only gets called """Get version from 'git describe' in the root of the source tree.
# if the git-archive 'subst' keywords were *not* expanded, and
# _version.py hasn't already been rewritten with a short version string,
# meaning we're inside a checked out source tree.
This only gets called if the git-archive 'subst' keywords were *not*
expanded, and _version.py hasn't already been rewritten with a short
version string, meaning we're inside a checked out source tree.
"""
if not os.path.exists(os.path.join(root, ".git")): if not os.path.exists(os.path.join(root, ".git")):
if verbose: if verbose:
print("no .git in %s" % root) print("no .git in %s" % root)
@ -1011,10 +1056,11 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
GITS = ["git"] GITS = ["git"]
if sys.platform == "win32": if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"] GITS = ["git.cmd", "git.exe"]
# if there is a tag, this yields TAG-NUM-gHEX[-dirty] # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
# if there are no tags, this yields HEX[-dirty] (no NUM) # if there isn't one, this yields HEX[-dirty] (no NUM)
describe_out = run_command(GITS, ["describe", "--tags", "--dirty", describe_out = run_command(GITS, ["describe", "--tags", "--dirty",
"--always", "--long"], "--always", "--long",
"--match", "%s*" % tag_prefix],
cwd=root) cwd=root)
# --long was added in git-1.5.5 # --long was added in git-1.5.5
if describe_out is None: if describe_out is None:
@ -1079,6 +1125,11 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
def do_vcs_install(manifest_in, versionfile_source, ipy): def do_vcs_install(manifest_in, versionfile_source, ipy):
"""Git-specific installation logic for Versioneer.
For Git, this means creating/changing .gitattributes to mark _version.py
for export-time keyword substitution.
"""
GITS = ["git"] GITS = ["git"]
if sys.platform == "win32": if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"] GITS = ["git.cmd", "git.exe"]
@ -1112,8 +1163,11 @@ def do_vcs_install(manifest_in, versionfile_source, ipy):
def versions_from_parentdir(parentdir_prefix, root, verbose): def versions_from_parentdir(parentdir_prefix, root, verbose):
# Source tarballs conventionally unpack into a directory that includes """Try to determine the version from the parent directory name.
# both the project name and a version string.
Source tarballs conventionally unpack into a directory that includes
both the project name and a version string.
"""
dirname = os.path.basename(root) dirname = os.path.basename(root)
if not dirname.startswith(parentdir_prefix): if not dirname.startswith(parentdir_prefix):
if verbose: if verbose:
@ -1125,7 +1179,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
"dirty": False, "error": None} "dirty": False, "error": None}
SHORT_VERSION_PY = """ SHORT_VERSION_PY = """
# This file was generated by 'versioneer.py' (0.15) from # This file was generated by 'versioneer.py' (0.15+dev) from
# revision-control system data, or from the parent directory name of an # revision-control system data, or from the parent directory name of an
# unpacked source archive. Distribution tarballs contain a pre-generated copy # unpacked source archive. Distribution tarballs contain a pre-generated copy
# of this file. # of this file.
@ -1144,6 +1198,7 @@ def get_versions():
def versions_from_file(filename): def versions_from_file(filename):
"""Try to determine the version from _version.py if present."""
try: try:
with open(filename) as f: with open(filename) as f:
contents = f.read() contents = f.read()
@ -1157,6 +1212,7 @@ def versions_from_file(filename):
def write_to_version_file(filename, versions): def write_to_version_file(filename, versions):
"""Write the given version number to the given _version.py file."""
os.unlink(filename) os.unlink(filename)
contents = json.dumps(versions, sort_keys=True, contents = json.dumps(versions, sort_keys=True,
indent=1, separators=(",", ": ")) indent=1, separators=(",", ": "))
@ -1167,19 +1223,21 @@ def write_to_version_file(filename, versions):
def plus_or_dot(pieces): def plus_or_dot(pieces):
"""Return a + if we don't already have one, else return a ."""
if "+" in pieces.get("closest-tag", ""): if "+" in pieces.get("closest-tag", ""):
return "." return "."
return "+" return "+"
def render_pep440(pieces): def render_pep440(pieces):
# now build up version string, with post-release "local version """Build up version string, with post-release "local version identifier".
# identifier". Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
# get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
# exceptions: Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
# 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty] get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
Exceptions:
1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]: if pieces["distance"] or pieces["dirty"]:
@ -1197,11 +1255,11 @@ def render_pep440(pieces):
def render_pep440_pre(pieces): def render_pep440_pre(pieces):
# TAG[.post.devDISTANCE] . No -dirty """TAG[.post.devDISTANCE] -- No -dirty.
# exceptions:
# 1: no tags. 0.post.devDISTANCE
Exceptions:
1: no tags. 0.post.devDISTANCE
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"]: if pieces["distance"]:
@ -1213,14 +1271,15 @@ def render_pep440_pre(pieces):
def render_pep440_post(pieces): def render_pep440_post(pieces):
# TAG[.postDISTANCE[.dev0]+gHEX] . The ".dev0" means dirty. Note that """TAG[.postDISTANCE[.dev0]+gHEX] .
# .dev0 sorts backwards (a dirty tree will appear "older" than the
# corresponding clean one), but you shouldn't be releasing software with
# -dirty anyways.
# exceptions: The ".dev0" means dirty. Note that .dev0 sorts backwards
# 1: no tags. 0.postDISTANCE[.dev0] (a dirty tree will appear "older" than the corresponding clean one),
but you shouldn't be releasing software with -dirty anyways.
Exceptions:
1: no tags. 0.postDISTANCE[.dev0]
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]: if pieces["distance"] or pieces["dirty"]:
@ -1239,11 +1298,13 @@ def render_pep440_post(pieces):
def render_pep440_old(pieces): def render_pep440_old(pieces):
# TAG[.postDISTANCE[.dev0]] . The ".dev0" means dirty. """TAG[.postDISTANCE[.dev0]] .
# exceptions: The ".dev0" means dirty.
# 1: no tags. 0.postDISTANCE[.dev0]
Eexceptions:
1: no tags. 0.postDISTANCE[.dev0]
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]: if pieces["distance"] or pieces["dirty"]:
@ -1259,12 +1320,13 @@ def render_pep440_old(pieces):
def render_git_describe(pieces): def render_git_describe(pieces):
# TAG[-DISTANCE-gHEX][-dirty], like 'git describe --tags --dirty """TAG[-DISTANCE-gHEX][-dirty].
# --always'
# exceptions: Like 'git describe --tags --dirty --always'.
# 1: no tags. HEX[-dirty] (note: no 'g' prefix)
Exceptions:
1: no tags. HEX[-dirty] (note: no 'g' prefix)
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"]: if pieces["distance"]:
@ -1278,12 +1340,14 @@ def render_git_describe(pieces):
def render_git_describe_long(pieces): def render_git_describe_long(pieces):
# TAG-DISTANCE-gHEX[-dirty], like 'git describe --tags --dirty """TAG-DISTANCE-gHEX[-dirty].
# --always -long'. The distance/hash is unconditional.
# exceptions: Like 'git describe --tags --dirty --always -long'.
# 1: no tags. HEX[-dirty] (note: no 'g' prefix) The distance/hash is unconditional.
Exceptions:
1: no tags. HEX[-dirty] (note: no 'g' prefix)
"""
if pieces["closest-tag"]: if pieces["closest-tag"]:
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
@ -1296,6 +1360,7 @@ def render_git_describe_long(pieces):
def render(pieces, style): def render(pieces, style):
"""Render the given version pieces into the requested style."""
if pieces["error"]: if pieces["error"]:
return {"version": "unknown", return {"version": "unknown",
"full-revisionid": pieces.get("long"), "full-revisionid": pieces.get("long"),
@ -1325,12 +1390,15 @@ def render(pieces, style):
class VersioneerBadRootError(Exception): class VersioneerBadRootError(Exception):
pass
"""The project root directory is unknown or missing key files."""
def get_versions(verbose=False): def get_versions(verbose=False):
# returns dict with two keys: 'version' and 'full' """Get the project version from whatever source is available.
Returns dict with two keys: 'version' and 'full'.
"""
if "versioneer" in sys.modules: if "versioneer" in sys.modules:
# see the discussion in cmdclass.py:get_cmdclass() # see the discussion in cmdclass.py:get_cmdclass()
del sys.modules["versioneer"] del sys.modules["versioneer"]
@ -1402,10 +1470,12 @@ def get_versions(verbose=False):
def get_version(): def get_version():
"""Get the short version string for this project."""
return get_versions()["version"] return get_versions()["version"]
def get_cmdclass(): def get_cmdclass():
"""Get the custom setuptools/distutils subclasses used by Versioneer."""
if "versioneer" in sys.modules: if "versioneer" in sys.modules:
del sys.modules["versioneer"] del sys.modules["versioneer"]
# this fixes the "python setup.py develop" case (also 'install' and # this fixes the "python setup.py develop" case (also 'install' and
@ -1456,7 +1526,11 @@ def get_cmdclass():
# setuptools/install -> bdist_egg ->.. # setuptools/install -> bdist_egg ->..
# setuptools/develop -> ? # setuptools/develop -> ?
from distutils.command.build_py import build_py as _build_py # we override different "build_py" commands for both environments
if "setuptools" in sys.modules:
from setuptools.command.build_py import build_py as _build_py
else:
from distutils.command.build_py import build_py as _build_py
class cmd_build_py(_build_py): class cmd_build_py(_build_py):
def run(self): def run(self):
@ -1539,7 +1613,7 @@ a section like:
style = pep440 style = pep440
versionfile_source = src/myproject/_version.py versionfile_source = src/myproject/_version.py
versionfile_build = myproject/_version.py versionfile_build = myproject/_version.py
tag_prefix = "" tag_prefix =
parentdir_prefix = myproject- parentdir_prefix = myproject-
You will also need to edit your setup.py to use the results: You will also need to edit your setup.py to use the results:
@ -1575,6 +1649,7 @@ del get_versions
def do_setup(): def do_setup():
"""Main VCS-independent setup function for installing Versioneer."""
root = get_root() root = get_root()
try: try:
cfg = get_config_from_root(root) cfg = get_config_from_root(root)
@ -1656,6 +1731,7 @@ def do_setup():
def scan_setup_py(): def scan_setup_py():
"""Validate the contents of setup.py against Versioneer's expectations."""
found = set() found = set()
setters = False setters = False
errors = 0 errors = 0