/usr/lib/python3/dist-packages/multipletau/_version.py is in python3-multipletau 0.1.7+ds-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 | #!/usr/bin/env python
"""
Determine package version for git repositories.
Each time this file is imported it checks if the ".git" folder is
present and if so, obtains the version from the git history using
`git describe`. This information is then stored in the file
`_version_save.py` which is not versioned by git, but distributed
along with e.g. pypi.
"""
from __future__ import print_function
# Put the entire script into a `True` statement and add the hint
# `pragma: no cover` to ignore code coverage here.
if True: # pragma: no cover
import imp
import os
from os.path import join, abspath, dirname
import subprocess
import sys
import time
import traceback
import warnings
def git_describe():
"""
Returns a string describing the version returned by the
command `git describe --tags HEAD`.
If it is not possible to determine the correct version,
then an empty string is returned.
"""
# make sure we are in a directory that belongs to the correct
# repository.
ourdir = dirname(abspath(__file__))
def _minimal_ext_cmd(cmd):
# construct minimal environment
env = {}
for k in ['SYSTEMROOT', 'PATH']:
v = os.environ.get(k)
if v is not None:
env[k] = v
# LANGUAGE is used on win32
env['LANGUAGE'] = 'C'
env['LANG'] = 'C'
env['LC_ALL'] = 'C'
cmd = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env)
out = cmd.communicate()[0]
return out
# change directory
olddir = abspath(os.curdir)
os.chdir(ourdir)
try:
out = _minimal_ext_cmd(['git', 'describe', '--tags', 'HEAD'])
GIT_REVISION = out.strip().decode('ascii')
except OSError:
GIT_REVISION = ""
# go back to original directory
os.chdir(olddir)
return GIT_REVISION
def load_version(versionfile):
""" load version from version_save.py
"""
longversion = ""
try:
_version_save = imp.load_source("_version_save", versionfile)
longversion = _version_save.longversion
except BaseException:
try:
from ._version_save import longversion
except BaseException:
try:
from _version_save import longversion
except BaseException:
pass
return longversion
def save_version(version, versionfile):
""" save version to version_save.py
"""
data = "#!/usr/bin/env python\n" \
+ "# This file was created automatically\n" \
+ "longversion='{VERSION}'"
try:
with open(versionfile, "w") as fd:
fd.write(data.format(VERSION=version))
except BaseException:
msg = "Could not write package version to {}.".format(versionfile)
warnings.warn(msg)
versionfile = join(dirname(abspath(__file__)), "_version_save.py")
# Determine the accurate version
longversion = ""
# 1. git describe
try:
# Get the version using `git describe`
longversion = git_describe()
except BaseException:
pass
# 2. previously created version file
if longversion == "":
# Either this is this is not a git repository or we are in the
# wrong git repository.
# Get the version from the previously generated `_version_save.py`
longversion = load_version(versionfile)
# 3. last resort: date
if longversion == "":
print("Could not determine version. Reason:")
print(traceback.format_exc())
ctime = os.stat(__file__)[8]
longversion = time.strftime("%Y.%m.%d-%H-%M-%S", time.gmtime(ctime))
print("Using creation time as version: {}".format(longversion))
if not hasattr(sys, 'frozen'):
# Save the version to `_version_save.py` to allow distribution using
# `python setup.py sdist`.
# This is only done if the program is not frozen (with e.g.
# pyinstaller),
if longversion != load_version(versionfile):
save_version(longversion, versionfile)
# PEP 440-conform development version:
version = ".dev".join(longversion.split("-")[:2])
|