[Fuglu-users] Plugin consisting of multiple files/with external dependency

Oli Schacher oli at fuglu.org
Wed Apr 4 13:54:43 CEST 2018


Hi Andreas

On 04.04.18 09:04, Andreas Scherrer wrote:
> I am trying to write a custom plugin that has an external dependency to
> something that is not available as package, just as a python file.
> 
> For now, I have a file "myplugin.py" that I put into the Fuglu plugins
> folder and I have just copied the dependency there too. That works, but
> it seems wrong that the dependency is in the plugins folder too, even
> though it is not a plugin.
> 
> The question is: is there a "standard way" to handle this? Can I for
> example have a folder for my plugin in the plugins folder and put my
> plugin and its dependency there, so they are at least "isolated" from
> the other plugins?

I guess by dependencies you mean "something that python can import" - in
this case the file has to be somewhere in the python path (sys.path).
Fuglu adds the plugindir to sys.path at startup, this is why it is
working there.

I don't think we've had the use case to import anything from outside the
python path so far. There are workarounds, for example you could add
your dependency directory to the PYTHONPATH environment variable
(haven't tried that, but in theory this should work). You could also
fiddle with sys.path within your plugin and import the dependency
afterwards. However, this is pretty ugly.

That being said, we could allow for multiple comma separated paths in
the "plugindir" configuration option and document it as "plugins and
their dependencies". This would also allow for dependency overrides, so
we could load a different version of a dependency from the one installed
in the system path as the plugindir takes precedence.

If that sounds reasonable I'll patch this in.

> 
> In the "extra-plugins" I found "solr_index" [1] that might have the same
> situation (there is a folder called "solrconfig" in the solr_index
> folder). Is that the way to do it: put the plugin.py in one folder and
> have a subfolder for the dependency?
> 
> [1] https://github.com/fumail/fuglu-extra-plugins/tree/master/solr_index

iirc this folder just contains the configurations to set up the SOLR
index and is not actually used by the plugin.

Some plugins do obviously require additional files (config files etc,
like for example the ratelimit plugin), these are not necessarily in the
python path. Plugins just use a custom configuration option which
defines where to load these files from.


Cheers
Oli



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://fuglu.org/pipermail/fuglu-users_fuglu.org/attachments/20180404/b14454e6/attachment.sig>


More information about the Fuglu-users mailing list