Extract the version from the package.
191181
def extract_version():
    """"""
    with open('pdftools/__init__.py', 'r') as f:
        content = f.read()

    version_match = _version_re.search(content)
    version = str(ast.literal_eval(version_match.group(1)))
    return version
478970
def find_version():
    """"""
    version_file = read_file('__init__.py')
    version_match = re.search(r'^__version__ = ["\']([^"\']*)["\']',
                              version_file, re.M)
    if version_match:
        return version_match.group(1)
    raise RuntimeError('Unable to find version string.')
738489
def get_upstream_version(package):
    
    import apt_pkg
    cache = apt_cache()
    try:
        pkg = cache[package]
    except Exception:
        # the package is unknown to the current apt cache.
        return None

    if not pkg.current_ver:
        # package is known, but no version is currently installed.
        return None

    return apt_pkg.upstream_version(pkg.current_ver.ver_str)
841765
def get_version(version):
    ""
    # Now build the two parts of the version number:
    # main = X.Y[.Z]
    # sub = .devN - for pre-alpha releases
    #     | {a|b|c}N - for alpha, beta and rc releases

    main = get_main_version(version)

    sub = ''
    if version[3] != 'final':
        mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
        sub = mapping[version[3]] + str(version[4])

    return main + sub
1025698
def get_version_from_unpacked_sdist(path):
    """"""
    # This is a condensed version of the relevant code in pkginfo 1.4.1
    try:
        with open(os.path.join(path, 'PKG-INFO')) as f:
            data = f.read()
    except IOError:
        # Could not load path as an unpacked sdist as it had no PKG-INFO file
        return
    fp = StringIO(_must_decode(data))
    msg = Parser().parse(fp)
    value = msg.get('Version')
    if value != 'UNKNOWN':
        return value
112453
def get_version(project_dir=os.curdir):
    
    if 'LAGO_VERSION' in os.environ and os.environ['LAGO_VERSION']:
        return os.environ['LAGO_VERSION']

    version = None
    pkg_info_file = os.path.join(project_dir, 'PKG-INFO')
    version_manager = os.path.join(project_dir, 'scripts/version_manager.py')
    if os.path.exists(pkg_info_file):
        with open(pkg_info_file) as info_fd:
            for line in info_fd.readlines():
                if line.startswith('Version: '):
                    version = line.split(' ', 1)[-1]

    elif os.path.exists(version_manager):
        version = check_output([version_manager, project_dir,
                                'version']).strip()

    if version is None:
        raise RuntimeError('Failed to get package version')

    # py3 compatibility step
    if not isinstance(version, str) and isinstance(version, bytes):
        version = version.decode()

    return version
1212626
def package(self):
        """"""
        return u'{0}-{1}-{2}'.format(self.name,
                                     self.version,
                                     self.release)
1335250
def get():
    """"""
    pkgnames = find_packages()

    if len(pkgnames) == 0:
        raise ValueError("Can't find any packages")

    pkgname = pkgnames[0]

    content = open(join(pkgname, '__init__.py')).read()
    c = re.compile(r"__version__ *= *('[^']+'|\"[^\"]+\")")
    m = c.search(content)

    if m is None:
        raise ValueError("Can't find __version__ = ... in __init__.py")

    return m.groups()[0][1: -1]
420531
def get_version(self, cached=True):
        """"""
        if hasattr(self.__class__, '_version') and cached:
            version = self.__class__._version
        else:
            repo = self.get_repo()
            if repo is not None:
                head = repo.head
                version = head.commit.hexsha
                if repo.is_dirty():
                    version += "*"
            else:
                version = None
        self.__class__._version = version
        return version
1341584
def get_version(package, url_pattern=URL_PATTERN):
    """"""
    req = requests.get(url_pattern.format(package=package))
    version = parse('0')
    if req.status_code == requests.codes.ok:
        # j = json.loads(req.text.encode(req.encoding))
        j = req.json()
        releases = j.get('releases', [])
        for release in releases:
            ver = parse(release)
            if not ver.is_prerelease:
                version = max(version, ver)
    return version
585864
def version(*args, **attrs):
    """"""
    if hasattr(sys, "_getframe"):
        package = attrs.pop("package", sys._getframe(1).f_globals.get("__package__"))
        if package:
            attrs.setdefault("version", get_version(package))
    return click.version_option(*args, **attrs)
467441
def get_version(package):
    
    init_py = readfile(os.path.join(package, '__init__.py'))
    return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)
461423
def getversion(package):
    
    distribution = get_distribution(package)
    if distribution is None:
        raise RuntimeError("Can't find distribution {0}".format(package))
    repo_type = get_repo_type(distribution.location)
    if repo_type is None:
        return distribution.version

    return repo_type.get_version(distribution.location)
785277
def get_package_version():
    """"""
    base = os.path.abspath(os.path.dirname(__file__))
    with open(os.path.join(base, 'policy', '__init__.py'),
              mode='rt',
              encoding='utf-8') as initf:
        for line in initf:
            m = version.match(line.strip())
            if not m:
                continue
            return m.groups()[0]
968857
def get_package_version(self):
        
        output = subprocess.check_output([
            '{}'.format(self.python),
            'setup.py',
            '--version',
        ]).decode()
        return output.rstrip()
598852
def get_version():
    """"""
    with io.open('grammar_check/__init__.py', encoding='utf-8') as input_file:
        for line in input_file:
            if line.startswith('__version__'):
                return ast.parse(line).body[0].value.s
1206815
def parse_package_for_version(name):
    
    from utool import util_regex
    init_fpath = join(name, '__init__.py')
    version_errmsg = textwrap.dedent(
        '''
        You must include a __version__ variable
        in %s\'s __init__.py file.
        Try something like:
        __version__ = '1.0.0.dev1' ''' % (name,))
    if not exists(init_fpath):
        raise AssertionError(version_errmsg)
    val_regex = util_regex.named_field('version', '[0-9a-zA-Z.]+')
    regexstr = '__version__ *= *[\'"]' + val_regex
    def parse_version(line):
        # Helper
        line = line.replace(' ', '').replace('\t', '')
        match_dict = util_regex.regex_parse(regexstr, line)
        if match_dict is not None:
            return match_dict['version']
    # Find the version  in the text of the source
    #version = 'UNKNOWN_VERSION'
    with open(init_fpath, 'r') as file_:
        for line in file_.readlines():
            if line.startswith('__version__'):
                version = parse_version(line)
                if version is not None:
                    return version
    raise AssertionError(version_errmsg)