def find_version(include_dev_version=True, root='<STR_LIT>',<EOL>version_file='<STR_LIT>', version_module_paths=(),<EOL>git_args=None, vcs_args=None, decrement_dev_version=None,<EOL>strip_prefix='<STR_LIT:v>',<EOL>Popen=subprocess.Popen, open=open):
substitutions = {'<STR_LIT>': os.getcwd()}<EOL>substitutions['<STR_LIT:root>'] = root % substitutions<EOL>def substitute(val):<EOL><INDENT>return _fix_path(val % substitutions)<EOL><DEDENT>if version_file is not None:<EOL><INDENT>version_file = substitute(version_file)<EOL><DEDENT>if git_args is not None:<EOL><INDENT>warnings.warn(<EOL>'<STR_LIT>',<EOL>DeprecationWarning)<EOL>vcs_args = git_args<EOL><DEDENT>if vcs_args is None:<EOL><INDENT>for path, args in _vcs_args_by_path:<EOL><INDENT>if os.path.exists(substitute(path)):<EOL><INDENT>vcs_args = args<EOL>break<EOL><DEDENT><DEDENT><DEDENT>raw_version = None<EOL>vcs_output = []<EOL>if vcs_args is not None:<EOL><INDENT>vcs_args = [substitute(arg) for arg in vcs_args]<EOL>try:<EOL><INDENT>proc = Popen(vcs_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)<EOL><DEDENT>except OSError:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>stdout, stderr = proc.communicate()<EOL>raw_version = stdout.strip().decode()<EOL>vcs_output = stderr.decode().splitlines()<EOL>version_source = '<STR_LIT>'<EOL><DEDENT>failure = '<STR_LIT>' % (vcs_args,)<EOL><DEDENT>else:<EOL><INDENT>failure = '<STR_LIT>' % substitutions<EOL><DEDENT>def show_vcs_output():<EOL><INDENT>if not vcs_output:<EOL><INDENT>return<EOL><DEDENT>print('<STR_LIT>')<EOL>for line in vcs_output:<EOL><INDENT>print(line)<EOL><DEDENT><DEDENT>if not raw_version:<EOL><INDENT>if version_file is None:<EOL><INDENT>print('<STR_LIT>' % (failure,))<EOL>show_vcs_output()<EOL>raise SystemExit(<NUM_LIT:2>)<EOL><DEDENT>elif not os.path.exists(version_file):<EOL><INDENT>print("<STR_LIT>" % (failure, version_file))<EOL>print("<STR_LIT>")<EOL>show_vcs_output()<EOL>raise SystemExit(<NUM_LIT:2>)<EOL><DEDENT>with open(version_file, '<STR_LIT:rb>') as infile:<EOL><INDENT>raw_version = infile.read().decode()<EOL><DEDENT>version_source = repr(version_file)<EOL><DEDENT>try:<EOL><INDENT>tag_version, commits, sha = raw_version.rsplit('<STR_LIT:->', <NUM_LIT:2>)<EOL><DEDENT>except ValueError:<EOL><INDENT>print("<STR_LIT>" % (<EOL>raw_version, version_source))<EOL>show_vcs_output()<EOL>raise SystemExit(<NUM_LIT:2>)<EOL><DEDENT>if tag_version.startswith(strip_prefix):<EOL><INDENT>tag_version = tag_version[len(strip_prefix):]<EOL><DEDENT>if version_file is not None:<EOL><INDENT>with open(version_file, '<STR_LIT:w>') as outfile:<EOL><INDENT>outfile.write(raw_version)<EOL><DEDENT><DEDENT>if sha.startswith('<STR_LIT>') and decrement_dev_version is None:<EOL><INDENT>decrement_dev_version = True<EOL><DEDENT>if decrement_dev_version:<EOL><INDENT>commits = str(int(commits) - <NUM_LIT:1>)<EOL><DEDENT>if commits == '<STR_LIT:0>' or not include_dev_version:<EOL><INDENT>version = tag_version<EOL><DEDENT>else:<EOL><INDENT>version = '<STR_LIT>' % (tag_version, commits)<EOL><DEDENT>for path in version_module_paths:<EOL><INDENT>with open(path, '<STR_LIT:w>') as outfile:<EOL><INDENT>outfile.write(
Find an appropriate version number from version control.

    It's much more convenient to be able to use your version control system's
    tagging mechanism to derive a version number than to have to duplicate that
    information all over the place.

    The default behavior is to write out a ``version.txt`` file which contains
    the VCS output, for systems where the appropriate VCS is not installed or
    there is no VCS metadata directory present. ``version.txt`` can (and
    probably should!) be packaged in release tarballs by way of the
    ``MANIFEST.in`` file.

    :param include_dev_version: By default, if there are any commits after the
        most recent tag (as reported by the VCS), that number will be included
        in the version number as a ``.post`` suffix. For example, if the most
        recent tag is ``1.0`` and there have been three commits after that tag,
        the version number will be ``1.0.post3``. This behavior can be disabled
        by setting this parameter to ``False``.

    :param root: The directory of the repository root. The default value is the
        current working directory, since when running ``setup.py``, this is
        often (but not always) the same as the current working directory.
        Standard substitutions are performed on this value.

    :param version_file: The name of the file where version information will be
        saved. Reading and writing version files can be disabled altogether by
        setting this parameter to ``None``. Standard substitutions are
        performed on this value.

    :param version_module_paths: A list of python modules which will be
        automatically generated containing ``__version__`` and ``__sha__``
        attributes. For example, with ``package/_version.py`` as a version
        module path, ``package/__init__.py`` could do ``from package._version
        import __version__, __sha__``.

    :param git_args: **Deprecated.** Please use *vcs_args* instead.

    :param vcs_args: The command to run to get a version. By default, this is
        automatically guessed from directories present in the repository root.
        Specify this as a list of string arguments including the program to
        run, e.g. ``['git', 'describe']``. Standard substitutions are performed
        on each value in the provided list.

    :param decrement_dev_version: If ``True``, subtract one from the number of
        commits after the most recent tag. This is primarily for hg, as hg
        requires a commit to make a tag. If the VCS used is hg (i.e. the
        revision starts with ``'hg'``) and *decrement_dev_version* is not
        specified as ``False``, *decrement_dev_version* will be set to
        ``True``.

    :param strip_prefix: A string which will be stripped from the start of
        version number tags. By default this is ``'v'``, but could be
        ``'debian/'`` for compatibility with ``git-dch``.

    :param Popen: Defaults to ``subprocess.Popen``. This is for testing.

    :param open: Defaults to ``open``. This is for testing.

    *root*, *version_file*, and *git_args* each support some substitutions:

    ``%(root)s``
      The value provided for *root*. This is not available for the *root*
      parameter itself.

    ``%(pwd)s``
      The current working directory.

    ``/`` will automatically be translated into the correct path separator for
    the current platform, such as ``:`` or ``\``.

    ``vcversioner`` will perform automatic VCS detection with the following
    directories, in order, and run the specified commands.

       ``%(root)s/.git``

          ``git --git-dir %(root)s/.git describe --tags --long``. ``--git-dir``
          is used to prevent contamination from git repositories which aren't
          the git repository of your project.

       ``%(root)s/.hg``

          ``hg log -R %(root)s -r . --template
          '{latesttag}-{latesttagdistance}-hg{node|short}'``. ``-R`` is
          similarly used to prevent contamination.