piptools.resolver module#

class piptools.resolver.BacktrackingResolver(constraints: Iterable[InstallRequirement], existing_constraints: dict[str, InstallRequirement], repository: BaseRepository, allow_unsafe: bool = False, unsafe_packages: set[str] | None = None, **kwargs: Any)#

Bases: BaseResolver

A wrapper for the backtracking (or 2020) resolver.

_abc_impl = <_abc._abc_data object>#
_do_resolve(resolver: Resolver, compatible_existing_constraints: dict[str, InstallRequirement]) bool#

Resolve dependencies based on resolvelib Resolver.

Returns:

True on successful resolution, otherwise removes problematic requirements from existing constraints and returns False.

_get_install_requirement_from_candidate(candidate: Candidate, reverse_dependencies: dict[str, set[str]]) InstallRequirement | None#
_get_install_requirements(resolver_result: Result) set[InstallRequirement]#

Return a set of install requirements from resolver results.

static _get_reverse_dependencies(resolver_result: Result) dict[str, set[str]]#
resolve(max_rounds: int = 10) set[InstallRequirement]#

Resolve given ireqs.

Find concrete package versions for all the given InstallRequirements and their recursive dependencies.

Returns:

A set of pinned InstallRequirements.

class piptools.resolver.BaseResolver#

Bases: object

_abc_impl = <_abc._abc_data object>#
_filter_out_unsafe_constraints(ireqs: set[InstallRequirement], unsafe_packages: Container[str]) None#

Remove from a given set of InstallRequirements unsafe constraints.

repository: BaseRepository#
abstract resolve(max_rounds: int) set[InstallRequirement]#

Find concrete package versions for all the given InstallRequirements and their recursive dependencies. :returns: a set of pinned InstallRequirements.

resolve_hashes(ireqs: set[InstallRequirement]) dict[InstallRequirement, set[str]]#

Find acceptable hashes for all of the given InstallRequirements.

unsafe_constraints: set[InstallRequirement]#
class piptools.resolver.LegacyResolver(constraints: Iterable[InstallRequirement], existing_constraints: dict[str, InstallRequirement], repository: BaseRepository, cache: DependencyCache, prereleases: bool | None = False, clear_caches: bool = False, allow_unsafe: bool = False, unsafe_packages: set[str] | None = None)#

Bases: BaseResolver

Wrapper for the (deprecated) legacy dependency resolver.

_abc_impl = <_abc._abc_data object>#
_group_constraints(constraints: Iterable[InstallRequirement]) Iterator[InstallRequirement]#

Group constraints (remember, InstallRequirements!) by their key name.

Then combine their SpecifierSets into a single InstallRequirement per package. For example, given the following constraints:

Django<1.9,>=1.4.2 django~=1.5 Flask~=0.7

This will be combined into a single entry per package:

django~=1.5,<1.9,>=1.4.2 flask~=0.7

_ireqs_of_dependencies(ireq: InstallRequirement, dependency_strings: list[str]) Iterator[InstallRequirement]#
_iter_dependencies(ireq: InstallRequirement) Iterator[InstallRequirement]#

Emit all secondary dependencies for an ireq.

Given a pinned, url, or editable InstallRequirement, collects all the secondary dependencies for them, either by looking them up in a local cache, or by reaching out to the repository.

Editable requirements will never be looked up, as they may have changed at any time.

_resolve_one_round() tuple[bool, set[InstallRequirement]]#

Resolve one level of the current constraints.

This is achieved by finding the best match for each package in the repository and adding all requirements for those best package versions. Some of these constraints may be new or updated.

Returns:

whether new constraints appeared in this round. If no constraints were added or changed, this indicates a stable configuration.

property constraints: set[InstallRequirement]#
get_best_match(ireq: InstallRequirement) InstallRequirement#

Return a (pinned or editable) InstallRequirement.

This indicates the best match to use for the given InstallRequirement (in the form of an InstallRequirement).

Example: Given the constraint Flask>=0.10, may return Flask==0.10.1 at a certain moment in time.

Pinned requirements will always return themselves, i.e.

Flask==0.10.1 => Flask==0.10.1

resolve(max_rounds: int = 10) set[InstallRequirement]#

Find concrete package versions for all the given InstallRequirements and their recursive dependencies and return a set of pinned InstallRequirements.

Resolves constraints one round at a time, until they don’t change anymore.

Parameters:

max_rounds – break out of resolution process after the given number of rounds to prevent infinite loops (default is 10)

class piptools.resolver.RequirementSummary(ireq: InstallRequirement)#

Bases: object

Summary of a requirement’s properties for comparison purposes.

piptools.resolver.combine_install_requirements(ireqs: Iterable[InstallRequirement]) InstallRequirement#

Return a single install requirement that reflects a combination of all the inputs.