Skip to content
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

Out-of-sequence Viewer imports #467

Closed
tkphd opened this issue Oct 7, 2015 · 2 comments
Closed

Out-of-sequence Viewer imports #467

tkphd opened this issue Oct 7, 2015 · 2 comments

Comments

@tkphd
Copy link
Contributor

tkphd commented Oct 7, 2015

The generic Viewer constructor (defined in fipy/viewers/__init__.py) works as advertised -- it imports the first viewer it discovers that can handle the variable's dimensionality -- but perhaps not as expected, i.e. Matplotlib before Mayavi.

In setup.py, the entry_points are ordered (matplotlib, mayavi), and the FiPy documentation implies that MatplotlibViewer should be called unless the problem is 3-D. However, the Viewer() constructor uses pkg_resources.iter_entry_points, which places no guarantees on the order in which entry points are yielded. Its documentation (https://pythonhosted.org/setuptools/pkg_resources.html#entry-points) suggests entry points are yielded in the order they are found on sys.path, which is environment- and system-dependent.

This issue cropped up (and is reproducible) on two Linux machines with FiPy installed in conda environments using Python 2.7. If both matplotlib (1.4.3) and mayavi (4.4.0) are installed using the conda package manager, the mayavi entry point is yielded first:

>>> from fipy import Viewer
>>> from pkg_resources import working_set
>>> for ep in working_set.iter_entry_points(group='fipy.viewers',name=None):
>>>    print ep
mayavi = fipy.viewers.mayaviViewer:MayaviClient
matplotlib = fipy.viewers.matplotlibViewer:MatplotlibViewer

In this order, even 1-D examples open Mayavi to display results. This occurs despite the correct sequence in setup.py and the entry_points.txt it generates:

$ cat FiPy.egg-info/entry_points.txt 

            [fipy.viewers]
            matplotlib = fipy.viewers.matplotlibViewer:MatplotlibViewer
            mayavi = fipy.viewers.mayaviViewer:MayaviClient

On these machines, removing mayavi from the conda environment and re-installing it through the operating system's package manager (i.e., dpkg) resolves the problem, but in the clumsiest possible way.

@tkphd
Copy link
Contributor Author

tkphd commented Oct 7, 2015

Strangely, after purging both Mayavi and Matplotlib from the machine and re-installing through the conda package manager, neither are explicitly listed in the working_set:

>>> print pkg_resources.working_set.entries
[
    '',
    '$ANACONDA/lib/python2.7/site-packages/Cython-0.22.1.egg',
    '$ANACONDA/lib/python2.7/site-packages/scikit_fmm-0.0.6.egg', 
    '$ANACONDA/lib/python2.7/site-packages/mock-1.3.0.egg',
    '$ANACONDA/lib/python2.7/site-packages/nose-1.3.7.egg', 
    '$ANACONDA/lib/python2.7/site-packages/pyparsing-2.0.3.egg', 
    '$ANACONDA/lib/python2.7/site-packages/python_dateutil-2.4.2.egg',     
    '$ANACONDA/lib/python2.7/site-packages/six-1.9.0.egg',
    '$ANACONDA/lib/python2.7/site-packages/funcsigs-0.4.egg', 
    '$ANACONDA/lib/python2.7/site-packages/pbr-1.3.0.egg', 
    '$ANACONDA/lib/python2.7/site-packages/pylsmlib-0.1.egg', 
    '$ANACONDA/lib/python2.7/site-packages/traclinks-0.1.dev20150922.egg',          
    '$ANACONDA/lib/python2.7/site-packages/tqdm-1.0.egg', 
    '~/Downloads/fipy', 
    '$ANACONDA', 
    '$ANACONDA/lib/python27.zip', 
    '$ANACONDA/lib/python2.7', 
    '$ANACONDA/lib/python2.7/plat-linux2', 
    '$ANACONDA/lib/python2.7/lib-tk', 
    '$ANACONDA/lib/python2.7/lib-old', 
    '$ANACONDA/lib/python2.7/lib-dynload', 
    '~/.local/lib/python2.7/site-packages', 
    '$ANACONDA/lib/python2.7/site-packages/Sphinx-1.3.1.egg', 
    '$ANACONDA/lib/python2.7/site-packages/setuptools-18.3.2.egg', 
    '$ANACONDA/lib/python2.7/site-packages', 
    '$ANACONDA/lib/python2.7/site-packages/wx-3.0-gtk2', 
    '$ANACONDA/lib/python2.7/site-packages/IPython/extensions'
]

This suggests that both viewers would be found in the $ANACONDA/lib/python2.7/site-packages path, in which case matplotlib should come before mayavi. Apparently not?

@guyer
Copy link
Member

guyer commented Feb 7, 2016

Fixed by #469

@guyer guyer closed this as completed Feb 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants