StackStorm / st2

StackStorm (aka "IFTTT for Ops") is event-driven automation for auto-remediation, incident responses, troubleshooting, deployments, and more for DevOps and SREs. Includes rules engine, workflow, 160 integration packs with 6000+ actions (see https://exchange.stackstorm.org) and ChatOps. Installer at https://docs.stackstorm.com/install/index.html
https://stackstorm.com/
Apache License 2.0
6.05k stars 745 forks source link

Sharing python code between packs #4355

Open nmaludy opened 6 years ago

nmaludy commented 6 years ago
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:

Kami commented 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.

nmaludy commented 6 years ago

@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?

ghost commented 2 years ago

@LindsayHill @nmaludy I have the same problem and want to ask, what is the way to share python code now?