diff --git a/.gitignore b/.gitignore index f29dd026c6..3f25a701e5 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ innosetup/config.ini .coverage +dvc/version.py diff --git a/dvc/__init__.py b/dvc/__init__.py index 8f959501b0..1a2185000b 100644 --- a/dvc/__init__.py +++ b/dvc/__init__.py @@ -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__