dvc: version: use autogenerated file to properly report version

Fixes #620

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2018-04-06 01:30:50 +03:00
parent 2bddeb5993
commit 8ba4139f3c
2 changed files with 36 additions and 10 deletions
+1
View File
@@ -23,3 +23,4 @@ innosetup/config.ini
.coverage
dvc/version.py
+35 -10
View File
@@ -5,18 +5,43 @@ Make your data science projects reproducible and shareable.
"""
import os
VERSION = '0.9.5'
__version__ = '0.9.5'
if os.getenv('APPVEYOR_REPO_TAG', '').lower() != 'true' and os.getenv('TRAVIS_TAG', '') == '':
# Dynamically update version
PACKAGEPATH = os.path.abspath(os.path.dirname(__file__))
HOMEPATH = os.path.dirname(PACKAGEPATH)
VERSIONPATH = os.path.join(PACKAGEPATH, 'version.py')
if os.path.exists(os.path.join(HOMEPATH, 'setup.py')):
# dvc is run directly from source without installation or
# __version__ is called from setup.py
if os.getenv('APPVEYOR_REPO_TAG', '').lower() != 'true' and os.getenv('TRAVIS_TAG', '') == '':
# Dynamically update version
try:
import git
repo = git.Repo(HOMEPATH)
sha = repo.head.object.hexsha
short_sha = repo.git.rev_parse(sha, short=6)
dirty = '.mod' if repo.is_dirty() else ''
__version__ = '{}+{}{}'.format(__version__, short_sha, dirty)
# Write a helper file, that will be installed with the package
# and will provide a true version of the installed dvc
with open(VERSIONPATH, 'w+') as fd:
fd.write('# AUTOGENERATED by dvc/__init__.py')
fd.write('version = "{}"'.format(__version__))
except:
pass
else:
# Remove version.py so that it doesn't get into the release
if os.path.exists(VERSIONPATH):
os.unlink(VERSIONPATH)
else:
# dvc was installed with pip or something. Hopefully we have our
# auto-generated version.py to help us provide a true version
try:
import git
repo = git.Repo(os.curdir, search_parent_directories=True)
sha = repo.head.object.hexsha
short_sha = repo.git.rev_parse(sha, short=6)
dirty = '.mod' if repo.is_dirty() else ''
VERSION = '{}+{}{}'.format(VERSION, short_sha, dirty)
from dvc.version import version
__version__ = version
except:
pass
__version__ = VERSION
VERSION = __version__