"""
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")

[((225, 253), 'os.path.dirname', 'os.path.dirname', (['PACKAGEPATH'], {}), '(PACKAGEPATH)\n', (240, 253), False, 'import os\n'), ((268, 307), 'os.path.join', 'os.path.join', (['PACKAGEPATH', '"""version.py"""'], {}), "(PACKAGEPATH, 'version.py')\n", (280, 307), False, 'import os\n'), ((2141, 2210), 'warnings.filterwarnings', 'warnings.filterwarnings', (['"""ignore"""'], {'message': '"""numpy.dtype size changed"""'}), "('ignore', message='numpy.dtype size changed')\n", (2164, 2210), False, 'import warnings\n'), ((2211, 2280), 'warnings.filterwarnings', 'warnings.filterwarnings', (['"""ignore"""'], {'message': '"""numpy.ufunc size changed"""'}), "('ignore', message='numpy.ufunc size changed')\n", (2234, 2280), False, 'import warnings\n'), ((187, 212), 'os.path.dirname', 'os.path.dirname', (['__file__'], {}), '(__file__)\n', (202, 212), False, 'import os\n'), ((1150, 1177), 'os.path.exists', 'os.path.exists', (['VERSIONPATH'], {}), '(VERSIONPATH)\n', (1164, 1177), False, 'import os\n'), ((1230, 1264), 'os.path.join', 'os.path.join', (['HOMEPATH', '"""setup.py"""'], {}), "(HOMEPATH, 'setup.py')\n", (1242, 1264), False, 'import os\n'), ((481, 495), 'git.Repo', 'Repo', (['HOMEPATH'], {}), '(HOMEPATH)\n', (485, 495), False, 'from git import Repo\n'), ((1187, 1209), 'os.unlink', 'os.unlink', (['VERSIONPATH'], {}), '(VERSIONPATH)\n', (1196, 1209), False, 'import os\n'), ((1444, 1471), 'os.getenv', 'os.getenv', (['"""TRAVIS_TAG"""', '""""""'], {}), "('TRAVIS_TAG', '')\n", (1453, 1471), False, 'import os\n'), ((1378, 1412), 'os.getenv', 'os.getenv', (['"""APPVEYOR_REPO_TAG"""', '""""""'], {}), "('APPVEYOR_REPO_TAG', '')\n", (1387, 1412), False, 'import os\n')]