Parse version into a comparable Version tuple.
343747
def parse_version(ver, pre=False):
    """"""

    m = RE_VER.match(ver)

    # Handle major, minor, micro
    major = int(m.group('major'))
    minor = int(m.group('minor')) if m.group('minor') else 0
    micro = int(m.group('micro')) if m.group('micro') else 0

    # Handle pre releases
    if m.group('type'):
        release = PRE_REL_MAP[m.group('type')]
        pre = int(m.group('pre'))
    else:
        release = "final"
        pre = 0

    # Handle development releases
    dev = m.group('dev') if m.group('dev') else 0
    if m.group('dev'):
        dev = int(m.group('dev'))
        release = '.dev-' + release if pre else '.dev'
    else:
        dev = 0

    # Handle post
    post = int(m.group('post')) if m.group('post') else 0

    return Version(major, minor, micro, release, pre, post, dev)
1106006
def get_version(version):
    """"""
    if len(version) > 2 and version[2] is not None:
        if isinstance(version[2], int):
            str_version = "%s.%s.%s" % version[:3]
        else:
            str_version = "%s.%s_%s" % version[:3]
    else:
        str_version = "%s.%s" % version[:2]

    return str_version
691320
def query_versions(self, version=None):
        """"""
        if version not in RELEASE_AND_CANDIDATE_LATEST_VERSIONS:
            return [version]

        url = urljoin(self.base_url, 'releases/')
        parser = self._create_directory_parser(url)
        if version:
            versions = parser.filter(RELEASE_AND_CANDIDATE_LATEST_VERSIONS[version])
            from distutils.version import LooseVersion
            versions.sort(key=LooseVersion)
            return [versions[-1]]
        else:
            return parser.entries
548538
def versions(self, rev=None, index=None):
        """"""
        raise NotImplementedError
        _revisions = [line.split()[0] for line in self.log.split('\n') if line]
        _versions = [Version(self.obj.repo.commit(r)) for r in _revisions if rev is None or r.startswith(rev)]
        if index is not None and len(_versions) > index:
            _versions = _versions[index]
        return _versions
951567
def unpack_version(version):
    """"""
    minor_version = version % VERSION_MULTIPLIER
    major_version = (version - minor_version) / VERSION_MULTIPLIER
    return (major_version, minor_version)
64316
def parse_version(output):
    
    for x in output.splitlines():
        match = VERSION_PATTERN.match(x)
        if match:
            return match.group('version').strip()
    return None
936589
def node_version():
    """"""
    version = check_output(('node', '--version'))
    return tuple(int(x) for x in version.strip()[1:].split(b'.'))
628244
public static Version parseMavenVersion(String version) {
		if (Strings.isNullOrEmpty(version)) {
			return new Version(0, 0, 0);
		}

		// Detect the snapshot
		final boolean isSnapshot;
		final String coreVersion;
		Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(version);
		if (matcher.matches()) {
			coreVersion = matcher.group(1);
			isSnapshot = true;
		} else {
			matcher = SNAPSHOT_VERSION_PATTERN.matcher(version);
			if (matcher.matches()) {
				coreVersion = matcher.group(1);
				isSnapshot = true;
			} else {
				coreVersion = version;
				isSnapshot = false;
			}
		}

		// Parse the numbers
		final String[] parts = coreVersion.split("[.]"); //$NON-NLS-1$
		final int[] numbers = new int[] {0, 0, 0};
		int i = 0;
		while (i < numbers.length && i < parts.length) {
			try {
				numbers[i] = Integer.parseInt(parts[i]);
				++i;
			} catch (Exception exception) {
				// Force the exit of the loop since a number cannot be find.
				i = numbers.length;
			}
		}
		// Reply
		if (isSnapshot) {
			return new Version(numbers[0], numbers[1], numbers[2], SNAPSHOT_QUALIFIER);
		}
		return new Version(numbers[0], numbers[1], numbers[2]);
	}
1176683
def msvs_parse_version(s):
    
    num, suite = version_re.match(s).groups()
    return float(num), suite
127536
def get_version(*args):
    """"""
    contents = get_contents(*args)
    metadata = dict(re.findall('__([a-z]+)__ = [\'"]([^\'"]+)', contents))
    return metadata['version']
817603
def compare_version(version1, version2):
    
    def normalize(v):
        return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]
    return (normalize(version1) > normalize(version2))-(normalize(version1) < normalize(version2))
1373681
def parse_version(v):
    
    parts = v.split(".")
    # Pad the list to make sure there is three elements so that we get major, minor, point
    # comparisons that default to "0" if not given.  I.e. "1.2" --> (1, 2, 0)
    parts = (parts + 3 * ['0'])[:3]
    return tuple(int(x) for x in parts)
218340
def parse(cls, version_string):
        
        match = RE.match(version_string)
        if match:
            major_str, minor_str, patch_str, postrelease_alpha, \
                postrelease_digit, prerelease_str, build_metadata = \
                match.groups()

            if postrelease_digit:
                postrelease = int(postrelease_digit)
            else:
                postrelease = postrelease_alpha

            # A well-defined version cannot both have a pre- and a
            # post-release identifier.
            if postrelease and prerelease_str:
                raise InvalidVersionExpression(version_string)

            major = int(major_str)

            if minor_str:
                minor = int(minor_str)
            else:
                minor = 0

            if patch_str:
                patch = int(patch_str)
            else:
                patch = 0

            if prerelease_str:
                try:
                    prerelease = int(prerelease_str)
                except ValueError:
                    prerelease = prerelease_str
            else:
                prerelease = None

            return cls(major, minor, patch,
                       postrelease, prerelease, build_metadata)

        else:
            raise InvalidVersionExpression(version_string)
217722
def getVersion(data):
    
    data = data.splitlines()
    return next((
        v
        for v, u in zip(data, data[1:])  # v = version, u = underline
        if len(v) == len(u) and allSame(u) and hasDigit(v) and "." in v
    ))
613890
def parse_version(version):
    """"""
    global parse_version
    try:
        if "__PEX_UNVENDORED__" in __import__("os").environ:
          from pkg_resources import parse_version  # vendor:skip
        else:
          from pex.third_party.pkg_resources import parse_version

    except ImportError:
        from distutils.version import LooseVersion as parse_version
    return parse_version(version)
205179
def parse_version(cls, version_str):
        
        match = cls.VERSION_RE.match(version_str)
        if match:
            major = int(match.group('major'))
            minor = int(match.group('minor'))
            flags = set(match.group('flags') or '')
        else:
            major, minor, flags = None, None, set()
        return cls(major, minor, flags)
1274432
def package_version(filename, varname):
    """"""
    _locals = {}
    with open(filename) as fp:
        exec(fp.read(), None, _locals)
    return _locals[varname]