How to use the packaging.version.InvalidVersion function in packaging

To help you get started, we’ve selected a few packaging examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pypa / packaging / tests / test_version.py View on Github external
def test_invalid_versions(self, version):
        with pytest.raises(InvalidVersion):
            Version(version)
github dvershinin / lastversion / lastversion / ProjectHolder.py View on Github external
log.info("Did not find anything that looks like a version in the tag")
                # as a last resort, let's try to convert underscores to dots, while stripping out
                # any "alphanumeric_". many hg repos do this, e.g. PROJECT_1_2_3
                parts = version.split('_')
                if len(parts) >= 2 and parts[0].isalpha():
                    # gets list except first item, joins by dot
                    version = '.'.join(parts[1:])
                    try:
                        v = Version(version)
                        if not v.is_prerelease or pre_ok:
                            log.info("Parsed as Version OK")
                            log.info("String representation of version is {}.".format(v))
                            res = v
                        else:
                            log.info("Parsed as unwanted pre-release version: {}.".format(v))
                    except InvalidVersion:
                        log.info('Still not a valid version after applying underscores fix')
        # apply --major filter
        if res and major and not self.matches_major_filter(version, major):
            log.info('{} is not under the desired major {}'.format(
                version, major))
            res = False
        return res
github mozilla / iris_firefox / iris / api / core / util / version_parser.py View on Github external
if input_str is None or input_str == '':
        return

    if '-' in input_str:
        versions_list = input_str.split('-')
        if len(versions_list) > 2:
            return
        else:
            try:

                v_list = [Version(versions_list[0]), Version(versions_list[1])]
                result[version_key] = v_list
                result[operator_key] = '-'
                return result

            except InvalidVersion:
                return
    try:

        result[version_key] = Version(input_str)
        result[operator_key] = '='
        return result

    except InvalidVersion:
        op_list = []
        for op in valid_operators:
            if find_str(input_str, op) == 0:
                op_list.append(op)

        op = max(op_list)
        try:
            result[version_key] = Version(input_str.replace(op, '', 1))
github mozilla / iris_firefox / iris / api / core / util / version_parser.py View on Github external
try:

                v_list = [Version(versions_list[0]), Version(versions_list[1])]
                result[version_key] = v_list
                result[operator_key] = '-'
                return result

            except InvalidVersion:
                return
    try:

        result[version_key] = Version(input_str)
        result[operator_key] = '='
        return result

    except InvalidVersion:
        op_list = []
        for op in valid_operators:
            if find_str(input_str, op) == 0:
                op_list.append(op)

        op = max(op_list)
        try:
            result[version_key] = Version(input_str.replace(op, '', 1))
            result[operator_key] = op

        except InvalidVersion:
            return

    return result
github Capevace / halbert / env / halbert_python_env / lib / python2.7 / site-packages / pkg_resources / __init__.py View on Github external
def safe_version(version):
    """
    Convert an arbitrary string to a standard version string
    """
    try:
        # normalize the version
        return str(packaging.version.Version(version))
    except packaging.version.InvalidVersion:
        version = version.replace(' ', '.')
        return re.sub('[^A-Za-z0-9.]+', '-', version)
github pallets / pallets-sphinx-themes / src / pallets_sphinx_themes / versions.py View on Github external
def _is_version(value, placeholder="x"):
    if value.endswith(".{}".format(placeholder)):
        value = value[: -(len(placeholder) + 1)]

    try:
        pv.Version(value)
        return True
    except pv.InvalidVersion:
        return False
github alexbecker / dotlock / src / dotlock / dist_info / json_api.py View on Github external
async def get_candidate_infos(
        package_types: List[PackageType],
        source: str,
        session: ClientSession,
        name: str,
) -> Optional[List[CandidateInfo]]:
    base_metadata = await get_json_metadata(source, session, name, version=None)
    if base_metadata is None:
        return None

    candidate_infos = []
    for version_str, distributions in base_metadata['releases'].items():
        try:
            version = Version(version_str)
        except InvalidVersion:
            logger.info('Invalid version for %r: %s', name, version_str)
            continue  # Skip candidates without a valid version.

        for distribution in distributions:
            package_type = PackageType[distribution['packagetype']]

            if package_type.name.startswith('bdist'):
                filename = distribution['filename']
                if not is_supported(filename):
                    logger.debug('Skipping unsupported bdist %s', filename)
                    continue

            if package_type not in package_types:
                logger.debug('Skipping package type %s for %s', package_type.name, name)
                continue
github dephell / dephell / dephell / pythons.py View on Github external
raise FileNotFoundError(msg + str(prefer))
        if path.exists():
            python = self.get_by_path(path)
            if python is not None:
                return python

        # looks like constraint
        if set(prefer) & {'<', '>', '='}:
            python = self.get_by_spec(RangeSpecifier(prefer))
            if python is not None:
                return python

        # ok, let's try it like a version
        try:
            version = Version(prefer)
        except InvalidVersion:
            pass
        else:
            python = self.get_by_version(version)
            if python is not None:
                return python

        # ok, let's try it like a name
        python = self.get_by_name(prefer)
        if python is not None:
            return python

        # no success
        raise FileNotFoundError('cannot find interpretor: ' + str(prefer))
github dvershinin / lastversion / lastversion / lastversion.py View on Github external
"""
    Argument parser helper for --newer-than (-gt) option
    :param value:
    :type value:
    :return:
    :rtype:
    """
    try:
        # TODO use sanitize_version so that we can just pass tags as values
        # help devel releases to be correctly identified
        # https://www.python.org/dev/peps/pep-0440/#developmental-releases
        value = re.sub('-devel$', '.dev0', value, 1)
        # help post (patch) releases to be correctly identified (e.g. Magento 2.3.4-p2)
        value = re.sub('-p(\\d+)$', '.post\\1', value, 1)
        value = Version(value)
    except InvalidVersion:
        raise argparse.ArgumentTypeError("%s is an invalid version value" % value)
    return value
github eccentricayman / dotfiles / emacs / .emacs.d / .python-environments / default / lib / python2.7 / site-packages / pkg_resources / __init__.py View on Github external
def safe_version(version):
    """
    Convert an arbitrary string to a standard version string
    """
    try:
        # normalize the version
        return str(packaging.version.Version(version))
    except packaging.version.InvalidVersion:
        version = version.replace(' ', '.')
        return re.sub('[^A-Za-z0-9.]+', '-', version)