Workaround for illegal package merging in py-matplotlib/py-basemap#1964
Conversation
# Conflicts: # var/spack/repos/builtin/packages/py-basemap/package.py
| # legal Python for "Implicit Namespace Packages": | ||
| # https://www.python.org/dev/peps/pep-0420/ | ||
| # https://github.com/Homebrew/homebrew-python/issues/112 | ||
| # In practice, Python will wee only the basemap version of mpl_toolkits |
|
@lee218llnl can you do a quick test of this? |
|
My only misgiving is that it used to work for me without this fix and now it doesn't, and I still don't know why. I've already ruled out issues related to the version of Matplotlib or Basemap itself. Looking in the Python changelog, I see that starting with Python 3.3, they support namespace packages in a standardized way: I also notice that Python 3.5.2 came into Spack this July; before that, I was using Python 3.5.1. And it did work then (I know it didn't work for my August build). My best guess is that Python 3.5.2 made a change that broke the way Basemap and Matplotlib split packages across directories --- because they do it in a non-standard way. I think the right approach to this is:
|
| # We are not sure if this fix is needed before Python 3.5.2. | ||
| # If it is needed, this test should be changed. | ||
| # See: https://github.com/LLNL/spack/pull/1964 | ||
| if spec.version >= Version('3.5.2'): |
There was a problem hiding this comment.
Won't spec.version refer to basemap's version?
|
Thanks, good catch On Fri, Oct 14, 2016 at 3:13 PM, Gregory Lee [email protected]
|
|
No problem, this looks good to me now. I can merge it if you think it is ready @citibeth. |
|
Yes
|
…pack#1964) * Workaround for illegal package merging in py-matplotlib/py-basemap # Conflicts: # var/spack/repos/builtin/packages/py-basemap/package.py * flake8 * flake8 * Be conservative: only apply the namespace package fix for Python >= 3.5.2 * flake8 * Bug fix
This PR addresses #1948
Matplotlib defines a Python package called
mpl_tools. They put some Python code in that package, so it does not qualify as a Python Implicit Namespace Package ( https://www.python.org/dev/peps/pep-0420/ ).Basemap also defines
mpl_tools, implicitly as an extension of Matplotlib'smpl_tools. The Python packagempl_toolscan now be found twice on$PYTHONPATH: once in thepy-mathplotlibSpack package, and once in thepy-basemapSpack package. This is not legal Python, except for the special case of an implicit namespace package (which does not apply here).Maybe some Python interpreter in the past implicitly "merged" the two
mpl_toolsdirectories together, and it is clear that the authors of Matplotlib/Basemap added Jujitsu in those directories to try to make it happen that way (see the__init__.pyfiles). HOWEVER... it does not currently work with MY versions of Matplotlib (1.5.1), Basemap (1.0.7) and Python (3.5.2) on Spack. On MY system, Python sees only thebasemapversion ofmpl_tools. It then throws an exception when Basemap tries to import things that are in thematplotlibversion ofmpl_tools.The right way to solve this problem is to re-work Basemap and Matplotlib so they don't step on each others' toes that way. It's not clear how this would be done, since this bad design decision is now baked into the library APIs. This problem has been an issue for years without getting fixed; see for example (From 2014): https://github.com/Homebrew/homebrew-python/issues/112
This PR solves the problem by symlinking all of the
mpl_toolsdirectory frommatplotlibintobasemap. It's an un-holy mess, and wouldn't scale if there were additional packages that also implicitly "merge" intompl_tools(there are none that I know of). But it solves the problem at hand, it doesn't break the Spack paridigm, and is better than any other solution I could think of; for example, to create a Spack package that installs Matplotlib and Basemap simultaneously into one Spack prefix.