def split_archive_name(archive_name, probable_name=None): """Split an archive name into two parts: name and version. Return the tuple (name, version) """ # Try to determine wich part is the name and wich is the version using the # "-" separator. Take the larger part to be the version number then reduce # if this not works. def eager_split(str, maxsplit=2): # split using the "-" separator splits = str.rsplit("-", maxsplit) name = splits[0] version = "-".join(splits[1:]) if version.startswith("-"): version = version[1:] if suggest_normalized_version(version) is None and maxsplit >= 0: # we dont get a good version number: recurse ! return eager_split(str, maxsplit - 1) else: return name, version if probable_name is not None: probable_name = probable_name.lower() name = None if probable_name is not None and probable_name in archive_name: # we get the name from probable_name, if given. name = probable_name version = archive_name.lstrip(name) else: name, version = eager_split(archive_name) version = suggest_normalized_version(version) if version is not None and name != "": return name.lower(), version else: raise CantParseArchiveName(archive_name)
def distinfo_dirname(name, version): """ The *name* and *version* parameters are converted into their filename-escaped form, i.e. any ``'-'`` characters are replaced with ``'_'`` other than the one in ``'dist-info'`` and the one separating the name from the version number. :parameter name: is converted to a standard distribution name by replacing any runs of non- alphanumeric characters with a single ``'-'``. :type name: string :parameter version: is converted to a standard version string. Spaces become dots, and all other non-alphanumeric characters (except dots) become dashes, with runs of multiple dashes condensed to a single dash. :type version: string :returns: directory name :rtype: string""" file_extension = ".dist-info" name = name.replace("-", "_") normalized_version = suggest_normalized_version(version) # Because this is a lookup procedure, something will be returned even if # it is a version that cannot be normalized if normalized_version is None: # Unable to achieve normality? normalized_version = version return "-".join([name, normalized_version]) + file_extension
def set_version(self, version): try: self._version = NormalizedVersion(version) except IrrationalVersionError: suggestion = suggest_normalized_version(version) if suggestion: self.version = suggestion else: raise IrrationalVersionError(version)
def eager_split(str, maxsplit=2): # split using the "-" separator splits = str.rsplit("-", maxsplit) name = splits[0] version = "-".join(splits[1:]) if version.startswith("-"): version = version[1:] if suggest_normalized_version(version) is None and maxsplit >= 0: # we dont get a good version number: recurse ! return eager_split(str, maxsplit - 1) else: return name, version
def __init__(self, version): self.unnormalized_version = version NormalizedVersion.__init__( self, suggest_normalized_version(version))
def __init__(self, version): self.unnormalized_version = version NormalizedVersion.__init__(self, suggest_normalized_version(version))
def normalized_version(self): version = suggest_normalized_version(self['Version']) if version is None: raise InvalidVersion("cannot determine the normalized version " "for: %s" % self['Version']) return NormalizedVersion(version)