def tag_to_version(tag, config=None): """ take a tag that might be prefixed with a keyword and return only the version part :param config: optional configuration object """ trace("tag", tag) if not config: config = Configuration() tagdict = _parse_version_tag(tag, config) if not isinstance(tagdict, dict) or not tagdict.get("version", None): warnings.warn("tag %r no version found" % (tag,)) return None version = tagdict["version"] trace("version pre parse", version) if tagdict.get("suffix", ""): warnings.warn( "tag %r will be stripped of its suffix '%s'" % (tag, tagdict["suffix"]) ) if VERSION_CLASS is not None: version = pkg_parse_version(version) trace("version", repr(version)) return version
def tag_to_version(tag, config=None): """ take a tag that might be prefixed with a keyword and return only the version part :param config: optional configuration object """ trace("tag", tag) if not config: config = Configuration() tagdict = _parse_version_tag(tag, config) if not isinstance(tagdict, dict) or not tagdict.get("version", None): warnings.warn("tag {!r} no version found".format(tag)) return None version = tagdict["version"] trace("version pre parse", version) if tagdict.get("suffix", ""): warnings.warn( "tag {!r} will be stripped of its suffix '{}'".format( tag, tagdict["suffix"] ) ) if VERSION_CLASS is not None: version = pkg_parse_version(version) trace("version", repr(version)) return version
def parse_version(version_string): """Parse a version string. Will attempt to use `packaging` module to parse versions according to PEP 440. If the `packaging` module is not available (usually vendored via `pkg_resources`) will fall back to a more naive version parsing. """ if pkg_parse_version is not None: return pkg_parse_version(version_string) return parse_version_fallback(version_string)
def tag_to_version(tag): """ take a tag that might be prefixed with a keyword and return only the version part """ trace("tag", tag) if "+" in tag: warnings.warn("tag %r will be stripped of the local component" % tag) tag = tag.split("+")[0] # lstrip the v because of py2/py3 differences in setuptools # also required for old versions of setuptools prefix_match = TAG_PREFIX.match(tag) if prefix_match is not None: version = prefix_match.group(1) else: version = tag trace("version pre parse", version) if VERSION_CLASS is None: return version version = pkg_parse_version(version) trace("version", repr(version)) if isinstance(version, VERSION_CLASS): return version
def _get_version_class(): modern_version = pkg_parse_version("1.0") if isinstance(modern_version, tuple): return None else: return type(modern_version)
def _get_version_class(): modern_version = pkg_parse_version("1.0") if isinstance(modern_version, tuple): return None else: return type(modern_version)