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)

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)

Represents a set of Dependent. This class behaves like a set.

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 solving
  • expand() provides minimal expansion of dependency trees
  • dig() provides expansion of “root” dependents – dependents with no dependencies of their own
  • draw() provides a means to print a dependency tree to the terminal (useful when debugging)
revscoring.dependencies.solve(dependents, context=None, cache=None)

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 of revscoring.Dependent pairs.

cache : dict

A cache of previously solved dependencies as revscoring.Dependent:<value> pairs

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

revscoring.dependencies.expand(dependents, context=None, cache=None)

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 of revscoring.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

revscoring.dependencies.dig(dependents, context=None, cache=None)

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 of revscoring.Dependent pairs.

cache : dict | set

A cache of previously solved dependencies to not scan beneath

Returns:

A generator over root dependencies

revscoring.dependencies.draw(dependent, context=None, cache=None, depth=0)

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 of revscoring.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

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.

expand(dependents, cache=None, context=None)[source]

Expands iterable of all dependents within the context.

See expand() for call signature.

solve(dependents, context=None, cache=None)[source]

Solves an iterable of dependents within the context.

See solve() for call signature.

Revision Scoring

Navigation

Related Topics