/usr/lib/python2.7/dist-packages/vcversioner.py is in python-vcversioner 1.13.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | # Copyright (c) 2013, Aaron Gallagher <_@habnab.it>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
"""Simplify your python project versioning.
In-depth docs online: https://vcversioner.readthedocs.org/en/latest/
Code online: https://github.com/habnabit/vcversioner
"""
from __future__ import print_function, unicode_literals
import collections
import os
import subprocess
Version = collections.namedtuple('Version', 'version commits sha')
_print = print
def print(*a, **kw):
_print('vcversioner:', *a, **kw)
def find_version(include_dev_version=True, root='%(pwd)s',
version_file='%(root)s/version.txt', version_module_paths=(),
git_args=('git', '--git-dir', '%(root)s/.git', 'describe',
'--tags', '--long'),
Popen=subprocess.Popen):
"""Find an appropriate version number from version control.
It's much more convenient to be able to use your version control system's
tagging mechanism to derive a version number than to have to duplicate that
information all over the place. Currently, only git is supported.
The default behavior is to write out a ``version.txt`` file which contains
the git output, for systems where git isn't installed or there is no .git
directory present. ``version.txt`` can (and probably should!) be packaged
in release tarballs by way of the ``MANIFEST.in`` file.
:param include_dev_version: By default, if there are any commits after the
most recent tag (as reported by git), that
number will be included in the version number
as a ``.dev`` suffix. For example, if the most
recent tag is ``1.0`` and there have been three
commits after that tag, the version number will
be ``1.0.dev3``. This behavior can be disabled
by setting this parameter to ``False``.
:param root: The directory of the repository root. The default value is the
current working directory, since when running ``setup.py``,
this is often (but not always) the same as the current working
directory. Standard substitutions are performed on this value.
:param version_file: The name of the file where version information will be
saved. Reading and writing version files can be
disabled altogether by setting this parameter to
``None``. Standard substitutions are performed on this
value.
:param version_module_paths: A list of python modules which will be
automatically generated containing
``__version__`` and ``__sha__`` attributes.
For example, with ``package/_version.py`` as a
version module path, ``package/__init__.py``
could do ``from package._version import
__version__, __sha__``.
:param git_args: The git command to run to get a version. By default, this
is ``git --git-dir %(root)s/.git describe --tags --long``.
``--git-dir`` is used to prevent contamination from git
repositories which aren't the git repository of your
project. Specify this as a list of string arguments
including ``git``, e.g. ``['git', 'describe']``. Standard
substitutions are performed on each value in the provided
list.
:param Popen: Defaults to ``subprocess.Popen``. This is for testing.
*root*, *version_file*, and *git_args* each support some substitutions:
``%(root)s``
The value provided for *root*. This is not available for the *root*
parameter itself.
``%(pwd)s``
The current working directory.
"""
substitutions = {'pwd': os.getcwd()}
substitutions['root'] = root % substitutions
git_args = [arg % substitutions for arg in git_args]
if version_file is not None:
version_file %= substitutions
# try to pull the version from git, or (perhaps) fall back on a
# previously-saved version.
try:
proc = Popen(git_args, stdout=subprocess.PIPE)
except OSError:
raw_version = None
else:
raw_version = proc.communicate()[0].strip().decode()
version_source = 'git'
# git failed if the string is empty
if not raw_version:
if version_file is None:
print('%r failed' % (git_args,))
raise SystemExit(2)
elif not os.path.exists(version_file):
print("%r failed and %r isn't present." % (git_args, version_file))
print("are you installing from a github tarball?")
raise SystemExit(2)
print("couldn't determine version from git; using %r" % version_file)
with open(version_file, 'r') as infile:
raw_version = infile.read()
version_source = repr(version_file)
# try to parse the version into something usable.
try:
tag_version, commits, sha = raw_version.rsplit('-', 2)
except ValueError:
print("%r (from %s) couldn't be parsed into a version" % (
raw_version, version_source))
raise SystemExit(2)
if version_file is not None:
with open(version_file, 'w') as outfile:
outfile.write(raw_version)
if commits == '0' or not include_dev_version:
version = tag_version
else:
version = '%s.dev%s' % (tag_version, commits)
for path in version_module_paths:
with open(path, 'w') as outfile:
outfile.write("""
# This file is automatically generated by setup.py.
__version__ = %s
__sha__ = %s
""" % (repr(version).lstrip('u'), repr(sha).lstrip('u')))
return Version(version, commits, sha)
def setup(dist, attr, value):
"""A hook for simplifying ``vcversioner`` use from distutils.
This hook, when installed properly, allows vcversioner to automatically run
when specifying a ``vcversioner`` argument to ``setup``. For example::
from setuptools import setup
setup(
setup_requires=['vcversioner'],
vcversioner={},
)
The parameter to the ``vcversioner`` argument is a dict of keyword
arguments which :func:`find_version` will be called with.
"""
dist.version = dist.metadata.version = find_version(**value).version
|