-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Debian ruamel.yaml 0.15: Infinite Recoursion On Setup #9206
Comments
@alalazo @healther @scheibelp @tgamblin after bisecting this problem, I found it was introduced in 63004e3 My system uses: >> ruamel.yaml.version_info
(0, 15, 37) |
Found a Docker reproducer! :) Python2: $ docker run -it debian:stretch
> apt-get update
> apt-get install -y git ca-certificates curl python python-pip procps
> cd /usr/local
> git clone https://github.com/spack/spack.git
> pip install -U ruamel.yaml
> source spack/share/spack/setup-env.sh Python3: $ docker run -it debian:stretch
> apt-get update
> apt-get install -y git ca-certificates curl python3 python3-pip procps
> cd /usr/local
> git clone https://github.com/spack/spack.git
> pip3 install -U ruamel.yaml
> ln -s /usr/bin/python3 /usr/bin/python
> source spack/share/spack/setup-env.sh |
I'm a little puzzled by this. I tried your docker image and I can reproduce the problem, but I don't know why it's not working. I am seeing something kind of like this, where I can't seem to get it to import the |
@tgamblin Still digging. Right now I can confirm what you say. The code fails here: spack/lib/spack/llnl/util/lang.py Line 552 in ff13f39
Because of: >>> import sys
>>> sys.exc_info()
(<class 'AttributeError'>, AttributeError("module 'ruamel.yaml' has no attribute 'Mark'",), <traceback object at 0x7f67edb20e08>) If I look at the >>> import ruamel.yaml
>>> import inspect
>>> inspect.getsourcefile(ruamel.yaml)
'/home/mculpo/venvs/spack/py36/lib/python3.6/site-packages/ruamel/yaml/__init__.py'
I could reproduce on Ubuntu, the trigger seems to be having a site |
I also found this SO but it does not look to me that
Also only a single |
Fact: when it is installed |
By the way, the problem can be trimmed down to something very simple: import inspect
import sys
sys.path.insert(0, '<SpackRoot>/lib/spack/external/')
import ruamel.yaml
print(inspect.getsourcefile(ruamel.yaml))
import six
print(inspect.getsourcefile(six)) Here |
😱 I think I got it. Installing import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('ruamel',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('ruamel', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('ruamel', [os.path.dirname(p)])));m = m or sys.modules.setdefault('ruamel', types.ModuleType('ruamel'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p) According to the docs (emphasis mine):
The creator of I don't really understand the purpose of that but found a couple of posts here and here. Also, there's a comment here that suggests the deletion of the infamous issue 28, where the intentions were clearly explained? To end this: it's by design |
To finish the diagnosis: $ docker run -it debian:stretch
> apt-get update
> apt-get install -y git ca-certificates curl python3 python3-pip procps
> cd /usr/local
> git clone https://github.com/spack/spack.git
> pip3 install -U ruamel.yaml
> rm /usr/local/lib/python2.7/dist-packages/ruamel.yaml-0.15.66-py2.7-nspkg.pth
> rm /usr/local/lib/python2.7/dist-packages/ruamel.ordereddict-0.4.13-py2.7-nspkg.pth
> ln -s /usr/bin/python3 /usr/bin/python
> source spack/share/spack/setup-env.sh works as expected. Probably it's worth opening an issue upstream saying that the package can't be vendored because of the way it is installed. |
It's worth looking into Python's |
@alalazo: do you want to do a hot fix to "undo" the sys.modules modification the |
@tgamblin I'll give it a shot tomorrow. I think we have 2 possible ways to solve the issue:
|
We had a discussion around something similar regarding the installation of python namespace packages (namely |
To add on this. A possible path to explore is to rename #!/usr/bin/env bash
exec /usr/bin/env python -S $0.py "$@" This is needed to invoke
Because of portability issues, this can't be done simply with: #!/usr/bin/env python -S as the shebang argument is "correctly" interpreted on BSD and MacOS, but not on Linux. See here and here for more details. Going this route though we need to solve other issues, like vendoring eval `spack --print-shell-vars sh` as they seem to print to user stdout with this extra indirection. |
fixes spack#9206 fixes spack#9034 A possible solution to spack#9206 is to avoid running `import site` and all the initialization procedures that this entails. This requires us to use `python -S` as an interpreter, instead of plain `python`. Of course things can't be that simple. In Linux (but not in BSD or MacOS) the shebang pass a single string argument to the interpreter. More details on the subject are here: http://sambal.org/2014/02/passing-options-node-shebang-line/ https://github.com/smikes/node/blob/minus-x-switch/doc/Minus-X-Switch-Proposal.md#shebang-interpretation but the bottom line is that this requires us to have a wrapper bash script that invokes the interpreter with the correct option. Finally, as now we are not picking up anything from the 'site', we need to vendor `setuptools` (which was still missing).
Could we just rename the included dirs to make sure they have a distinct name, such as |
@ax3l Changing name to the module would work, if we are fine with this hack. In any case, the entire Python initialization process seems like an hack, so fine with me 😄 |
Will it work? Would we not also have to change the name ruamel.yaml throughput the package? I’d rather not do that if we do not have to... |
That's for sure. 63 matches in 17 files. |
For the record: I have a possible solution in #9261 - I just need to make it work correctly with virtualenv and Python 2.7 to pass the tests in Travis. |
Just to state explicitly another solution that is similar to @ax3l proposal, but doesn't require changes in vendored packages: if we had a different directory layout for dependencies, we could have embedded them into a namespace. At that point we would use, for instance, something like: import spack.externals.six instead of import six in Spack's code. On the plus side we can refer to our vendored packages unambiguously, on the minus side a typo ( |
fixes spack#9206 fixes spack#9034 A possible solution to spack#9206 is to avoid running `import site` and all the initialization procedures that this entails. This requires us to use `python -S` as an interpreter, instead of plain `python`. Of course things can't be that simple. In Linux (but not in BSD or MacOS) the shebang pass a single string argument to the interpreter. More details on the subject are here: http://sambal.org/2014/02/passing-options-node-shebang-line/ https://github.com/smikes/node/blob/minus-x-switch/doc/Minus-X-Switch-Proposal.md#shebang-interpretation but the bottom line is that this requires us to have a wrapper bash script that invokes the interpreter with the correct option. Finally, as now we are not picking up anything from the 'site', we need to vendor `setuptools` (which was still missing).
fixes spack#9206 fixes spack#9034 A possible solution to spack#9206 is to avoid running `import site` and all the initialization procedures that this entails. This requires us to use `python -S` as an interpreter, instead of plain `python`. Of course things can't be that simple. In Linux (but not in BSD or MacOS) the shebang pass a single string argument to the interpreter. More details on the subject are here: http://sambal.org/2014/02/passing-options-node-shebang-line/ https://github.com/smikes/node/blob/minus-x-switch/doc/Minus-X-Switch-Proposal.md#shebang-interpretation but the bottom line is that this requires us to have a wrapper bash script that invokes the interpreter with the correct option. Finally, as now we are not picking up anything from the 'site', we need to vendor `setuptools` (which was still missing).
This is an issue for me as well on Ubuntu, and it has been two weeks since fixes were proposed with no action... I would recommend just picking one fix and implementing it, or reverting the change that introduced this bug. |
@ibaned If you read the thread you'll see that #9261 has been implemented already, and it's waiting for review. As a temporary solution, you can work-around the issue using a virtualenv without |
fixes spack#9206 fixes spack#9034 A possible solution to spack#9206 is to avoid running `import site` and all the initialization procedures that this entails. This requires us to use `python -S` as an interpreter, instead of plain `python`. Of course things can't be that simple. In Linux (but not in BSD or MacOS) the shebang pass a single string argument to the interpreter. More details on the subject are here: http://sambal.org/2014/02/passing-options-node-shebang-line/ https://github.com/smikes/node/blob/minus-x-switch/doc/Minus-X-Switch-Proposal.md#shebang-interpretation but the bottom line is that this requires us to have a wrapper bash script that invokes the interpreter with the correct option. Finally, as now we are not picking up anything from the 'site', we need to vendor `setuptools` (which was still missing).
fixes spack#9206 fixes spack#9034 A possible solution to spack#9206 is to avoid running `import site` and all the initialization procedures that this entails. This requires us to use `python -S` as an interpreter, instead of plain `python`. Of course things can't be that simple. In Linux (but not in BSD or MacOS) the shebang pass a single string argument to the interpreter. More details on the subject are here: http://sambal.org/2014/02/passing-options-node-shebang-line/ https://github.com/smikes/node/blob/minus-x-switch/doc/Minus-X-Switch-Proposal.md#shebang-interpretation but the bottom line is that this requires us to have a wrapper bash script that invokes the interpreter with the correct option. Finally, as now we are not picking up anything from the 'site', we need to vendor `setuptools` (which was still missing).
@scheibelp @tgamblin (Replying to a comment from Peter in #9261)
I'm half-way through having all vendored packages used under the
As a sidenote, while I started with the idea of having everything under the EDIT: going this route consistently is really cumbersome, but if we accept to use namespace |
fixes spack#9206 ruamel.yaml generates a .pth file when installed via pip that has the effect of always preferring the version of this package installed at site scope (effectively preventing us from vendoring it). Here we work around the issue by putting our vendored version of the package under an additional namespace.
fixes spack#9206 ruamel.yaml generates a .pth file when installed via pip that has the effect of always preferring the version of this package installed at site scope (effectively preventing us from vendoring it). This mechanism triggers when implicitly importing the 'site' module when the python interpreter is started. In this PR we explicitly delete references to 'ruamel.yaml' and 'ruamel' in sys.modules, if any, after we set 'sys.path' to search from the directory where we store vendored packages. This ensures that the imports after those statements will be done from our vendored version.
I just submitted a PR that tweaks |
- Delete references to ruamel.yaml at Spack start-up, if they are present - ruamel.yaml generates a .pth file when installed via pip that has the effect of always preferring the version of this package installed at site scope (effectively preventing us from vendoring it). - This mechanism triggers when implicitly importing the 'site' module when the python interpreter is started. In this PR we explicitly delete references to 'ruamel.yaml' and 'ruamel' in sys.modules, if any, after we set 'sys.path' to search from the directory where we store vendored packages. This ensures that the imports after those statements will be done from our vendored version. - See #9206 for further details
Migrated out of #2495 (comment)
Just moving it out not to clutter it further.
I currently get an infinite recursion on a fresh copy of spack
develop
(ccbff6e) and removed$HOME/.spack
directory on. share/spack/setup_env.sh
in Debian 9.5 "stretch".Steps to reproduce the issue
See docker image below. Basically, make sure to have a recent version of
ruamel.yaml
on your system.Error Message
Information on your system
Python 3.6.4 from Anaconda
ruamel.yaml 0.15.37
Debian 9.5
The text was updated successfully, but these errors were encountered: