Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey!
I develop Scripts and Plugins for several years now and used several different approaches to include external python modules for plugins. All with their own advantages and drawbacks.
The general problem is, that every python file (.py) in the ScriptPlugins directory is automatically interpreted as a script plugin. A naive approach to adding external modules or splitting up you code in different files as plain scripts does not work.
There are several different ways I tried to work around that over the years:
- Put all plugin modules in a directory outside of ScriptPlugins
- Pro: Easy to do with a custom build pipeline
- Con: Not very elegant, may break when users load plugins from a directory specified by environment variables
- Remove file extensions from module files and use some python magic to load them anyway
- Pro: Files can be places inside the plugin directory
- Con: Complex build pipeline necessary, testing is slower because files have to be processed and loaded differently when running in VRED (you want the files to be .py in your dev environment but without .py in VRED)
- Compile python files to .pyc
- Pro: Works with custom modules
- Con: Does not work (out-of-the-box) when you want to ship other python packages
- Export everything to a custom module and load it from somewhere else
- Really depends on the customer infrastructure
- Put all code in one file
- Good look maintaining your 10000 lines of code plugin
I havent found the holy grail yet. What approaches do you prefer? Is there a "best practice" that we can agree on?
Suggestions for improvement:
- Use an "ignore" file where developers can define glob patterns to exclude .py files from being interpreted as Script Plugins.
- Suggest a default Plugin directory structure where custom and externa libraries have fixed folders
Best,
Christopher
Solved! Go to Solution.