"""
DVC
----
Make your data science projects reproducible and shareable.
"""
import os
import warnings


VERSION_BASE = '0.23.2'
__version__ = VERSION_BASE

PACKAGEPATH = os.path.abspath(os.path.dirname(__file__))
HOMEPATH = os.path.dirname(PACKAGEPATH)
VERSIONPATH = os.path.join(PACKAGEPATH, 'version.py')


def _update_version_file():
    """Dynamically update version file."""
    from git import Repo
    from git.exc import InvalidGitRepositoryError

    try:
        repo = Repo(HOMEPATH)
    except InvalidGitRepositoryError:
        return __version__

    sha = repo.head.object.hexsha
    short_sha = repo.git.rev_parse(sha, short=6)
    dirty = '.mod' if repo.is_dirty() else ''
    ver = '{}+{}{}'.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 fobj:
        fobj.write('# AUTOGENERATED by dvc/__init__.py\n')
        fobj.write('version = "{}"\n'.format(ver))

    return ver


def _remove_version_file():
    """Remove version.py so that it doesn't get into the release."""
    if os.path.exists(VERSIONPATH):
        os.unlink(VERSIONPATH)


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', '') == '':
        __version__ = _update_version_file()
    else:  # pragma: no cover
        _remove_version_file()
else:  # pragma: no cover
    # dvc was installed with pip or something. Hopefully we have our
    # auto-generated version.py to help us provide a true version
    from dvc.version import version
    __version__ = version

VERSION = __version__


# Ignore numpy's runtime warnings: https://github.com/numpy/numpy/pull/432.
# We don't directly import numpy, but our dependency networkx does, causing
# these warnings in some environments. Luckily these warnings are benign and
# we can simply ignore them so that they don't show up when you are using dvc.
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")

[((14, 11, 14, 39), 'os.path.dirname', 'os.path.dirname', ({(14, 27, 14, 38): 'PACKAGEPATH'}, {}), '(PACKAGEPATH)', False, 'import os\n'), ((15, 14, 15, 53), 'os.path.join', 'os.path.join', ({(15, 27, 15, 38): 'PACKAGEPATH', (15, 40, 15, 52): '"""version.py"""'}, {}), "(PACKAGEPATH, 'version.py')", False, 'import os\n'), ((69, 0, 69, 69), 'warnings.filterwarnings', 'warnings.filterwarnings', (), '', False, 'import warnings\n'), ((70, 0, 70, 69), 'warnings.filterwarnings', 'warnings.filterwarnings', (), '', False, 'import warnings\n'), ((13, 30, 13, 55), 'os.path.dirname', 'os.path.dirname', ({(13, 46, 13, 54): '__file__'}, {}), '(__file__)', False, 'import os\n'), ((44, 7, 44, 34), 'os.path.exists', 'os.path.exists', ({(44, 22, 44, 33): 'VERSIONPATH'}, {}), '(VERSIONPATH)', False, 'import os\n'), ((48, 18, 48, 52), 'os.path.join', 'os.path.join', ({(48, 31, 48, 39): 'HOMEPATH', (48, 41, 48, 51): '"""setup.py"""'}, {}), "(HOMEPATH, 'setup.py')", False, 'import os\n'), ((24, 15, 24, 29), 'git.Repo', 'Repo', ({(24, 20, 24, 28): 'HOMEPATH'}, {}), '(HOMEPATH)', False, 'from git import Repo\n'), ((45, 8, 45, 30), 'os.unlink', 'os.unlink', ({(45, 18, 45, 29): 'VERSIONPATH'}, {}), '(VERSIONPATH)', False, 'import os\n'), ((52, 11, 52, 38), 'os.getenv', 'os.getenv', ({(52, 21, 52, 33): '"""TRAVIS_TAG"""', (52, 35, 52, 37): '""""""'}, {}), "('TRAVIS_TAG', '')", False, 'import os\n'), ((51, 7, 51, 41), 'os.getenv', 'os.getenv', ({(51, 17, 51, 36): '"""APPVEYOR_REPO_TAG"""', (51, 38, 51, 40): '""""""'}, {}), "('APPVEYOR_REPO_TAG', '')", False, 'import os\n')]