Jump to content
  • Advertisement
Sign in to follow this  

[Python] help designing a plugin system

This topic is 2765 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi folks,

I'm writing a little tool in Python. I'd like to implement a plugin mechanism through which power-users can extend the tool's functionality.

Ideally, I was thinking that when swarm (working title of the tool) is invoked, it would look for python packages under the system- and user-level site-packages directories and each plugin could either be contained in a directory or a zip file.

So the foobar plugin would be found if either of the following files existed:

.../site-packages/swarm/plugins/foobar/plugin.py
.../site-packages/swarm/plugins/foobar.zip/plugin.py

Each plugin.py would export certain hooks expected of a plugin.

The idea behind giving each plugin its own directory or zip file is that the implementation of that plugin could be spread across multiple python modules if the author so-desired. Then the plugins wouldn't step on each others' toes, at least as far as the filesystem is concerned. The idea behind allowing zip files is that you would be able to develop the plugin inside a regular directory and simply zip it up when it's ready for distribution.

Hopefully that sounds semi-reasonable so far. So now the problem: if I'm the author of the foobar plugin and I have a module called utilities(.py/.pyc) that I'd like to include as part of the plugin, I'd like to be able to say "import utilities" in foobar's plugin.py.

As far as I know, this can only be achieved by adding .../site-packages/swarm/plugins/foobar to sys.path. But this somewhat defeats the point of giving each plugin their own directory, since now if another plugin does "import utilities", it might end up with the module provided with foobar.

So my questions are:

1. Is there a way around this?
2. Or is there a better way, entirely?

I'd like to avoid the situation where each plugin author has to do "import swarm.plugins.foobar.utilities", but maybe that's asking for too much?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!