st2 icon indicating copy to clipboard operation
st2 copied to clipboard

[FEATURE] Add a Python 3 runner and pack wide virtualenv option

Open tonybaloney opened this issue 9 years ago • 18 comments

All of our dev effort into APIs, integrations and automation is going on Python 3.

It would be unreasonable to request StackStorm be upgraded to Python 2 so instead I'd like the option to use Python 3 packages and actions within my own packs. That is,

  1. Add a python3 runner to compliment the python runner
  2. Add the ability to configure in a pack which Python version is used with the virtualenv is created for the pack directory.

❤️

tonybaloney avatar Feb 17 '17 01:02 tonybaloney

Not a bad request. We had a recent debate on it too for just general pack support. One of the problems is OS support for the python version. (We still support el6 for instance). I'm curious what the wrapper would need to be 2/3 compliant. Let us get 2.2 out and I'll put some cycles towards investigating this.

bigmstone avatar Feb 17 '17 03:02 bigmstone

Yeah, from a high-level this sounds quite reasonable to me.

There are some edge cases (not all packages work with Python 3, etc.) but users who opt-in to use Python 3 would probably already be aware of that and we will still default to Python 2.

Kami avatar Feb 17 '17 08:02 Kami

+1

bjwschaap avatar Mar 22 '17 12:03 bjwschaap

I wonder if this is something we can do use the pluggable runners framework? Initially write a separate runner that people can install if they wish, which will use python3. Have to figure out all the virtualenv bits, but might be a way to start distributing an experimental runner?

LindsayHill avatar May 09 '17 21:05 LindsayHill

I’m very interested in seeing this and/or testing it.

punkrokk avatar Sep 23 '17 04:09 punkrokk

Hi, Is there any update on this ? Or is there a workaround/hack to use python3 for an extension ?

etz69 avatar Nov 15 '17 09:11 etz69

@etz69 as a workaround, you could have a shell-script action that launches a python3 script. But it won't be able to inherit from the ST2 Action class, or use pack config within the Python code, only in the parameters.

LindsayHill avatar Nov 15 '17 16:11 LindsayHill

@LindsayHill It worked fine. I packed in one directory under actions all the files (python 3 virtualenv, source etc..) and just called via bash by sourcing the right env and just passing the arguments. Thanks !

etz69 avatar Nov 16 '17 08:11 etz69

Good to hear that it worked. It’s not ideal, and I would love to have a proper Python3 runner. But at least it gets you going

LindsayHill avatar Nov 16 '17 16:11 LindsayHill

Hello guys,

+1 for this feature, is there any update on it?

With more and more libraries having Python 3 support (e.g. NAPALM for network automation), it is a bit disappointing to be stuck with Python 2 on StackStorm. The workaround can play well exceptionally, but if one is willing to completely switch to Python 3 (which probably makes sense for new developments with a perspective of multiple years of lifetime), then it is a bit of a showstopper...

akrajewski avatar Nov 21 '17 10:11 akrajewski

+1 for this feature, is there any update on it?

No current plans or work in progress to implement this, but PRs are welcome.

If anyone does start working on this, then their PR would be linked to this issue, and you would be able to track that PR.

LindsayHill avatar Nov 21 '17 14:11 LindsayHill

I’m going to start a WIP PR

tonybaloney avatar Jan 01 '18 02:01 tonybaloney

Python implementation raised. Remaining tasks:

  • [ ] tools/st2-setup-tests is a command-line script to setup the virtual env of a pack with the requirements. it is hard-coded to Python 2.7. This means all pack tests will run as Python 2.x
  • [x] documentation needs to be updated
  • [ ] Update CI for packs (https://github.com/stackstorm-exchange/ci) to read pack metadata and use correct Python version and pass correct flags to other scripts (run pack tests, etc.) if system.python3 attribute is True

tonybaloney avatar Jan 05 '18 11:01 tonybaloney

Added a thing to your TODO - "Update CI for packs (https://github.com/stackstorm-exchange/ci) to read pack metadata and use correct Python version and pass correct flags to other scripts (run pack tests, etc.) if system.python3 attribute is True"

Kami avatar Jan 05 '18 11:01 Kami

Docs update in PR https://github.com/StackStorm/st2docs/pull/677

tonybaloney avatar Jan 05 '18 11:01 tonybaloney

@Kami The system attribute is simply of type "object" from what I saw.

tonybaloney avatar Jan 05 '18 11:01 tonybaloney

@Kami The system attribute is simply of type "object" from what I saw.

Correct, but you can specify a schema and additional allowed keys / properties for an object. We haven't done that yet, because we didn't have an actual use case for that field yet, but now we do.

Something like this should work:

...
'system': {
                'type': 'object',
                'description': 'Specification for the system components and packages '
                               'required for the pack.',
                'default': {}
                'properties': {
                    'python3': {
                        'type': 'boolean',
                        'description': '....',
                        'default': False
                    }
                },
                'additionalProperties': True
            }
....

Kami avatar Jan 05 '18 12:01 Kami

Python 3 action support added into 2.8dev https://github.com/StackStorm/st2/pull/4149

LindsayHill avatar Jun 19 '18 20:06 LindsayHill