adorn.orchestrator.base module

Vanilla coordinator

class adorn.orchestrator.base.Base(units, alters=None)

Bases: adorn.orchestrator.orchestrator.Orchestrator

Vanilla coordinator between different Unit

Base finds the first Unit specified in the list of Unit that contains a type and delegates the action to the given Unit. Therefore, the earlier a Unit appears in units the higher priority it has in the orchestrator.

Parameters
  • units (List[Unit]) – a collection of collection of types

  • alters (List[Alter]) – a collection of ways to dynamically alter a configuration

Return type

None

unit_dict

a mapping from a type of a Unit to an instance of the Unit

Type

OrderedDict[Type, Unit]

a_get(cls, obj)

Finds all the Alter associated with cls

Note

The list of Alter will be returned, in the order Alter were passed.

Parameters
  • cls (Type) – a type that you want to check or convert the obj into

  • obj (Any) – the object to be type checked or converted into cls

Returns

the classes requested to perform a dynamic alteration

to the obj

Return type

List[Alter]

alter_obj(cls, obj)

Potentially perform a dynamic alteration to an object

Parameters
  • cls (Type) – a type that you want to check or convert the obj into

  • obj (Any) – the object to be type checked or converted into cls

Returns

Either an unaltered obj is returned, when no

:class`~adorn.alter.alter.Alter` in alters contains the given cls and obj, an altered obj is returned when the given cls and obj is contained by an :class`~adorn.alter.alter.Alter` in alters, or a TypeCheckError, when there was an issue performing a dynamic alteration to the obj

Return type

Union[Any, TypeCheckError]

contains(cls)

Check if Type is contained in one of the Unit objects

Parameters

cls (Type) – a type that is being checked to see if it exists in one of the Unit

Returns

if True a Unit

contained in the orchestrator contains the provided type

Return type

bool

from_obj(cls, obj)

Generate an instance of type cls from obj

First, the code gets the Unit that contains cls. Then the instantiating is delegated to the relevant Unit.

Parameters
  • cls (Type) – the type obj would be converted into

  • obj (Any) – an instance to be converted into type cls

Returns

an instance of type cls, that was created from obj

Return type

Any

Raises

obj – obj is a TypeCheckError indicating there was an issue applying a dynamic alteration to obj

get(cls)

Finds the Unit associated with cls

Note

The first Unit will be returned, where order is determined by a Unit location in units.

Parameters

cls (Type) – a type that you want the associated Unit of

Returns

The collection of types that contains cls

Return type

Unit

Raises

TypeCheckErrorcls cannot be represented by any of the Unit contained in the orchestrator

log_instance(cls, obj, instance)

Potentially perform a dynamic logging of instantiated instances

Parameters
  • cls (Type) – a type that you converted the obj into

  • obj (Any) – the object converted into cls

  • instance (Any) – the object created from converting obj into an instance of cls

Return type

None

type_check(cls, obj)

Check if obj can be converted to type of cls

First, the code gets the Unit that contains cls. Then the type checking is delegated to the relevant Unit.

Parameters
  • cls (Type) – the type obj would be converted into

  • obj (Any) – an instance to be converted into type cls

Returns

if None, obj can be converted to an

instance of cls, otherwise an error is returned explaining why an obj cannot be converted to an instance of cls

Return type

Optional[TypeCheckError]

units: List[adorn.unit.unit.Unit]

a collection of collection of types