anod.context

Module Contents

Classes

AnodContext

Anod context.

Attributes

CacheKeyType

logger

anod.context.CacheKeyType
anod.context.logger
exception anod.context.SchedulingError(message: str | list[str], origin: str | None = None, uid: e3.collection.dag.VertexID | None = None, initiators: list[e3.collection.dag.VertexID] | None = None)

Bases: e3.error.E3Error

Exception raised by scheduling algorithm.

class anod.context.AnodContext(spec_repository: e3.anod.loader.AnodSpecRepository, default_env: e3.env.BaseEnv | None = None, reject_duplicates: bool = False)

Anod context.

Variables:
  • repo (e3.anod.loader.AnodSpecRepository) – an anod spec repository

  • tree – a DAG containing the list of possible actions

  • root – root node of the DAG

  • cache (dict[e3.anod.spec.Anod]) – cache of anod instances, indexed by the spec’s name.

  • sources (list[e3.anod.package.SourceBuilder]) – list of available sources in the current context, indexed by the source’s name.

  • default_env – default environment (used to override build=’default’) when simulating a list of action from another machine.

  • plan – maintain a link between a plan line and the generated actions which is useful for setting parameters such as weather or process that are conveyed by the plan and not by the specs

load(name: str, env: e3.env.BaseEnv | None, qualifier: str | None, kind: e3.anod.spec.PRIMITIVE, sandbox: e3.anod.sandbox.SandBox | None = None, source_name: str | None = None) e3.anod.spec.Anod

Load a spec instance.

Parameters:
  • name – spec name

  • env – environment to use for the spec instance

  • qualifier – spec qualifier

  • kind – primitive used for the loaded spec

  • sandbox – is not None bind the anod instances to a sandbox

  • source_name – when the primitive is “source” we create a specific instance for each source package we have to create.

Returns:

a spec instance

add(data: e3.anod.action.Action, *args: e3.anod.action.Action) None

Add node to context tree.

Parameters:
  • data – node data

  • args – list of predecessors

add_decision(decision_class: collections.abc.Callable[Ellipsis, e3.anod.action.Decision], root: e3.anod.action.Action, left: e3.anod.action.Action, right: e3.anod.action.Action) e3.anod.action.Decision

Add a decision node.

This create the following subtree inside the dag:

root --> decision --> left
                  |-> right
Parameters:
  • decision_class – Decision subclass to use

  • root – parent node of the decision node

  • left – left decision (child of Decision node)

  • right – right decision (child of Decision node)

connect(action: e3.anod.action.Action, *args: e3.anod.action.Action) None

Add predecessors to a node.

Parameters:
  • action – parent node

  • args – list of predecessors

__contains__(data: e3.anod.action.Action) bool

Check if a given action is already in the internal DAG.

Parameters:

data – an Action

__getitem__(key: str) e3.anod.action.Action

Retrieve action from the internal DAG based on its key.

Parameters:

key – action uid

Returns:

an Action

predecessors(action: e3.anod.action.Action) list[e3.anod.action.Action]

Retrieve predecessors of a given action.

Parameters:

action – the parent action

Returns:

the predecessor list

Tag the vertex with plan info.

Parameters:
  • vertex_id – ID of the vertex

  • plan_line – corresponding line:linenumber in the plan

  • plan_args – action args after plan execution, taking into account plan context (such as with defaults(XXX):)

add_plan_action(plan_action_env: e3.electrolyt.plan.PlanActionEnv, sandbox: e3.anod.sandbox.SandBox | None = None) e3.anod.action.Action | None

Add an Anod action to the context.

Parameters:
  • plan_action_env – the PlanActionEnv object as returned by PlanContext

  • sandbox – the SandBox object that will be used to run commands

Returns:

the root added action or None if this is not an anod action

add_anod_action(name: str, env: e3.env.BaseEnv, primitive: e3.anod.spec.PRIMITIVE, qualifier: str | None = None, source_packages: list[str] | None = None, upload: bool = True, plan_line: str | None = None, plan_args: dict | None = None, sandbox: e3.anod.sandbox.SandBox | None = None) e3.anod.action.Action

Add an Anod action to the context (internal function).

Note that using add_anod_action should be avoided when possible and replaced by a call to add_plan_action.

Parameters:
  • name – spec name

  • env – context in which to load the spec

  • primitive – spec primitive

  • qualifier – qualifier

  • source_packages – if not empty only create the specified list of source packages and not all source packages defined in the anod specification file

  • upload – if True consider uploading to the store

  • plan_line – corresponding line:linenumber in the plan

  • plan_args – action args after plan execution, taking into account plan context (such as with defaults(XXX):)

  • sandbox – the SandBox object that will be used to run commands

Returns:

the root added action

add_spec(name: str, env: e3.env.BaseEnv, primitive: e3.anod.spec.PRIMITIVE, qualifier: str | None = None, source_packages: list[str] | None = None, expand_build: bool = True, source_name: str | None = None, plan_line: str | None = None, plan_args: dict | None = None, sandbox: e3.anod.sandbox.SandBox | None = None, upload: bool = False, force_download: bool = False) e3.anod.action.Build | e3.anod.action.CreateSources | e3.anod.action.CreateSource | e3.anod.action.Install | e3.anod.action.Test

Expand an anod action into a tree (internal).

Parameters:
  • name – spec name

  • env – context in which to load the spec

  • primitive – spec primitive

  • qualifier – qualifier

  • source_packages – if not empty only create the specified list of source packages and not all source packages defined in the anod specification file

  • expand_build – should build primitive be expanded

  • source_name – source name associated with the source primitive

  • plan_line – corresponding line:linenumber in the plan

  • plan_args – action args after plan execution, taking into account plan context (such as with defaults(XXX):)

  • sandbox – if not None, anod instance are automatically bind to the given sandbox

  • upload – if True consider uploads to the store (sources and binaries)

  • force_download – if True force a download

classmethod decision_error(action: e3.anod.action.Action, decision: e3.anod.action.Decision) NoReturn

Raise SchedulingError.

Parameters:
  • action – action to consider

  • decision – decision to resolve

Raise:

SchedulingError

classmethod always_download_source_resolver(action: e3.anod.action.Action, decision: e3.anod.action.Decision) bool

Force source download when scheduling a plan.

The resolver takes the following decision: * sources are always downloaded * any build that produces a package should be added explicitly

Parameters:
  • action – action to consider

  • decision – decision to resolve

Returns:

True if the action should be scheduled, False otherwise

Raises:

SchedulingError – in case no decision can be taken

classmethod always_create_source_resolver(action: e3.anod.action.Action, decision: e3.anod.action.Decision) bool

Force source creation when scheduling a plan.

schedule(resolver: ResolverType) e3.collection.dag.DAG

Compute a DAG of scheduled actions.

Parameters:

resolver – a function that helps the scheduler resolve cases for which a decision should be taken