a
ljI @ s d Z ddlZddlmZ ddlmZmZmZmZm Z m
Z
mZ ddlm
Z
ddlmZ ee
eg e e f f Zerzee ZneZee ee dd d
Zeee ee ddd
Zeee ee dddZG dd deZdS )a Utilities to lazily create and visit candidates found.
Creating and visiting a candidate is a *very* costly operation. It involves
fetching, extracting, potentially building modules from source, and verifying
distribution metadata. It is therefore crucial for performance to keep
everything here lazy all the way down, so we only touch candidates that we
absolutely need, and not "download the world" when we only need one version of
something.
N)Sequence)
TYPE_CHECKINGAnyCallableIteratorOptionalSetTuple)_BaseVersion ) Candidate)infosreturnc c sB t }| D ]2\}}||v rq
| }|du r,q
|V || q
dS )zIterator for ``FoundCandidates``.
This iterator is used when the package is not already installed. Candidates
from index come later in their normal ordering.
N)setadd)r
versions_foundversionfunc candidate r X/usr/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py_iter_built% s r ) installedr
r c c sJ | V | j h}|D ]2\}}||v r$q| }|du r4q|V || qdS )aK Iterator for ``FoundCandidates``.
This iterator is used when the resolver prefers the already-installed
candidate and NOT to upgrade. The installed candidate is therefore
always yielded first, and candidates from index come later in their
normal ordering, except skipped when the version is already installed.
N)r r r r
r r r r r r r _iter_built_with_prepended6 s
r c c sn t }|D ]N\}}||v rq
| j|kr8| V || j | }|du rHq
|V || q
| j|vrj| V dS )a Iterator for ``FoundCandidates``.
This iterator is used when the resolver prefers to upgrade an
already-installed package. Candidates from index are returned in their
normal ordering, except replaced when the version is already installed.
The implementation iterates through and yields other candidates, inserting
the installed candidate exactly once before we start yielding older or
equivalent candidates, or after all other candidates if they are all newer.
N)r r r r r r r _iter_built_with_insertedL s
r c @ s e Zd ZdZeg ee f ee e e
e dddZe
e
dddZee dd d
ZedddZejd
de dddZdS )FoundCandidatesac A lazy sequence to provide candidates to the resolver.
The intended usage is to return this from `find_matches()` so the resolver
can iterate through the sequence multiple times, but only access the index
page when remote packages are actually needed. This improve performances
when suitable candidates are already installed on disk.
) get_infosr prefers_installedincompatible_idsc C s || _ || _|| _|| _d S N)
_get_infos
_installed_prefers_installed_incompatible_ids)selfr r r r r r r __init__u s zFoundCandidates.__init__)indexr c C s t dd S Nz
don't do thisNotImplementedError)r% r' r r r __getitem__ s zFoundCandidates.__getitem__)r c sJ } jst|}n jr,t j|}nt j|} fdd|D S )Nc 3 s | ]}t | jvr|V qd S r )idr$ ).0cr% r r