Hi!
If you’re developing custom Python actions and use a lib
directory in actions
,
you may have seen that all imports related to lib
start with from lib.<submodule>
import <something>
or import lib
.
However,
a) your IDE is likely to report this import statement as invalid.
b) (afaik) you can’t test the code outside of StackStorm.
The proposed solution:
- add a
setup.py
file to theactions
directory with the following content:
from setuptools import setup, find_packages
setup(
name='lib',
packages=find_packages('.'),
)
- add this file to
.gitignore
- open a terminal (if you haven’t already ) and go into the
actions
directory - run either
pip install -e ./
orpython setup.py develop
- ATTENTION: if you’re deducing your
requirements.txt
viapip freeze
, exclude the line corresponding tolib
(it’s a line starting with-e
, and containing a reference to the git repo) - maybe restart the IDE if the IDE still reports the
lib
import statements as wrong
Done
Now your lib
imports should “work”, and also your IDE’s autocomplete/inspection features.
Furthermore, you can now test your library code with ease
If you’re wondering what this was all about, check out Python Packaging. It’s straightforward and powerful.
Feedback, questions and comments on this procedure are very welcome.