rez.solver#

The dependency resolving module.

This gives direct access to the solver. You should use the resolve() function in resolve.py instead, which will use cached data where possible to provide you with a faster resolve.

See SOLVER.md for an in-depth description of how this module works.

class rez.solver.VariantSelectMode#

Bases: Enum

Variant selection mode.

version_priority = 0#
intersection_priority = 1#
class rez.solver.SolverStatus#

Bases: Enum

Enum to represent the current state of a solver instance. The enum also includes a human readable description of what the state represents.

pending = ('The solve has not yet started.',)#
solved = ('The solve has completed successfully.',)#
exhausted = ('The current solve is exhausted and must be split to continue further.',)#
failed = ('The solve is not possible.',)#
cyclic = ('The solve contains a cycle.',)#
unsolved = ('The solve has started, but is not yet solved.',)#
class rez.solver.SolverCallbackReturn#

Bases: Enum

Enum returned by the callback callable passed to a Solver instance.

keep_going = ('Continue the solve',)#
abort = ('Abort the solve',)#
fail = 'Stop the solve and set to most recent failure'#
class rez.solver.SolverState#

Bases: object

Represent the current state of the solver instance for use with a callback.

__init__(num_solves, num_fails, phase)#
class rez.solver.Reduction#

Bases: _Common

A variant was removed because its dependencies conflicted with another scope in the current phase.

__init__(name, version, variant_index, dependency, conflicting_request)#
reducee_str()#
involved_requirements()#
class rez.solver.DependencyConflict#

Bases: _Common

A common dependency shared by all variants in a scope, conflicted with another scope in the current phase.

__init__(dependency, conflicting_request)#
Parameters:
  • dependency (Requirement) – Merged requirement from a set of variants.

  • conflicting_request (Requirement) – The request they conflict with.

class rez.solver.FailureReason#

Bases: _Common

involved_requirements()#
description()#
class rez.solver.TotalReduction#

Bases: FailureReason

All of a scope’s variants were reduced away.

__init__(reductions)#
involved_requirements()#
description()#
class rez.solver.DependencyConflicts#

Bases: FailureReason

A common dependency in a scope conflicted with another scope in the current phase.

__init__(conflicts)#
involved_requirements()#
description()#
class rez.solver.Cycle#

Bases: FailureReason

The solve contains a cyclic dependency.

__init__(packages)#
involved_requirements()#
description()#
class rez.solver.PackageVariant#

Bases: _Common

A variant of a package.

__init__(variant, building)#

Create a package variant.

Parameters:
  • variant (Variant) – Package variant.

  • building (bool) – True if a build is occurring.

property name#
property version#
property index#
property handle#
requires_list()#

It is important that this property is calculated lazily. Getting the ‘requires’ attribute may trigger a package load, which may be avoided if this variant is reduced away before that happens.

property request_fams#
property conflict_request_fams#
get(pkg_name)#
class rez.solver.PackageVariantCache#

Bases: object

__init__(solver)#
get_variant_slice(package_name, range_)#

Get a list of variants from the cache.

Parameters:
  • package_name (str) – Name of package.

  • range (VersionRange) – Package version range.

Returns:

_PackageVariantSlice object.

class rez.solver.Solver#

Bases: _Common

Solver.

A package solver takes a list of package requests (the ‘request’), then runs a resolve algorithm in order to determine the ‘resolve’ - the list of non-conflicting packages that include all dependencies.

max_verbosity = 3#
__init__(package_requests, package_paths, context=None, package_filter=None, package_orderers=None, callback=None, building=False, optimised=True, verbosity=0, buf=None, package_load_callback=None, prune_unfailed=True, suppress_passive=False, print_stats=False)#

Create a Solver.

Parameters:
  • package_requests – List of Requirement objects representing the request.

  • package_paths – List of paths to search for pkgs.

  • context (ResolvedContext) – Context this solver is used within, if any. This is needed in a solve if any packages contain late binding package attributes that need access to context info.

  • package_filter (PackageFilterBase) – Filter for excluding packages.

  • package_orderers (list of PackageOrder) – Custom package ordering.

  • building – True if we’re resolving for a build.

  • optimised – Run the solver in optimised mode. This is only ever set to False for testing purposes.

  • callback – If not None, this callable will be called after each solve step. It is passed a SolverState object. It must return a 2-tuple: - SolverCallbackReturn object indicating what to do next; - str: Reason for solve abort, ignored if solve not aborted. If the callable returns SolverCallbackReturn.fail, but there has not been a failure, the solver will ignore the callback and continue on with the solve.

  • package_load_callback – If not None, this callable will be called prior to each package being loaded. It is passed a single Package object.

  • prune_unfailed (bool) – If the solve failed, and prune_unfailed is True, any packages unrelated to the conflict are removed from the graph.

  • suppress_passive (bool) – If True, don’t print debugging info that has had no effect on the solve. This argument only has an effect if verbosity > 2.

  • print_stats (bool) – If true, print advanced solver stats at the end.

timed(target)#
property status#

Return the current status of the solve.

Returns:

Enum representation of the state of the solver.

Return type:

SolverStatus

property num_solves#

Return the number of solve steps that have been executed.

property num_fails#

Return the number of failed solve steps that have been executed. Note that num_solves is inclusive of failures.

property cyclic_fail#

Return True if the solve failed due to a cycle, False otherwise.

property resolved_packages#

Return a list of resolved variants.

Returns:

Resolved variants, or None if the resolve did not complete or was unsuccessful.

Return type:

list of PackageVariant

property resolved_ephemerals#

Return the list of final ephemeral package ranges.

Note that conflict ephemerals are not included.

Returns:

Final non-conflict ephemerals, or None if the resolve did not complete or was unsuccessful.

Return type:

List of Requirement

reset()#

Reset the solver, removing any current solve.

solve()#

Attempt to solve the request.

property solve_stats#
solve_step()#

Perform a single solve step.

failure_reason(failure_index=None)#

Get the reason for a failure.

Parameters:

failure_index

Index of the fail to return the graph for (can be negative). If None, the most appropriate failure is chosen according to these rules:

  • If the fail is cyclic, the most recent fail (the one containing the cycle) is used;

  • If a callback has caused a failure, the most recent fail is used;

  • Otherwise, the first fail is used.

Returns:

A FailureReason subclass instance describing the failure.

failure_description(failure_index=None)#

Get a description of the failure.

This differs from failure_reason - in some cases, such as when a callback forces a failure, there is more information in the description than there is from failure_reason.

failure_packages(failure_index=None)#

Get packages involved in a failure.

Parameters:

failure_index – See failure_reason.

Returns:

A list of Requirement objects.

get_graph()#

Returns the most recent solve graph.

This gives a graph showing the latest state of the solve. The specific graph returned depends on the solve status. When status is: unsolved: latest unsolved graph is returned; solved: final solved graph is returned; failed: most appropriate failure graph is returned (see failure_reason); cyclic: last failure is returned (contains cycle).

Returns:

A pygraph.digraph object.

get_fail_graph(failure_index=None)#

Returns a graph showing a solve failure.

Parameters:

failure_index – See failure_reason

Returns:

A pygraph.digraph object.

dump()#

Print a formatted summary of the current solve state.