How to use the distlib.util.parse_requirement function in distlib

To help you get started, we’ve selected a few distlib 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 iodide-project / pyodide / packages / micropip / micropip / micropip.py View on Github external
def add_requirement(self, requirement, ctx, transaction):
        req = util.parse_requirement(requirement)

        # If it's a Pyodide package, use that instead of the one on PyPI
        if req.name in self.builtin_packages:
            transaction['pyodide_packages'].add(req.name)
            return

        if req.marker:
            if not markers.evaluator.evaluate(
                    req.marker, ctx):
                return

        matcher = self.version_scheme.matcher(req.requirement)

        # If we already have something that will work, don't
        # fetch again
        for name, ver in transaction['locked'].items():
github clarete / curdling / curdling / __init__.py View on Github external
def check_installed(self, package):
        return DistributionPath().get_distribution(
            parse_requirement(package).name.replace('_', '-')) is not None
github colcon / colcon-core / colcon_core / package_identification / python.py View on Github external
See https://www.python.org/dev/peps/pep-0440/#version-specifiers

    :param str requirement_string: a PEP440 compliant requirement string
    :return: A descriptor with version constraints from the requirement string
    :rtype: DependencyDescriptor
    """
    symbol_mapping = {
        '==': 'version_eq',
        '!=': 'version_neq',
        '<=': 'version_lte',
        '>=': 'version_gte',
        '>': 'version_gt',
        '<': 'version_lt',
    }

    requirement = parse_requirement(requirement_string)
    metadata = {}
    for symbol, version in (requirement.constraints or []):
        if symbol in symbol_mapping:
            metadata[symbol_mapping[symbol]] = version
        elif symbol == '~=':
            metadata['version_gte'] = version
            metadata['version_lt'] = _next_incompatible_version(version)
        else:
            logger.warning(
                "Ignoring unknown symbol '{symbol}' in '{requirement}'"
                .format_map(locals()))
    return DependencyDescriptor(requirement.name, metadata=metadata)
github clarete / curdling / curdling / util.py View on Github external
def parse_requirement(spec):
    if not is_url(spec):
        requirement = util.parse_requirement(spec)
        requirement.name = safe_name(requirement.name)
        requirement.requirement = safe_requirement(spec)
        requirement.is_link = False
    else:
        requirement = Requirement()
        requirement.name = spec
        requirement.requirement = spec
        requirement.constraints = ()
        requirement.is_link = True
        requirement.extras = ()
    return requirement