Skip to content

Commit

Permalink
dvc: version: use autogenerated file to properly report version
Browse files Browse the repository at this point in the history
Fixes iterative#620

Signed-off-by: Ruslan Kuprieiev <[email protected]>
  • Loading branch information
efiop committed Apr 5, 2018
1 parent 2bddeb5 commit 8ba4139
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ innosetup/config.ini

.coverage

dvc/version.py
45 changes: 35 additions & 10 deletions dvc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,43 @@
"""
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__

0 comments on commit 8ba4139

Please sign in to comment.