Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

packs - ability to share code between actions/ and sensors/ #3490

Closed
nmaludy opened this issue Jun 19, 2017 · 3 comments · Fixed by #3658
Closed

packs - ability to share code between actions/ and sensors/ #3490

nmaludy opened this issue Jun 19, 2017 · 3 comments · Fixed by #3658

Comments

@nmaludy
Copy link
Member

nmaludy commented Jun 19, 2017

There has been some discussion on Slack about the following so i decided to create an issue to track requirements and investigations.

Use Case:

  • There is a pack deployed that has some code in actions/lib/common.py that implements some common functionality
  • Within this pack an action exists actions/example_action.py that utilizes the common code in actions/lib/common.py
  • Within the same pack a sensor exists in sensors/example_sensor.py that also needs to utilize the common code in actions/lib/common.py

Problem:

  • This common code is not available to both the sensor and action at the same time within the same pack

Ideas:

  1. Place the code in some "common" area (/opt/stackstorm/common/xxx) and setup symlinks to the code in both the /opt/stackstorm/packs/<pack_name>/actions/lib and /opt/stackstorm/packs/<pack_name>/sensors/lib directories.
  2. Place the code into a "common" python module that can be installed via pip using requirements.txt (this can support both public modules and installing from private git repos)
  3. Something else (may allowing packs to access code from other packs?)
@cognifloyd
Copy link
Member

cognifloyd commented Jun 19, 2017

Here's what I'm doing right now:

/opt/stackstorm/packs/<pack>/
  common_lib/
      __init__.py
      common_foobar.py
  actions/
    lib/ <= directory
      __init__.py        <= symlink to ../../common_lib/__init__.py
      common_foobar.py   <= symlink to ../../common_lib/common_foobar.py
      action.py          <= not shared, not a symlink
  sensor/
    lib/ <= directory
      __init__.py        <= symlink to ../../common_lib/__init__.py
      common_foobar.py   <= symlink to ../../common_lib/common_foobar.py
      action.py          <= not shared, not a symlink

edit: swapped out the / directory for /common_lib to make it clearer

@andrew-regan
Copy link
Contributor

Also see #2220

@cognifloyd
Copy link
Member

I looked into using relative links in requirements.txt to grab some lib folder in a different directory, but pip doesn't support relative links in any sane fashion right now (see pypa/pip#328 which is fixed partially by pypa/pip#4208, but is not in any released version yet).
It looks like, if the common_lib dir (or whatever you choose to call it) is included in requirements.txt as ./common_lib (not ./common_lib#egg....) then it should work (I haven't tested yet, I'm just noting my thoughts).
I wonder, is it possible for pip to use a custom URI scheme? Maybe we could register st2:// as a custom scheme, and then we add requirements using st2://<pack>/dir/in/pack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants