-
-
Notifications
You must be signed in to change notification settings - Fork 782
Fix for "module 'enum' has no attribute 'IntFlag'" error when using python 3 for pack virtual environments under RHEL / CentOS #4297
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
Conversation
for python runner actions for packs which were created with "use_python3=true" flag. This way we ensure modules and packages from Python3 directory are used before modules and packages from python2.7 site-packages directory. This way we avoid issues such as the one with the enum import.
blag
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider adding some comments in the code about how this situation happens to begin with, not just what the fix is itself. I'm not 100% sure why you are fixing this the way you are, so if I'm 100% off base with the rest of my review, please disregard.
Okay, so the enum library is getting loaded from someplace it shouldn't be. Sounds like it's getting loaded from the system's Python environment. Is that correct? In that case, wouldn't a better fix be to create the pack's virtualenv with the --no-site-packages flag? That's been the default flag for virtualenv for quite some time now.
Or if the pack's requirements.txt includes enum because the pack was developed with Python 2 (meaning pip freeze would include the enum library), but run with Python 3, the site-packages would be searched before the built-in library. But in that case, using the enum; python_version <= 2.7 environment markers from PEP 508 might be a better fix, although it requires pip > 6.0 (which we do anyway, I think) and it requires pack developers to know how to use the option and update their requirements.txt appropriately.
If neither of those are better solutions, this seems reasonable. I do want to point out that this PR does make it impossible for PyPI packages to "override" any of the built-in packages. For instance: if I had a special JSON library that was backwards compatible with the built-in json library it could supply a json module in site-packages so code that imported json would automatically use my library instead of the standard library module. But I can't think of any libraries off the top of my head that do that, and I don't know that we necessarily want to support them if we find ones that do.
So if you think that this is a more reasonable fix for the problem than the solutions above, I approve of it.
Yes, it's getting loaded from system Python 2.7 virtual environment which is used by all the StackStorm components.
Yes, that would be ideal. In fact, it's something I tried to do in the past, but sadly our components cross-depend on Right now Python runner actions and action runner depends on So the easiest way to make pack virtual environments work is to simply inherit all the system dependencies. We do that by manipulating
That's what happens right now - In short - this is a workaround and the main problem is mixing Python 2.7 and 3 dependencies. For the most part that is not an issue since all other libraries we use work with Python 2.7 and 3.x, but All of that should hopefully become less relevant once we fully support Python 3 end to end (then this won't be an issue anymore). |
|
Thanks for the additional explanation - all of that sounds reasonable. |
This pull request includes a fix for the
AttributeError: module 'enum' has no attribute 'IntFlag'error which would appear when using python3 for a pack virtualenv (pack was created usinguse_python3=trueparameter) and running on RHEL / CentOS (see https://forum.stackstorm.com/t/unable-to-run-an-action-implemented-by-python3/217/7 for details).The issue was related to
enumPython package being installed in python2.7 virtual environment. The python runner action script would try to use that package instead ofenummodule from Python 3 stdlib.The fix includes adding
<virtualenv path>/lib/python3.6directory toPYTHONPATHfor Python runner actions. This way we ensure Python 3 stdlib imports always have precedence over other python2.7 site-packages imports.