Using External Plugins#

When using a plugin which you have created and placed on SIERRA_PLUGIN_PATH, there are some important aspects to be aware of, detailed below.

Modifications to sys.path#

Once a plugin is loaded, the parent directory of the directory it which it was found is added to sys.path. Referring to the example above, that would be $HOME/git/organization. Thus if you need to import modules among the different files in your plugin, all imports must be relative to the parent directory of the plugin. So:

import plugins.myplugin              # valid
import organization.plugins.myplugin # invalid
import myplugin                      # invalid

Entries earlier in sys.path take precedence over those which are later, and plugins external to SIERRA have their modifications earlier in sys.path, you cannot generally have the same plugin directory hierarchy as SIERRA, because the package for e.g., engine will be picked up in your project, and thus something like import engine.argos will fail, because that isn't defined in your module. Concretely, if you have:

$HOME/myproject/engine/simengine/
  - plugin.py
  - __init__.py

and $HOME/ is on SIERRA_PLUGIN_PATH, then SIERRA will fail to start with a rather cryptic error. If you instead have:

$HOME/myproject/plugins/simengine/
- plugin.py
- __init__.py

Then your simengine plugin is accessible as plugins.simengine.

If you really want to do this, you would need to do something like from sierra.core.engine import in __init__.py in the above example, but this isn't recommended, as it will probably have all sorts of subtle consequences.