Re: How to properly import a plugin?



Hi Chandan,

On 14/08/17 20:17, Chandan Singh wrote:
Hello,

I was trying to extend one of the Element Plugins but ran into an issue
quite early on. I'm hoping that someone on this list might have some
answers.

I was trying to naively extend a plugin (DpkgElement specifically) like so:

```
from buildstream.plugins.elements.dpkg_build import DpkgElement

# Element implementation for the 'my_dpkg_build' kind.
class MyDpkgElement(DpkgElement):
     pass

Thanks for trying out BuildStream!

By design, elements from the plugins/ module can't be extended in Python code.

The idea is that the plugin should be flexible enough that you can achieve whatever you want just from the .bst files you create, i.e. by writing YAML only. If there's something that the DpkgElement can't do, we should look at improving the DpkgElement plugin itself.

We do have a few elements types which are subclassed (such as the BuildElement base class) but these are implemented in the core 'buildstream' module, not as plugins.

While the above import statement worked successfully when I was trying it
out in a python shell, it doesn't seem to work when it is run as part of
the `bst build` command. Upon doing that, I get an error message like so
(truncated):

```
...

   File "/usr/local/lib/python3.5/dist-packages/pluginbase.py", line 410, in
plugin_import
     fromlist, level)
   File "/src/plugins/elements/bb_dpkg_build.py", line 1, in <module>
     from buildstream.plugins.elements.dpkg_build import DpkgElement
   File "/usr/local/lib/python3.5/dist-packages/pluginbase.py", line 410, in
plugin_import
     fromlist, level)
ImportError: No module named
'pluginbase._internalspace._sp606628c88e67eb4efbaa8e0085714209.elements'
```

It looks like we need to make limitation this clearer in the code & documentation, this error message is nonsense :-) I've opened https://gitlab.com/BuildStream/buildstream/issues/64 to see if we can give a better error.

Sam

--
Sam Thursfield, Codethink Ltd.
Office telephone: +44 161 236 5575


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]