Lightweight, easy-to-use, flexible composite data structures.
Adjacency(contents=dict())
dataclass
¶
Bases: Graph, Dictionary
Base class for adjacency-list graphs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
MutableMapping[Hashable, set[Hashable]]
|
keys are hashable representations of nodes. Values are the
nodes to which the key node are connected. In a directed graph, the
key node is assumed to come before the value node in order. Nodes
that only appear in a value are added as keys with no connections.
Defaults to an empty |
dict()
|
Composite(contents=None)
dataclass
¶
Bases: ABC
Base class for composite data structures.
A subclass must provide the nodes property and the _add, _delete,
_merge, and _subset methods. The public methods of Composite provide
validation and error-checking so that subclasses only need to provide the
mechanism for each operation on the internal storage format they use.
Every direct subclass of Composite is automatically registered in
Forms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
Collection[Any] | None
|
stored nodes or node labels. Subclasses should narrow the type for contents based on the internal storage format used. |
None
|
contents = None
class-attribute
instance-attribute
¶
Initialization Methods
nodes
property
¶
Returns a set of all nodes in the stored composite data structure.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
if a subclass does not provide |
add(item, **kwargs)
¶
Adds node to the stored composite data structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Hashable
|
node to add to the stored composite data structure. |
required |
**kwargs
|
Any
|
additional keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
if |
Source code in src/holden/base.py
delete(item, **kwargs)
¶
Deletes node from the stored composite data structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Hashable
|
node to delete from the stored composite data structure. |
required |
**kwargs
|
Any
|
additional keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
KeyError
|
if |
TypeError
|
if |
Source code in src/holden/base.py
merge(item, **kwargs)
¶
Adds item to this Composite.
This method is roughly equivalent to a dict.update, just adding item
to the existing stored composite data structure while maintaining its
structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
another Composite or a raw form of a composite data structure to merge with. |
required |
**kwargs
|
Any
|
additional keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
Source code in src/holden/base.py
subset(include=None, exclude=None)
¶
Returns a new Composite with a subset of the stored nodes.
All edges will be removed that include any nodes that are not part of the new composite data structure.
Any extra attributes that are part of a Composite (or a subclass) are maintained in the returned composite data structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include
|
Hashable | Sequence[Hashable] | None
|
node(s) which should be included in the new composite data
structure. If |
None
|
exclude
|
Hashable | Sequence[Hashable] | None
|
node(s) which should not be included in the new composite
data structure. Defaults to |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Returns:
| Type | Description |
|---|---|
Composite
|
Composite with only selected nodes and edges. |
Source code in src/holden/base.py
Directed()
dataclass
¶
Bases: ABC
Mixin for directed graph data structures.
The methods of Directed work for any form of graph (or composite data
structure) that holden recognizes. Subclasses may override the methods and
properties to use more efficient approaches for their internal storage
formats.
endpoint
property
¶
Returns the endpoints of the stored composite.
root
property
¶
Returns the roots of the stored composite.
append(item, attachment=None, **kwargs)
¶
Appends item to the endpoint(s) of the stored composite.
Appending merges item into the stored composite and creates an edge
from every endpoint of the stored composite to every root of item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
a node, another composite data structure, or a raw form of a composite data structure to add to the stored composite. |
required |
attachment
|
Hashable | MutableSequence[Hashable] | None
|
the endpoint or endpoints to attach |
None
|
**kwargs
|
Any
|
additional keyword arguments passed to |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
Source code in src/holden/traits.py
prepend(item, **kwargs)
¶
Prepends item to the root(s) of the stored composite.
Prepending merges item into the stored composite and creates an edge
from every endpoint of item to every root of the stored composite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
a node, another composite data structure, or a raw form of a composite data structure to add to the stored composite. |
required |
**kwargs
|
Any
|
additional keyword arguments passed to |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
Source code in src/holden/traits.py
walk(start=None, stop=None)
¶
Returns all paths in the stored composite from start to stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
Hashable | list[Hashable] | None
|
node (or list of nodes) to start paths from. If it is |
None
|
stop
|
Hashable | list[Hashable] | None
|
node (or list of nodes) to stop paths at. If it is |
None
|
Returns:
| Type | Description |
|---|---|
RawParallel
|
A list of possible paths (each path is a list of nodes) from |
Source code in src/holden/traits.py
Edge(start, stop)
dataclass
¶
Bases: Sequence
Base class for an edge in a graph structure.
Edges are not required for most of the base graph classes in holden. But they can be used by subclasses of those base classes for more complex data structures.
An Edge is a drop-in replacement for a tuple of 2 nodes. It can be
indexed, iterated over, unpacked, and compared to a tuple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
Hashable
|
starting point for the edge. |
required |
stop
|
Hashable
|
stopping point for the edge. |
required |
stop
instance-attribute
¶
Dunder Methods
Edges(contents=list())
dataclass
¶
Bases: Graph, Listing
Base class for edge-list graphs.
An edge list can only store nodes that are part of an edge. As a result, a
graph is built up by adding edges with connect (which adds the nodes of
the edge, if necessary) or with add (which only accepts edges). A node
with no edges cannot be added on its own.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
MutableSequence[Edge | tuple[Hashable, Hashable]]
|
Listing of edges. Defaults to an empty list. |
list()
|
nodes
property
¶
Returns a set of all nodes in the graph.
Exportable()
dataclass
¶
Bases: ABC
Mixin for exporting graphs to other formats.
to_dot(path=None, name=None, settings=None)
¶
Converts the stored composite to a dot format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path | None
|
path to export to. Defaults to |
None
|
name
|
str | None
|
name to put in the dot |
None
|
settings
|
dict[str, Any] | None
|
any global settings to add to the dot graph. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
str
|
Composite object in graphviz dot format. |
Source code in src/holden/traits.py
to_mermaid(path=None, name=None, settings=None)
¶
Converts the stored composite to a mermaid format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path | None
|
path to export to. Defaults to |
None
|
name
|
str | None
|
name to put in the mermaid |
None
|
settings
|
dict[str, Any] | None
|
any global settings to add to the mermaid graph. Defaults
to |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Composite object in mermaid format. |
Source code in src/holden/traits.py
Forms()
dataclass
¶
Bases: Registrar
Registry of composite data structures.
Attributes:
| Name | Type | Description |
|---|---|---|
registry |
GenericDict
|
stores classes to be used in item construction. Keys are the
snake case names of the classes. Defaults to an empty |
registry = {}
class-attribute
¶
Public Methods
classify(item)
classmethod
¶
Determines which form of composite that item is.
There is no difference between this classmethod and the classify
function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
object to classify. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Name of form that |
Source code in src/holden/base.py
register(item, name=None)
classmethod
¶
Adds item to registry.
The key assigned for storing item is determined using the _namify
function if name is not passed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
type[Composite]
|
class to register. |
required |
name
|
str | None
|
key to use for storing |
None
|
Source code in src/holden/base.py
transform(item, output, *, raise_same_error=True)
classmethod
¶
General transform method that will call appropriate transformer.
Unlike the transform function, this method will return a Composite
wrapped in the form type stored in the Forms registry (as opposed to
the raw type). So, if output is edges, this method will return an
edge list in the Edges class. In contrast, the transform function
will return the structural type of an edge list without using the
Edges class. The rest of the logic is identical between the function
and method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
composite data structure or raw form to transform. |
required |
output
|
str
|
name of form to transform |
required |
raise_same_error
|
bool | None
|
whether to raise an error if the form of |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if the form of |
Returns:
| Type | Description |
|---|---|
Any
|
Transformed composite data structure. |
Source code in src/holden/base.py
Fungible()
dataclass
¶
Bases: ABC
Mixin for composite data structures that can be transformed.
Every form can be accessed as a property. The property returns an instance
of the default class for that form (see holden.Forms). If the composite is
already that form, the composite itself is returned. Every form can also be
used to create a new instance using the from_{form} class methods.
adjacency
property
¶
Returns the stored composite as an Adjacency.
edges
property
¶
Returns the stored composite as an Edges.
matrix
property
¶
Returns the stored composite as a Matrix.
parallel
property
¶
Returns the stored composite as a Parallel.
serial
property
¶
Returns the stored composite as a Serial.
from_adjacency(item)
classmethod
¶
Creates a composite data structure from an adjacency list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Adjacency | RawAdjacency
|
an |
required |
Returns:
| Type | Description |
|---|---|
Self
|
New instance of this class derived from |
Source code in src/holden/traits.py
from_edges(item)
classmethod
¶
Creates a composite data structure from an edge list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Edges | RawEdges
|
an |
required |
Returns:
| Type | Description |
|---|---|
Self
|
New instance of this class derived from |
Source code in src/holden/traits.py
from_matrix(item)
classmethod
¶
Creates a composite data structure from an adjacency matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Matrix | RawMatrix
|
a |
required |
Returns:
| Type | Description |
|---|---|
Self
|
New instance of this class derived from |
Source code in src/holden/traits.py
from_parallel(item)
classmethod
¶
Creates a composite data structure from a parallel structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Parallel | RawParallel
|
a |
required |
Returns:
| Type | Description |
|---|---|
Self
|
New instance of this class derived from |
Source code in src/holden/traits.py
from_serial(item)
classmethod
¶
Creates a composite data structure from a serial structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Serial | RawSerial
|
a |
required |
Returns:
| Type | Description |
|---|---|
Self
|
New instance of this class derived from |
Source code in src/holden/traits.py
Graph(contents=None)
dataclass
¶
Bases: Composite, ABC
Base class for holden graphs.
Graph adds the requirements of _connect and _disconnect methods in
addition to the requirements of Composite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
Collection[Any] | None
|
stored nodes, node labels, edges, or edge labels. Subclasses should narrow the type for contents based on the internal storage format used. |
None
|
connect(item, **kwargs)
¶
Adds edge to the stored graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Edge | tuple[Hashable, Hashable]
|
edge to add to the stored graph. |
required |
**kwargs
|
Any
|
additional keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
if the ends of the item are the same or if one of the edge ends does not currently exist in the stored graph. |
Source code in src/holden/base.py
disconnect(item, **kwargs)
¶
Removes edge from the stored graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Edge | tuple[Hashable, Hashable]
|
edge to delete from the stored graph. |
required |
**kwargs
|
Any
|
additional keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
if the edge does not exist in the stored graph. |
Source code in src/holden/base.py
Labeled(name=None, contents=None)
dataclass
¶
Bases: ABC
Mixin for labeling a composite object.
Labeled objects are hashed and compared by their name, so that a str
equal to the name of a labeled node can be used in place of the node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
designates the name of a class instance that is used for internal
and external referencing in a composite object. If it is not
passed, |
None
|
contents
|
Any | None
|
any stored item(s). Defaults to |
None
|
contents = None
class-attribute
instance-attribute
¶
Initialization Methods
Matrix(contents=list(), labels=list())
dataclass
¶
Bases: Graph, Listing
Base class for adjacency-matrix graphs.
Any non-zero value in the matrix is an edge from the node of the row to the node of the column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
MutableSequence[MutableSequence[float]]
|
a list of list of numbers indicating edges between nodes in the matrix. Defaults to an empty list. |
list()
|
labels
|
MutableSequence[Hashable]
|
names of nodes in the matrix. The label at each index corresponds to the row and column at that index. Defaults to an empty list. |
list()
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if the matrix is not square or its size does not match the number of labels. |
Node(contents=None)
dataclass
¶
Bases: Hashable
Vertex wrapper to provide hashability to any object.
Node acts a basic wrapper for any item stored in a graph structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
Any | None
|
any stored item(s). Defaults to |
None
|
contents = None
class-attribute
instance-attribute
¶
Initialization Methods
Parallel(contents=list())
dataclass
¶
Bases: Composite, Directed, Fungible, Exportable, Listing
Base class for a list of serial composites.
Each path in a Parallel is a list of nodes (or a Serial) that goes from
one of its roots to one of its endpoints. A Parallel is Directed,
Fungible, and Exportable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
MutableSequence[Serial | MutableSequence[Hashable]]
|
Listing of Serial instances (or lists of nodes). Defaults to an empty list. |
list()
|
contents = dataclasses.field(default_factory=list)
class-attribute
instance-attribute
¶
Properties
nodes
property
¶
Returns a set of all nodes in the stored composite.
add(item, **kwargs)
¶
Adds a path or a node to the stored composite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
a non-empty list of nodes (or a |
required |
**kwargs
|
Any
|
additional keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
TypeError
|
if |
Source code in src/holden/composites.py
append(item, attachment=None, **kwargs)
¶
Appends item to the end of every path.
If item has more than one path, every existing path is followed by
every path of item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
node, path, or other composite data structure (or raw form). |
required |
attachment
|
Hashable | MutableSequence[Hashable] | None
|
unused. It is accepted so that the method matches
|
None
|
**kwargs
|
Any
|
additional keyword arguments. |
{}
|
Source code in src/holden/composites.py
prepend(item, **kwargs)
¶
Prepends item to the start of every path.
If item has more than one path, every path of item precedes every
existing path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
node, path, or other composite data structure (or raw form). |
required |
**kwargs
|
Any
|
additional keyword arguments. |
{}
|
Source code in src/holden/composites.py
Serial(contents=list())
dataclass
¶
Bases: Composite, Directed, Fungible, Exportable, DictList
Base class for serial composites.
A Serial is a single path of nodes. It is Directed, Fungible, and
Exportable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
MutableSequence[Hashable]
|
list of nodes. Defaults to an empty list. |
list()
|
contents = dataclasses.field(default_factory=list)
class-attribute
instance-attribute
¶
Properties
nodes
property
¶
Returns a set of all nodes in the stored composite.
append(item, attachment=None, **kwargs)
¶
Appends item to the end of the stored composite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
a node, another composite data structure (or raw form) whose nodes are added in order. |
required |
attachment
|
Hashable | MutableSequence[Hashable] | None
|
unused. It is accepted so that the method matches
|
None
|
**kwargs
|
Any
|
additional keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
Source code in src/holden/composites.py
prepend(item, **kwargs)
¶
Prepends item to the start of the stored composite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
a node, another composite data structure (or raw form) whose nodes are added in order. |
required |
**kwargs
|
Any
|
additional keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
Source code in src/holden/composites.py
Storage(library=dict())
dataclass
¶
Bases: ABC
Mixin for storing data for nodes separate from the graph structure.
The graph stores lightweight nodes (such as str labels). The data or
objects that those labels represent are stored in library, so they can be
reused without being part of the graph structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
library
|
MutableMapping[Hashable, Any]
|
mapping of nodes to stored data. Defaults to an empty |
dict()
|
library = dataclasses.field(default_factory=dict)
class-attribute
instance-attribute
¶
Public Methods
discard(node)
¶
Removes the data stored for node, if there is any.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Hashable
|
node to remove stored data for. |
required |
retrieve(node)
¶
Returns the data stored for node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Hashable
|
node to return the stored data of. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
if there is no data stored for |
Returns:
| Type | Description |
|---|---|
Any
|
The data stored for |
Source code in src/holden/traits.py
store(node, item)
¶
Stores item as the data for node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Hashable
|
node to store data for. If this instance is a composite data structure, the node must be in it. |
required |
item
|
Any
|
data to store. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
if this instance is a composite data structure and |
Source code in src/holden/traits.py
Structural
¶
Bases: ABCMeta
Metaclass that provides structural subtyping for composite forms.
A class with this metaclass treats a raw python object as an instance if
the object has the structure of the form that the class represents. For
example, isinstance({"a": {"b"}, "b": set()}, holden.Adjacency) is True
because the dict is structured as an adjacency list.
System(contents=dict())
dataclass
¶
Bases: Directed, Adjacency, Fungible, Exportable
Directed graph with unweighted edges stored as an adjacency list.
A System combines the Adjacency form with the Directed, Fungible, and
Exportable traits. So, it can find roots, endpoints, and paths; be
converted to and created from every other form of composite data structure;
and be exported to dot and mermaid formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
MutableMapping[Hashable, set[Hashable]]
|
keys are nodes and values are sets of nodes (or hashable
representations of nodes). Defaults to an empty |
dict()
|
Weighted(weight=1.0)
dataclass
¶
Bases: ABC
Mixin for weighted nodes and edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weight
|
float
|
the weight of the object. Defaults to 1.0. |
1.0
|
weight = 1.0
class-attribute
instance-attribute
¶
Dunder Methods
add_checker(name, item)
¶
Adds a checker to the local namespace.
This allows the function to be found by the holden.classify function and
the holden.Forms.classify class method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the checker function. It needs to be in the |
required |
item
|
Callable[[Any], bool]
|
callable checker which should have a single parameter, |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Source code in src/holden/check.py
add_transformer(name, item)
¶
Adds a transformer to this module's namespace.
This allows the function to be found by the transform function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the transformer function. It needs to be in the
|
required |
item
|
Callable[[Any], Any]
|
callable transformer which should have a single parameter, |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Source code in src/holden/workshop.py
adjacency_to_edges(item)
¶
Converts item to an edge list.
Nodes without any edges cannot be represented in an edge list and are not included in the returned edge list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Adjacency | RawAdjacency
|
adjacency list to convert to an edge list. |
required |
Returns:
| Type | Description |
|---|---|
RawEdges
|
Edge list derived from |
Source code in src/holden/workshop.py
adjacency_to_matrix(item)
¶
Converts item to an adjacency matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Adjacency | RawAdjacency
|
adjacency list to convert to an adjacency matrix. |
required |
Returns:
| Type | Description |
|---|---|
RawMatrix
|
Adjacency matrix derived from |
Source code in src/holden/workshop.py
adjacency_to_parallel(item)
¶
Converts item to a parallel structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Adjacency | RawAdjacency
|
adjacency list to convert to a parallel structure. |
required |
Returns:
| Type | Description |
|---|---|
RawParallel
|
Parallel structure derived from |
Source code in src/holden/workshop.py
adjacency_to_serial(item)
¶
Converts item to a serial structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Adjacency | RawAdjacency
|
adjacency list to convert to a serial structure. |
required |
Returns:
| Type | Description |
|---|---|
RawSerial
|
Serial structure derived from |
Source code in src/holden/workshop.py
classify(item)
¶
Determines which form of composite data structure that item is.
Registered classes are checked first. If item is not an instance (or
subclass) of a registered class, the structure of item is checked against
each form using the is_{form} functions in the check module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
object to classify. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
Returns:
| Type | Description |
|---|---|
str
|
Name of form that |
Source code in src/holden/base.py
edges_to_adjacency(item)
¶
Converts item to an adjacency list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Edges | RawEdges
|
edge list to convert to an adjacency list. |
required |
Returns:
| Type | Description |
|---|---|
RawAdjacency
|
Adjacency list derived from |
Source code in src/holden/workshop.py
edges_to_matrix(item)
¶
Converts item to an adjacency matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Edges | RawEdges
|
edge list to convert to an adjacency matrix. |
required |
Returns:
| Type | Description |
|---|---|
RawMatrix
|
Adjacency matrix derived from |
Source code in src/holden/workshop.py
edges_to_parallel(item)
¶
Converts item to a parallel structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Edges | RawEdges
|
edge list to convert to a parallel structure. |
required |
Returns:
| Type | Description |
|---|---|
RawParallel
|
Parallel structure derived from |
Source code in src/holden/workshop.py
edges_to_serial(item)
¶
Converts item to a serial structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Edges | RawEdges
|
edge list to convert to a serial structure. |
required |
Returns:
| Type | Description |
|---|---|
RawSerial
|
Serial structure derived from |
Source code in src/holden/workshop.py
get_base(name)
¶
Returns the default base class for a form of composite data structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of form to get. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
if |
Returns:
| Type | Description |
|---|---|
type[Composite]
|
Class used as the base type for the |
Source code in src/holden/options.py
get_endpoints(item)
¶
Returns the endpoints in any recognized composite form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
composite data structure or raw form to examine. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
if there is no endpoint function for the form of
|
Returns:
| Type | Description |
|---|---|
MutableSequence[Hashable]
|
List of endpoints. |
Source code in src/holden/report.py
get_endpoints_adjacency(item)
¶
Returns the endpoints in item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Adjacency | RawAdjacency
|
adjacency list object to examine. |
required |
Returns:
| Type | Description |
|---|---|
MutableSequence[Hashable]
|
List of endpoints in the order they appear in |
Source code in src/holden/report.py
get_endpoints_edges(item)
¶
Returns the endpoints in item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Edges | RawEdges
|
edge list object to examine. |
required |
Returns:
| Type | Description |
|---|---|
MutableSequence[Hashable]
|
List of endpoints. |
Source code in src/holden/report.py
get_endpoints_matrix(item)
¶
Returns the endpoints in item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Matrix | RawMatrix
|
adjacency matrix object to examine. |
required |
Returns:
| Type | Description |
|---|---|
MutableSequence[Hashable]
|
List of endpoints. |
Source code in src/holden/report.py
get_endpoints_parallel(item)
¶
Returns the endpoints in item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Parallel | RawParallel
|
parallel object to examine. |
required |
Returns:
| Type | Description |
|---|---|
MutableSequence[Hashable]
|
List of the last node of each path (without duplicates). |
Source code in src/holden/report.py
get_endpoints_serial(item)
¶
Returns the endpoints in item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Serial | RawSerial
|
serial object to examine. |
required |
Returns:
| Type | Description |
|---|---|
MutableSequence[Hashable]
|
List of the last node in |
Source code in src/holden/report.py
get_roots(item)
¶
Returns the roots in any recognized composite form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
composite data structure or raw form to examine. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
if there is no root function for the form of
|
Returns:
| Type | Description |
|---|---|
MutableSequence[Hashable]
|
List of roots. |
Source code in src/holden/report.py
get_roots_adjacency(item)
¶
Returns the roots in item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Adjacency | RawAdjacency
|
adjacency list object to examine. |
required |
Returns:
| Type | Description |
|---|---|
MutableSequence[Hashable]
|
List of roots in the order they appear in |
Source code in src/holden/report.py
get_roots_edges(item)
¶
Returns the roots in item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Edges | RawEdges
|
edge list object to examine. |
required |
Returns:
| Type | Description |
|---|---|
MutableSequence[Hashable]
|
List of roots. |
Source code in src/holden/report.py
get_roots_matrix(item)
¶
Returns the roots in item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Matrix | RawMatrix
|
adjacency matrix object to examine. |
required |
Returns:
| Type | Description |
|---|---|
MutableSequence[Hashable]
|
List of roots. |
Source code in src/holden/report.py
get_roots_parallel(item)
¶
Returns the roots in item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Parallel | RawParallel
|
parallel object to examine. |
required |
Returns:
| Type | Description |
|---|---|
MutableSequence[Hashable]
|
List of the first node of each path (without duplicates). |
Source code in src/holden/report.py
get_roots_serial(item)
¶
Returns the roots in item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Serial | RawSerial
|
serial object to examine. |
required |
Returns:
| Type | Description |
|---|---|
MutableSequence[Hashable]
|
List of the first node in |
Source code in src/holden/report.py
is_adjacency(item)
¶
Returns whether item is an adjacency list.
An adjacency list is a mutable mapping where every value is a set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
instance to test. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether |
Source code in src/holden/check.py
is_composite(item)
¶
Returns whether item is a composite data structure.
A composite data structure is any object (or class) that has add,
delete, merge, and subset methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
instance or class to test. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether |
Source code in src/holden/check.py
is_edge(item)
¶
Returns whether item is an edge.
An edge is an immutable sequence (such as a tuple) of exactly 2 nodes.
Mutable sequences, such as a list, are not edges so that lists can be
used unambiguously for serial and parallel paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
instance to test. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether |
Source code in src/holden/check.py
is_edges(item)
¶
Returns whether item is an edge list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
instance to test. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether |
Source code in src/holden/check.py
is_graph(item)
¶
Returns whether item is a graph.
A graph is a composite data structure that also has connect and
disconnect methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
instance or class to test. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether |
Source code in src/holden/check.py
is_matrix(item)
¶
Returns whether item is an adjacency matrix.
A raw adjacency matrix is a 2-item sequence. The first item is a mutable sequence of equal-length mutable sequences of numbers (the rows). The second item is a mutable sequence of hashable labels for the nodes. The number of rows and the length of every row must match the number of labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
instance to test. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether |
Source code in src/holden/check.py
is_node(item)
¶
Returns whether item is a node.
Any hashable object (or class of hashable objects) can be a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
instance or class to test. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether |
Source code in src/holden/check.py
is_nodes(item)
¶
Returns whether item is a collection of nodes.
A str or bytes is treated as a single node, not a collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
instance to test. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether |
Source code in src/holden/check.py
is_parallel(item)
¶
Returns whether item is a sequence of serial paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
instance to test. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether |
Source code in src/holden/check.py
is_serial(item)
¶
Returns whether item is a serial path.
A serial path is a mutable sequence of nodes. Because a tuple is used for
edges, a tuple cannot be a node in a serial path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
instance to test. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether |
Source code in src/holden/check.py
matrix_to_adjacency(item)
¶
Converts item to an adjacency list.
Any non-zero value in the matrix is treated as an edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Matrix | RawMatrix
|
adjacency matrix to convert to an adjacency list. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the matrix is not square or its labels do not match its size. |
Returns:
| Type | Description |
|---|---|
RawAdjacency
|
Adjacency list derived from |
Source code in src/holden/workshop.py
matrix_to_edges(item)
¶
Converts item to an edge list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Matrix | RawMatrix
|
adjacency matrix to convert to an edge list. |
required |
Returns:
| Type | Description |
|---|---|
RawEdges
|
Edge list derived from |
Source code in src/holden/workshop.py
matrix_to_parallel(item)
¶
Converts item to a parallel structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Matrix | RawMatrix
|
adjacency matrix to convert to a parallel structure. |
required |
Returns:
| Type | Description |
|---|---|
RawParallel
|
Parallel structure derived from |
Source code in src/holden/workshop.py
matrix_to_serial(item)
¶
Converts item to a serial structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Matrix | RawMatrix
|
adjacency matrix to convert to a serial structure. |
required |
Returns:
| Type | Description |
|---|---|
RawSerial
|
Serial structure derived from |
Source code in src/holden/workshop.py
parallel_to_adjacency(item)
¶
Converts item to an adjacency list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Parallel | RawParallel
|
parallel structure to convert to an adjacency list. |
required |
Returns:
| Type | Description |
|---|---|
RawAdjacency
|
Adjacency list derived from |
Source code in src/holden/workshop.py
parallel_to_edges(item)
¶
Converts item to an edge list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Parallel | RawParallel
|
parallel structure to convert to an edge list. |
required |
Returns:
| Type | Description |
|---|---|
RawEdges
|
Edge list derived from |
Source code in src/holden/workshop.py
parallel_to_matrix(item)
¶
Converts item to an adjacency matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Parallel | RawParallel
|
parallel structure to convert to an adjacency matrix. |
required |
Returns:
| Type | Description |
|---|---|
RawMatrix
|
Adjacency matrix derived from |
Source code in src/holden/workshop.py
parallel_to_serial(item)
¶
Converts item to a serial structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Parallel | RawParallel
|
parallel structure to convert to a serial structure. |
required |
Returns:
| Type | Description |
|---|---|
RawSerial
|
Serial structure derived from |
Source code in src/holden/workshop.py
serial_to_adjacency(item)
¶
Converts item to an adjacency list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Serial | RawSerial
|
serial structure to convert to an adjacency list. Each node is
connected to the node that follows it. If |
required |
Returns:
| Type | Description |
|---|---|
RawAdjacency
|
Adjacency list derived from |
Source code in src/holden/workshop.py
serial_to_edges(item)
¶
Converts item to an edge list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Serial | RawSerial
|
serial structure to convert to an edge list. |
required |
Returns:
| Type | Description |
|---|---|
RawEdges
|
Edge list derived from |
Source code in src/holden/workshop.py
serial_to_matrix(item)
¶
Converts item to an adjacency matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Serial | RawSerial
|
serial structure to convert to an adjacency matrix. |
required |
Returns:
| Type | Description |
|---|---|
RawMatrix
|
Adjacency matrix derived from |
Source code in src/holden/workshop.py
serial_to_parallel(item)
¶
Converts item to a parallel structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Serial | RawSerial
|
serial structure to convert to a parallel structure. |
required |
Returns:
| Type | Description |
|---|---|
RawParallel
|
Parallel structure derived from |
Source code in src/holden/workshop.py
set_base(name, value)
¶
Sets default base class for a form of composite data structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of form to set. |
required |
value
|
type[Composite]
|
Composite subclass to use as the base type for the |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
if |
TypeError
|
if |
Source code in src/holden/options.py
to_dot(item, path=None, name='holden', settings=None)
¶
Converts item to a dot format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
composite data structure or raw form to convert to a dot format.
If |
required |
path
|
str | Path | None
|
path to export |
None
|
name
|
str
|
name of |
'holden'
|
settings
|
dict[str, Any] | None
|
any global settings to add to the dot graph. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
str
|
Composite object in graphviz dot format. |
Source code in src/holden/export.py
to_mermaid(item, path=None, name='holden', settings=None)
¶
Converts item to a mermaid format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
composite data structure or raw form to convert to a mermaid
format. If |
required |
path
|
str | Path | None
|
path to export |
None
|
name
|
str
|
name of |
'holden'
|
settings
|
dict[str, Any] | None
|
any global settings to add to the mermaid graph. A nested
|
None
|
Returns:
| Type | Description |
|---|---|
str
|
Composite object in mermaid format. |
Source code in src/holden/export.py
transform(item, output, *, raise_same_error=True)
¶
General transform function that will call appropriate transformer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
composite data structure or raw form to transform. |
required |
output
|
str
|
name of form to transform |
required |
raise_same_error
|
bool | None
|
whether to raise an error if the form of |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if the form of |
Returns:
| Type | Description |
|---|---|
Any
|
Transformed composite data structure in its raw form (for example, a
|
Source code in src/holden/base.py
walk(item, start=None, stop=None)
¶
Returns all paths in any recognized composite form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
composite data structure or raw form in which to find paths. |
required |
start
|
Hashable | Sequence[Hashable] | None
|
node (or list of nodes) to start paths from. If it is |
None
|
stop
|
Hashable | Sequence[Hashable] | None
|
node (or list of nodes) to stop paths at. If it is |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
if there is no walk function for the form of
|
Returns:
| Type | Description |
|---|---|
RawParallel
|
A list of possible paths (each path is a list of nodes) from |
Source code in src/holden/traverse.py
walk_adjacency(item, start, stop, path=None)
¶
Returns all paths in item from start to stop.
A path never visits the same node twice, so cycles cannot cause the search to run forever. Paths are returned in a deterministic order.
The code here is adapted from: https://www.python.org/doc/essays/graphs/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Adjacency | RawAdjacency
|
item in which to find paths. |
required |
start
|
Hashable
|
node to start paths from. |
required |
stop
|
Hashable
|
node to stop paths at. |
required |
path
|
Sequence[Hashable] | None
|
nodes to place in front of every returned path. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
RawParallel
|
A list of possible paths (each path is a list of nodes) from |
Source code in src/holden/traverse.py
walk_edges(item, start, stop, path=None)
¶
Returns all paths in item from start to stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Edges | RawEdges
|
item in which to find paths. |
required |
start
|
Hashable
|
node to start paths from. |
required |
stop
|
Hashable
|
node to stop paths at. |
required |
path
|
Sequence[Hashable] | None
|
nodes to place in front of every returned path. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
RawParallel
|
A list of possible paths (each path is a list of nodes) from |
Source code in src/holden/traverse.py
walk_matrix(item, start, stop, path=None)
¶
Returns all paths in item from start to stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Matrix | RawMatrix
|
item in which to find paths. |
required |
start
|
Hashable
|
node to start paths from. |
required |
stop
|
Hashable
|
node to stop paths at. |
required |
path
|
Sequence[Hashable] | None
|
nodes to place in front of every returned path. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
RawParallel
|
A list of possible paths (each path is a list of nodes) from |
Source code in src/holden/traverse.py
walk_parallel(item, start, stop)
¶
Returns all paths in item from start to stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Parallel | RawParallel
|
item in which to find paths. |
required |
start
|
Hashable
|
node to start paths from. |
required |
stop
|
Hashable
|
node to stop paths at. |
required |
Returns:
| Type | Description |
|---|---|
RawParallel
|
A list of possible paths (each path is a list of nodes) from |
Source code in src/holden/traverse.py
walk_serial(item, start, stop)
¶
Returns all paths in item from start to stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Serial | RawSerial
|
item in which to find paths. |
required |
start
|
Hashable
|
node to start paths from. |
required |
stop
|
Hashable
|
node to stop paths at. |
required |
Returns:
| Type | Description |
|---|---|
RawParallel
|
A list with the single path from the first |