revscoring.dependencies¶
This module provides a general set of utilities for implementing a set of dependencies, solving them and injecting context and cache.
-
class
revscoring.
Dependent
(name, process=None, depends_on=None, dependencies=None)[source]¶ Constructs a dependency-handling processor function.
Parameters: - name : str
A name to identify this dependency
- process : func
A function to run when solving this dependency
- depends_on : iterable
A collection of
revscoring.Dependent
whose values are required by process
-
class
revscoring.
DependentSet
(name, _dependents=None, _dependent_sets=None)[source]¶ Represents a set of
Dependent
. This class behaves like aset
.Parameters: - name : str
A base name for the items in the set
functions¶
The following functions provide a set of utilities for working with Dependent and collections of Dependent.
solve()
provides basic dependency solvingexpand()
provides minimal expansion of dependency treesdig()
provides expansion of “root” dependents – dependents with no dependencies of their owndraw()
provides a means to print a dependency tree to the terminal (useful when debugging)
-
revscoring.dependencies.
solve
(dependents, context=None, cache=None, profile=None)[source]¶ Calculates a dependent’s value by solving dependencies.
Parameters: - dependents :
revscoring.Dependent
| iterable A dependent or collection of dependents to solve
- context : dict | iterable
A mapping of injected dependency processers to use as context. Can be specified as a set of new
revscoring.Dependent
or a map ofrevscoring.Dependent
pairs.- cache : dict
A cache of previously solved dependencies as
revscoring.Dependent
:<value> pairs- profile : dict
A mapping of
revscoring.Dependent
to list of process durations for generating the value. The provided dict will be modified in-place and new durations will be appended.
Returns: The result of executing the dependents with all dependencies resolved. If a single dependent is provided, the value will be returned. If a collection of dependents is provided, a generator of values will be returned
- dependents :
-
revscoring.dependencies.
expand
(dependents, context=None, cache=None)[source]¶ Calculates a dependent’s value by solving dependencies.
Parameters: - dependents :
revscoring.Dependent
| iterable A dependent or collection of dependents to solve
- context : dict | iterable
A mapping of injected dependency processers to use as context. Can be specified as a set of new
revscoring.Dependent
or a map ofrevscoring.Dependent
pairs.- cache : dict
A cache of previously solved dependencies as Dependent:<value> pairs
Returns: A generator over all dependents in the dependency tree with each dependent occurring only once
- dependents :
-
revscoring.dependencies.
dig
(dependents, context=None, cache=None)[source]¶ Expands root dependencies. These are dependents at the bottom of the tree –
revscoring.Dependent
with no dependencies of their own.Parameters: - dependents :
revscoring.Dependent
| iterable A dependent or collection of dependents to scan
- context : dict | iterable
A mapping of injected dependency processers to use as context. Can be specified as a set of new
revscoring.Dependent
or a map ofrevscoring.Dependent
pairs.- cache : dict | set
A cache of previously solved dependencies to not scan beneath
Returns: A generator over root dependencies
- dependents :
-
revscoring.dependencies.
draw
(dependent, context=None, cache=None, depth=0)[source]¶ Returns a string representation of the the dependency tree for a single
revscoring.Dependent
.Parameters: - dependent :
revscoring.Dependent
The dependent to draw the dependencies for.
- context : dict | iterable
A mapping of injected dependency processers to use as context. Can be specified as a set of
revscoring.Dependent
or a map ofrevscoring.Dependent
pairs.- cache : dict | set
A cache of previously solved dependencies as Dependent:<value> pairs. When these items are reached while scanning the tree, “CACHED” will be printed.
Returns: None
- dependent :
context¶
-
class
revscoring.dependencies.context.
Context
(context=None, cache=None)[source]¶ Represents a contextual space for solving dependencies
Parameters: - context : dict | iterable
A set of dependents to be used in place of those already provided when solving dependencies.
- cache : dict
A cache of computed values to use for every call to
revscoring.dependencies.solve()
-
dig
(dependents, cache=None, context=None)[source]¶ Digs up the root dependents within the context.
See
dig()
for call signature.
-
draw
(dependent, cache=None, context=None)[source]¶ Returns a string representing the tree structure of a dependent’s dependencies.
See
draw()
for call signature.