Base classes for a project.
Contents
Library: stores Genre classes in the hierarchy of their subclasses.
library: the Library that Genre subclasses are added to.
Genre: base class for every class that is stored in the library.
Idea: settings of a project, with properties for building its workflow.
Vertex: base class for nodes in a project workflow.
Criteria: scores the results of a workflow.
Report: base class for reports that describe a project.
Criteria(contents=None, parameters=dict())
dataclass
¶
Bases: Genre, ABC
Scores the results of a workflow.
Criteria can be used directly, by wrapping a tool, or subclassed to
override score. A Contest keeps the result with the highest score, and
a Benchmark stops when test passes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
str | Callable[..., Any] | None
|
tool that scores a result: a callable or the import path of
one. Defaults to |
None
|
parameters
|
GenericDict
|
keyword arguments passed to the tool. Defaults to an empty
|
dict()
|
parameters = dataclasses.field(default_factory=dict)
class-attribute
instance-attribute
¶
Public Methods
score(item)
¶
Returns the score of item. Higher scores are better.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
data or object to score. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
if there is no tool in |
Returns:
| Type | Description |
|---|---|
Any
|
The result of calling the tool with |
Source code in src/chrisjen/base.py
test(item)
¶
Returns whether item meets the criteria (has a true score).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
data or object to test. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the score of |
Genre()
dataclass
¶
Bases: ABC
Stores itself in the project library.
Every subclass of Genre is added to library when it is defined. A
subclass that lists abc.ABC among its bases is abstract: it forms a new
layer of Library.contents. Any other subclass is stored in the layer of
its nearest abstract ancestor.
Idea()
dataclass
¶
Bases: Settings, Genre
Loads and stores configuration settings.
Idea is a subclass of the Settings class in the bobbie repo. See its documentation for information about its functionality. https://withprecedent.github.io/bobbie/
Idea adds properties (workers, steps, techniques, designs,
criteria, and parameters) and a get_settings method that read the
parts of a chrisjen workflow from the settings. Its fields (contents,
default_factory, and name) are those of bobbie.Settings.
criteria
property
¶
Returns the criteria of the workers and steps in the settings.
In each worker section, a "criterion" setting is the criterion of the
worker and a "{name}_criterion" setting is the criterion of name.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A |
designs
property
¶
Returns the designs of the workers in the settings.
In each worker section, a "design" setting is the design of the worker
and a "{name}_design" setting is the design of name. A worker without
a design uses options._DEFAULT_DESIGN.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A |
parameters
property
¶
Returns the parameters sections of the settings.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
A |
steps
property
¶
Returns the steps of the workers in the settings.
In each worker section, a "steps" setting lists the steps of the worker
and a "{name}_steps" setting lists the steps of name. A "workers" or
"{name}_workers" setting (as in the project section) lists steps the
same way.
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
A |
techniques
property
¶
Returns the techniques of the workers and steps in the settings.
In each worker section, a "techniques" setting lists the techniques of
the worker and a "{name}_techniques" setting lists the techniques of
name (usually a step).
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
A |
workers
property
¶
Returns the worker sections of the settings.
The project section (whose name ends in "_project") is included under the name of the project, the part before "_project", so its settings are found by the other properties as well.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
A |
get_settings(name, keys)
¶
Returns the settings in keys that belong to name.
A setting belongs to name if it is in the section for name or if
it is named "{name}_{key}" in any worker section. This is how settings
such as "max_iterations" reach the class that name is built from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of a worker, step, or technique. |
required |
keys
|
Sequence[str]
|
names of the settings to look for. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A |
Source code in src/chrisjen/base.py
Library(contents=dict())
dataclass
¶
Bases: MutableMapping[str, Any]
Stores Genre classes in the hierarchy of their subclasses.
contents is a nested dict that follows the subclasses of Genre. An
abstract class (one that lists abc.ABC among its bases) is only a key: its
value is a new layer for its subclasses, and the class itself is not
stored. Any other class is stored, under its name, in the layer of its
nearest abstract ancestor (or at the top level, if it has none). For
example, Vertex, Step, and Worker are abstract, so if Scaler is a
subclass of Technique and Scale is a subclass of Step:
{
'vertex': {
'technique': Technique,
'scaler': Scaler,
'step': {'scale': Scale},
'worker': {'flow': Flow, 'contest': Contest},
}
}
A class can also be added under another name (NullVertex is also stored
as "none"). all is a flat dict of every stored class, and borrow
finds classes by name.
Attributes:
| Name | Type | Description |
|---|---|---|
contents |
Layer
|
nested dictionary of |
all
property
¶
Returns a flattened dictionary of all classes in the library.
contents = dataclasses.field(default_factory=dict)
class-attribute
instance-attribute
¶
Properties
genres
property
¶
Returns names of the genres (abstract classes) at every level.
plurals
property
¶
Returns a list of pluralized names of genres.
add(item, name=None)
¶
Adds item to its place in contents.
An abstract class (one that lists abc.ABC among its bases) adds a
new, empty layer named for it, unless that layer already exists. Any
other class is stored under its name in the layer of its nearest
abstract ancestor. A direct subclass of Genre is at the top level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
type
|
|
required |
name
|
str | None
|
name to store |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
if |
Source code in src/chrisjen/base.py
borrow(names, genre=None)
¶
Returns the first class found that is named in names.
Listing more than one name allows a specific class to be used if it
exists, with a general one as a fallback. For example, a worker named
"analyst" can use an Analyst class, if there is one, and otherwise
the class of its design.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
str | Sequence[str]
|
name or names of classes, in the order to look for them. |
required |
genre
|
str | type[Genre] | None
|
name of the genre (or the abstract class) to look in.
Defaults to |
None
|
Raises:
| Type | Description |
|---|---|
KeyError
|
if none of |
Returns:
| Type | Description |
|---|---|
type[Genre]
|
The first class found. |
Source code in src/chrisjen/base.py
classify(item)
¶
Returns the genre (abstract base class) that item is in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
str | type[Genre] | Genre
|
|
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Returns:
| Type | Description |
|---|---|
str
|
The name of the genre to which |
Source code in src/chrisjen/base.py
delete(item)
¶
Deletes the class or layer named item, wherever it is.
Deleting a layer deletes everything in it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
str
|
name of a class or a layer. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
if |
Source code in src/chrisjen/base.py
get_genre(item)
¶
Returns the layer of contents formed by a genre abstract class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
str | type[Genre]
|
abstract |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
if there is no layer for |
Returns:
| Type | Description |
|---|---|
Layer
|
The nested |
Source code in src/chrisjen/base.py
Report(contents=None)
dataclass
¶
Bases: Genre, ABC
Describes a project after it is applied.
Project.apply calls generate after each run of the workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
Any
|
data for the report. Defaults to |
None
|
contents = dataclasses.field(default=None)
class-attribute
instance-attribute
¶
Required Methods
Vertex(contents=None, name=None, parameters=dict())
dataclass
¶
Bases: Labeled, Node, Genre, ABC
Base class for nodes in a chrisjen workflow.
Vertexes are hashed and compared by name, so a str equal to the name of
a node can be used in its place. Each vertex is applied to an item with
apply and can be built from a project's settings with build. The
subclasses are in the nodes and workers modules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
Any | None
|
item(s) to be applied to the |
None
|
name
|
str | None
|
name used to refer to the node in a workflow. Defaults to |
None
|
parameters
|
GenericDict
|
keyword arguments passed to |
dict()
|
parameters = dataclasses.field(default_factory=dict)
class-attribute
instance-attribute
¶
Class Methods
apply(item, **kwargs)
¶
Applies this node to item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
data or object (often the result of the previous node) to which this node should be applied. |
required |
**kwargs
|
Any
|
keyword arguments for |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The result of applying this node to |
Source code in src/chrisjen/base.py
build(name, project, parameters=None, **kwargs)
classmethod
¶
Builds an instance named name from the settings of project.
Settings that belong to name (see Idea.get_settings) and match a
field of the class are passed to the constructor, so a setting such as
"max_iterations" reaches the class that uses it. The "{name}_parameters"
section of the settings is added to the default parameters of the
class. Subclasses can override this method to build themselves
differently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the node. |
required |
project
|
Project
|
the project the node belongs to. |
required |
parameters
|
GenericDict | None
|
more parameters, which take precedence over those in
the settings. Defaults to |
None
|
**kwargs
|
Any
|
other arguments for the constructor, which take precedence over the settings. |
{}
|
Returns:
| Type | Description |
|---|---|
Vertex
|
The built instance. |
Source code in src/chrisjen/base.py
implement(item, **kwargs)
abstractmethod
¶
Applies contents to item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
data or object to which |
required |
**kwargs
|
Any
|
parameters for the implementation. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The result of applying |