symbench / electric-circuits

Electric Circuits Domain for webGME
https://webgme.symbench.org
Apache License 2.0
12 stars 3 forks source link

Importable Python Modules for Python Plugins #130

Open umesh-timalsina opened 3 years ago

umesh-timalsina commented 3 years ago

Python plugins work great as standalone files to run. However, there are cases where you might want to reuse some aspects of the code written for one plugin in another. Currently, we run into this problem, where in multiple analytics could be run on a GMESubTree, but all those analytics do a transformation of that SubTree to PySpice/SPICE format. The resolution we found is via inheritance. Wherein, we first subclass the PluginBase from webgme_bindings and use that class elsewhere for our plugins. Now, we could argue about Composition vs Inheritance all day, but the problem we face is two folds and doesn't resolve either using Composition vs Inheritance .

  1. Since Python plugins are run as standalone files, importing/inheriting common Plugin code is a bit of a pain and relies on some importlib features offered by Python.
  2. Standalone python modules like utils, that don't require webGME specific concepts but could be used in multiple places has to be defined in the class / module file itself. Causing import issues as well.

    A solution could be refactoring the common code into a separate Python package, which could be imported/used freely.