Registry

Registry for programmatic access to autopilot classes and plugins

When possible, rather than importing and using an object directly, access it using the get methods in this module. This makes it possible for plugins to be integrated across the system.

Classes:

REGISTRIES(value)

Types of registries that are currently supported, ie.

Functions:

get(base_class[, class_name, plugins, ast, ...])

Get an autopilot object.

get_names(base_class[, class_name, plugins, ...])

get() but return a list of object names instead of the objects themselves

get_hardware([class_name, plugins, ast])

Get a hardware class by name.

get_task([class_name, plugins, ast])

Get a task class by name.

class REGISTRIES(value)[source]

Bases: str, enum.Enum

Types of registries that are currently supported, ie. the possible values of the first argument of registry.get()

Values are the names of the autopilot classes that are searched for inheriting classes, eg. HARDWARE == "autopilot.hardware.Hardware" for autopilot.Hardware

Attributes:

HARDWARE

TASK

GRADUATION

TRANSFORM

CHILDREN

SOUND

HARDWARE = 'autopilot.hardware.Hardware'
TASK = 'autopilot.tasks.Task'
GRADUATION = 'autopilot.tasks.graduation.Graduation'
TRANSFORM = 'autopilot.transform.transforms.Transform'
CHILDREN = 'autopilot.tasks.children.Child'
SOUND = 'autopilot.stim.sound.sounds.BASE_CLASS'
get(base_class: Union[autopilot.utils.registry.REGISTRIES, str, type], class_name: Optional[str] = None, plugins: bool = True, ast: bool = True, include_base: bool = False) Union[type, List[type]][source]

Get an autopilot object.

Parameters
base_class (REGISTRIES, str, type) – Class to search its subclasses for the indicated object. One of the values in the REGISTRIES enum,

or else one of its keys (eg. 'HARDWARE'). If given a full module.ClassName string (eg. "autopilot.tasks.Task") attempt to get the indicated object. If given an object, use that.

class_name (str, None): Name of class that inherits from base_class that is to be returned.

if None (default), return all found subclasses of base_class

plugins (bool): If True (default), ensure contents of PLUGINDIR are loaded (with import_plugins())

and are included in results. If False, plugins are not explicitly imported, but if any have been imported elsewhere, they will be included anyway because we can’t control all the different ways to subclass in Python.

ast (bool): If True (default), if an imported object isn’t found that matches class_name,

parse the syntax trees of submodules of base_class with utils.common.list_classes() without importing to try and find it. If a match is found, it is imported and checked whether or not it is indeed a subclass of the base_class. if False, do not parse ast trees (will miss any modules that aren’t already imported).

include_base (bool): If False (default), remove the base_class before returning

Returns

Either the requested items, or a list of all the relevant items

get_names(base_class: Union[autopilot.utils.registry.REGISTRIES, str, type], class_name: Optional[str] = None, plugins: bool = True, ast: bool = True, full_name: bool = False) List[str][source]

get() but return a list of object names instead of the objects themselves

See get() for documentation of base arguments.

Note

While technically you can call this function with a class_name, by default [class_name] == get_names(base_class, class_name), but if full_name == False it could be used to get the fully qualified package.module name in a pretty roundabout way.

Parameters

full_name (bool) – if False (default), return just the class name. if True, return the full package.subpackage.module.Class_Name name.

Returns

a list of names

Return type

List[str]

get_hardware(class_name: Optional[str] = None, plugins: bool = True, ast: bool = True) Union[Type[Hardware], List[Type[Hardware]]][source]

Get a hardware class by name.

Alias for registry.get()

Parameters
  • class_name (str) – Name of hardware class to get

  • plugins (bool) – If True (default) ensure plugins are loaded and return from them. see registry.get() for more details about the behavior of this argument

  • ast (bool) – If True (default) parse the syntax tree of all modules within hardware. see registry.get() for more details about the behavior of this argument

Returns

Hardware

get_task(class_name: Optional[str] = None, plugins: bool = True, ast: bool = True) Union[Type[Task], List[Type[Task]]][source]

Get a task class by name.

Alias for registry.get()

Parameters
  • class_name (str) – Name of task class to get

  • plugins (bool) – If True (default) ensure plugins are loaded and return from them. see registry.get() for more details about the behavior of this argument

  • ast (bool) – If True (default) parse the syntax tree of all modules within tasks. see registry.get() for more details about the behavior of this argument

Returns

Task