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:
|
Types of registries that are currently supported, ie. |
Functions:
|
Get an autopilot object. |
|
|
|
Get a hardware class by name. |
|
Get a task class by name. |
- class REGISTRIES(value)[source]
-
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"forautopilot.HardwareAttributes:
- 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: REGISTRIES | str | type, class_name: str | None = None, plugins: bool = True, ast: bool = True, include_base: bool = False) 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 theREGISTRIESenum, 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 ofbase_class- plugins (bool): If
True(default), ensure contents of PLUGINDIR are loaded (withimport_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 matchesclass_name, parse the syntax trees of submodules of
base_classwithutils.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 thebase_class. ifFalse, do not parse ast trees (will miss any modules that aren’t already imported).
include_base (bool): If
False(default), remove thebase_classbefore returning- base_class (
- Returns:
Either the requested items, or a list of all the relevant items
- get_names(base_class: REGISTRIES | str | type, class_name: str | None = 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 themselvesSee
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 iffull_name == Falseit 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. ifTrue, return the fullpackage.subpackage.module.Class_Namename.- Returns:
a list of names
- Return type:
List[str]
- get_hardware(class_name: str | None = None, plugins: bool = True, ast: bool = True) 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. seeregistry.get()for more details about the behavior of this argumentast (bool) – If
True(default) parse the syntax tree of all modules withinhardware. seeregistry.get()for more details about the behavior of this argument
- Returns:
- get_task(class_name: str | None = None, plugins: bool = True, ast: bool = True) 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. seeregistry.get()for more details about the behavior of this argumentast (bool) – If
True(default) parse the syntax tree of all modules withintasks. seeregistry.get()for more details about the behavior of this argument
- Returns:
Task