This file is indexed.

/usr/lib/python2.7/dist-packages/setuptools_scm/__init__.py is in python-setuptools-scm 1.15.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""
:copyright: 2010-2015 by Ronny Pfannschmidt
:license: MIT
"""
import os
import sys
import warnings

from .utils import trace
from .version import format_version, meta, ScmVersion
from .discover import find_matching_entrypoint

PRETEND_KEY = 'SETUPTOOLS_SCM_PRETEND_VERSION'


TEMPLATES = {
    '.py': """\
# coding: utf-8
# file generated by setuptools_scm
# don't change, don't track in version control
version = {version!r}
""",
    '.txt': '{version}',
}

PY3 = sys.version_info > (3,)
string_types = (str,) if PY3 else (str, unicode)  # noqa


def version_from_scm(root):
    return _version_from_entrypoint(root, 'setuptools_scm.parse_scm')


def _version_from_entrypoint(root, entrypoint):
    ep = find_matching_entrypoint(root, entrypoint)
    if ep:
        return ep.load()(root)


def dump_version(root, version, write_to, template=None):
    assert isinstance(version, string_types)
    if not write_to:
        return
    target = os.path.normpath(os.path.join(root, write_to))
    ext = os.path.splitext(target)[1]
    template = template or TEMPLATES.get(ext)

    if template is not None:
        dump = template.format(version=version)
    else:
        raise ValueError((
            "bad file format: '%s' (of %s) \n"
            "only *.txt and *.py are supported") % (
            os.path.splitext(target)[1],
            target
        ))
    with open(target, 'w') as fp:
        fp.write(dump)


def _do_parse(root, parse):
    pretended = os.environ.get(PRETEND_KEY)
    if pretended:
        # we use meta here since the pretended version
        # must adhere to the pep to begin with
        return meta(pretended)

    if parse:
        parse_result = parse(root)
        if isinstance(parse_result, string_types):
            warnings.warn(
                "version parse result was a string\n"
                "please return a parsed version",
                category=DeprecationWarning)
            # we use ScmVersion here in order to keep legacy code working
            # for 2.0 we should use meta
            parse_result = ScmVersion(parse_result)
        version = parse_result or _version_from_entrypoint(
            root, 'setuptools_scm.parse_scm_fallback')
    else:
        # include fallbacks after dropping them from the main entrypoint
        version = version_from_scm(root)

    if version:
        return version

    raise LookupError(
        "setuptools-scm was unable to detect version for %r.\n\n"
        "Make sure you're either building from a fully intact git repository "
        "or PyPI tarballs. Most other sources (such as GitHub's tarballs, a "
        "git checkout without the .git folder) don't contain the necessary "
        "metadata and will not work.\n\n"
        "For example, if you're using pip, instead of "
        "https://github.com/user/proj/archive/master.zip "
        "use git+https://github.com/user/proj.git#egg=proj" % root)


def get_version(root='.',
                version_scheme='guess-next-dev',
                local_scheme='node-and-date',
                write_to=None,
                write_to_template=None,
                relative_to=None,
                parse=None,
                ):
    """
    If supplied, relative_to should be a file from which root may
    be resolved. Typically called by a script or module that is not
    in the root of the repository to direct setuptools_scm to the
    root of the repository by supplying ``__file__``.
    """
    if relative_to:
        root = os.path.join(os.path.dirname(relative_to), root)
    root = os.path.abspath(root)
    trace('root', repr(root))

    parsed_version = _do_parse(root, parse)

    if parsed_version:
        version_string = format_version(
            parsed_version,
            version_scheme=version_scheme,
            local_scheme=local_scheme)
        dump_version(
            root=root,
            version=version_string,
            write_to=write_to,
            template=write_to_template)

        return version_string