Open nmaludy opened 6 years ago
This can already be done using Python packages (you can publish re-usable code to PyPi / private registry / similar) which can than be shared by various packs and listed inside requirements.txt
file.
I personally prefer that approach over us re-inventing some sharing mechanism. It's standard, everyone from Python world knows how it works (no additional learning curve) and it might result in shared code to be more generic, testable and less coupled to StackStorm (which is not a bad thing).
And in your specific scenario - if the code is custom to your installation, I imagine you can still design the code that way so you can still re-use it some how (e.g. adding config option / variables or similar).
Another thing you can do is to have two packs and in pack 2 you import code from pack 1 (or similar). This is not "officially" supported and we don't do any dependency resolution when installing packs (it's up to you to ensure both packs are installed), but it should work.
@Kami I'll investigate creating a python module. That makes a lot of sense, and i agree is probably more maintainable and scalable.
What would the import statement look like for importing across packs?
@LindsayHill @nmaludy I have the same problem and want to ask, what is the way to share python code now?
SUMMARY
There are some cases where it would be nice to share python code between packs.
For example: I'm writing a pack for the PRTG monitoring tool. I'm coding up a bunch of generic actions using the
python-script
runner. I then have some "custom" stuff i need to do that is specific to the way we have our PRTG instance setup and doesn't make any sense to include that in the public PRTG pack. I would love to be able to reuse all of the code i just wrote in the public PRTG pack within my custom specific pack.ISSUE TYPE
Pick one below and delete the rest: