Example #1
0
def test_resolver(provider, base_reporter):
    resolver = Resolver(provider, base_reporter)
    result = resolver.resolve(provider.root_requirements)

    display = {
        identifier: candidate.version
        for identifier, candidate in result.mapping.items()
    }
    assert display == provider.expectation
def main(requirements):
    reqs = [Requirement(r) for r in requirements]

    reporter = BaseReporter()
    provider = Provider()
    resolver = Resolver(provider, reporter)

    state = resolver.resolve(reqs)
    target_path = Path("__pypackages__") / PYTHON_VERSION[:3] / "lib"
    print("resolution result:")
    for k, c in state.mapping.items():
        print(c.name, c.version)

    for c in state.mapping.values():
        c.install(target_path)
Example #3
0
def resolve(
    resolver: Resolver, requirements: List[Requirement],
    requires_python: PySpecSet
) -> Tuple[Dict[str, Candidate], Dict[str, Dict[str, Requirement]], Dict[str,
                                                                         str]]:
    provider, reporter = resolver.provider, resolver.reporter
    result = resolver.resolve(requirements)

    reporter.extract_metadata()
    all_metasets = _calculate_markers_and_pyspecs(
        result, provider.requires_python_collection)

    mapping = result.mapping

    for key, metaset in all_metasets.items():
        if key is None:
            continue
        # Root requires_python doesn't participate in the metaset resolving,
        # now check it!
        python = requires_python & metaset[1]
        if python.is_impossible:
            # Candidate doesn't match requires_python constraint
            del mapping[key]
        else:
            candidate = mapping[key]
            candidate.marker = join_metaset(metaset)
            candidate.hashes = provider.get_hashes(candidate)
    return mapping, provider.fetched_dependencies, provider.summary_collection
Example #4
0
def resolve(
    resolver: Resolver,
    requirements: List[Requirement],
    requires_python: PySpecSet,
    max_rounds: int = 10000,
) -> Tuple[Dict[str, Candidate], Dict[str, List[Requirement]], Dict[str, str]]:
    """Core function to perform the actual resolve process.
    Return a tuple containing 3 items:

        1. A map of pinned candidates
        2. A map of resolved dependencies from each section of pyproject.toml
        3. A map of package descriptions fetched from PyPI source.
    """
    provider = resolver.provider
    result = resolver.resolve(requirements, max_rounds)

    mapping = result.mapping
    for key, candidate in list(result.mapping.items()):
        if key is None:
            continue
        # Root requires_python doesn't participate in the metaset resolving,
        # now check it!
        candidate_requires = provider.requires_python_collection[strip_extras(key)[0]]
        if (requires_python & candidate_requires).is_impossible:
            # Remove candidates that don't match requires_python constraint
            del mapping[key]
        else:
            candidate.requires_python = str(candidate_requires)
            candidate.hashes = provider.get_hashes(candidate)

    return mapping, provider.fetched_dependencies, provider.summary_collection
Example #5
0
def resolve_requirements(
    repository,
    lines,
    requires_python="",
    allow_prereleases=None,
    strategy="all",
    preferred_pins=None,
    tracked_names=None,
):
    requirements = []
    for line in lines:
        if line.startswith("-e "):
            requirements.append(parse_requirement(line[3:], True))
        else:
            requirements.append(parse_requirement(line))
    requires_python = PySpecSet(requires_python)
    if not preferred_pins:
        provider = BaseProvider(repository, requires_python, allow_prereleases)
    else:
        provider_class = (ReusePinProvider
                          if strategy == "reuse" else EagerUpdateProvider)
        provider = provider_class(
            preferred_pins,
            tracked_names or (),
            repository,
            requires_python,
            allow_prereleases,
        )
    ui = termui.UI()
    with ui.open_spinner("Resolving dependencies") as spin, ui.logging("lock"):
        reporter = SpinnerReporter(spin, requirements)
        resolver = Resolver(provider, reporter)
        mapping, *_ = resolve(resolver, requirements, requires_python)
        return mapping
Example #6
0
def resolve(
    resolver: Resolver,
    requirements: list[Requirement],
    requires_python: PySpecSet,
    max_rounds: int = 10000,
) -> tuple[dict[str, Candidate], dict[str, list[Requirement]]]:
    """Core function to perform the actual resolve process.
    Return a tuple containing 3 items:

        1. A map of pinned candidates
        2. A map of resolved dependencies for each dependency group
        3. A map of package descriptions fetched from PyPI source
    """
    requirements.append(PythonRequirement.from_pyspec_set(requires_python))
    provider = cast(BaseProvider, resolver.provider)
    result = resolver.resolve(requirements, max_rounds)

    mapping = cast(Dict[str, Candidate], result.mapping)
    mapping.pop("python", None)
    for key, candidate in list(result.mapping.items()):
        if key is None:
            continue
        # For source distribution whose name can only be determined after it is built,
        # the key in the resolution map should be updated.
        if key.startswith(":empty:"):
            new_key = provider.identify(candidate)
            mapping[new_key] = mapping.pop(key)
            key = new_key

        candidate.hashes = provider.repository.get_hashes(candidate)

    return mapping, provider.fetched_dependencies
Example #7
0
    def resolve_func(
        lines,
        requires_python="",
        allow_prereleases=None,
        strategy="all",
        tracked_names=None,
    ):
        repository.environment.python_requires = PySpecSet(requires_python)
        if allow_prereleases is not None:
            project.tool_settings["allow_prereleases"] = allow_prereleases
        requirements = []
        for line in lines:
            if line.startswith("-e "):
                requirements.append(parse_requirement(line[3:], True))
            else:
                requirements.append(parse_requirement(line))
        provider = project.get_provider(strategy, tracked_names)

        ui = project.core.ui
        with ui.open_spinner("Resolving dependencies") as spin, ui.logging(
                "lock"):
            reporter = SpinnerReporter(spin, requirements)
            resolver = Resolver(provider, reporter)
            mapping, *_ = _resolve(resolver, requirements,
                                   repository.environment.python_requires)
            return mapping
Example #8
0
def resolve(
    resolver: Resolver,
    requirements: List[Requirement],
    requires_python: PySpecSet,
    max_rounds: int = 1000,
) -> Tuple[Dict[str, Candidate], Dict[str, List[Requirement]], Dict[str, str]]:
    """Core function to perform the actual resolve process.
    Return a tuple containing 3 items:

        1. A map of pinned candidates
        2. A map of resolved dependencies from each section of pyproject.toml
        3. A map of package descriptions fetched from PyPI source.
    """
    provider, reporter = resolver.provider, resolver.reporter
    result = resolver.resolve(requirements, max_rounds)

    reporter.extract_metadata()
    all_metasets = extract_metadata(result)

    mapping = result.mapping

    for key, metaset in all_metasets.items():
        if key is None:
            continue
        # Root requires_python doesn't participate in the metaset resolving,
        # now check it!
        python = (
            requires_python
            & metaset.requires_python
            & provider.requires_python_collection[strip_extras(key)[0]]
        )
        if python.is_impossible:
            # Candidate doesn't match requires_python constraint
            del mapping[key]
        else:
            candidate = mapping[key]
            candidate.marker = metaset.as_marker()
            candidate.hashes = provider.get_hashes(candidate)

    populate_sections(result)
    return mapping, provider.fetched_dependencies, provider.summary_collection
Example #9
0
def resolve(
    resolver: Resolver,
    requirements: list[Requirement],
    requires_python: PySpecSet,
    max_rounds: int = 10000,
) -> tuple[dict[str, Candidate], dict[str, list[Requirement]], dict[str, str]]:
    """Core function to perform the actual resolve process.
    Return a tuple containing 3 items:

        1. A map of pinned candidates
        2. A map of resolved dependencies for each dependency group
        3. A map of package descriptions fetched from PyPI source
    """
    provider = cast(BaseProvider, resolver.provider)
    result = resolver.resolve(requirements, max_rounds)

    mapping = cast(Dict[str, Candidate], result.mapping)
    for key, candidate in list(result.mapping.items()):
        if key is None:
            continue
        # For source distribution whose name can only be determined after it is built,
        # the key in the resolution map should be updated.
        if key.startswith(":empty:"):
            new_key = provider.identify(candidate)
            mapping[new_key] = mapping.pop(key)
            key = new_key
        # Root requires_python doesn't participate in the metaset resolving,
        # now check it!
        candidate_requires = provider.requires_python_collection[strip_extras(
            key)[0]]
        if (requires_python & candidate_requires).is_impossible:
            # Remove candidates that don't match requires_python constraint
            del mapping[key]
        else:
            candidate.requires_python = str(candidate_requires)
            candidate.hashes = provider.get_hashes(candidate)

    return mapping, provider.fetched_dependencies, provider.summary_collection
def test_resolver(provider, reporter):
    resolver = Resolver(provider, reporter)

    result = resolver.resolve(provider.root_requirements)
    assert _format_resolution(result) == provider.expected_resolution