openstb.simulator.plugin.loader
Functions:
| Name | Description |
|---|---|
load_plugin |
Load a plugin and create an instance of it. |
load_plugin_class |
Load a plugin class. |
register_loader |
Decorator to register a plugin loading function. |
registered_plugins |
List registered plugins. |
load_plugin
load_plugin(group, plugin_spec)
Load a plugin and create an instance of it.
In general, you should call one of the more specific functions in this module to load the particular type of plugin you want.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
str
|
The name of the entry point group that the plugin belongs to, e.g., "openstb.simulator.trajectory". |
required |
plugin_spec
|
(dict, Plugin)
|
If a dictionary, this specifies the name and parameters of the plugin to load. Otherwise, it is assumed to be an instance of a compatible class and is returned unchanged. |
required |
Returns:
| Type | Description |
|---|---|
Plugin
|
|
Source code in openstb/simulator/plugin/loader.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
load_plugin_class
load_plugin_class(group, name)
Load a plugin class.
Three formats are supported for the name of the plugin:
-
The name of an installed plugin registered under the entry point group.
-
A reference to an attribute name and the importable module it belongs to. The name "FromDisk:my_plugins.trajectories" effectively corresponds to this function being
from my_plugins.trajectories import FromDisk; return FromDisk. -
The name of an attribute in a Python file and the path of the file. The name "FromDisk:/path/to/my_plugins.py" results in the function dynamically importing the
/path/to/my_plugins.pyfile and returning theFromDiskattribute from it. Note that relative paths will be resolved relative to the current working directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
str
|
The name of the entry point group that the plugin belongs to, e.g., "openstb.simulator.trajectory". |
required |
name
|
str
|
The user-specified name of the plugin. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
plugin |
class
|
|
Source code in openstb/simulator/plugin/loader.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
register_loader
register_loader(__loader: F_PluginLoader[T_Plugin]) -> F_PluginLoader[T_Plugin]
register_loader(__loader=None, *, docstring=None, name=None)
Decorator to register a plugin loading function.
This should be applied to a function which takes a
openstb.simulator.types.PluginOrSpec parameter and returns a plugin instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docstring
|
Boolean
|
Whether to set a docstring for the class. If None (the default), then a docstring will only be set if one does not already exist. |
None
|
name
|
str
|
The name of the plugin type to use in the docstring. If not specified, the class name will be used. |
None
|
Source code in openstb/simulator/plugin/loader.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
registered_plugins
registered_plugins(group, load=False)
List registered plugins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
str
|
The name of the entry point group to list plugins for, e.g., "openstb.simulator.trajectory". |
required |
load
|
Boolean
|
If True, include the loaded plugins in the return. If False, only report the name and source of each plugin. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
installed |
list
|
A list of (name, src) tuples where name is the name the plugin is registered as
and src is the reference to the module and class implementing the plugin. If
|
Source code in openstb/simulator/plugin/loader.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |