ipython and matplotlib-0.83

John, is this due to the recent __init__ patch in

    > matplotlib? I haven't committed any of that, as I am in
    > the middle of the cvs->svn transition at ipython's site,
    > and without net access at home (moving), so I'm sort of
    > crippled right now.

    > I tried to fix backends/__init__.py to work with existing
    > ipython distributions. But I only tested calling plot
    > commands from ipython and not run. The latter exposes the
    > bug. I think this should be fixed on the matplotlib end,
    > since I don't want to require everyone to always have the
    > latest ipython. I'll take a look and see if I can figure
    > out a workaround.

The problem appears to be that the draw_if_interactive function pylab
gets by calling pylab_setup is not the same as the
backends.draw_if_interactive. Thus the "called" flag you set in
Shell.py

        backend.draw_if_interactive = flag_calls(backend.draw_if_interactive)

is not set on the pylab.draw_if_interactive. I tried to fix this by
modifying backends_init.py as follows, so that both functions would be
the same (in CVS).

  def pylab_setup():
      'return new_figure_manager, draw_if_interactive and show for pylab'
      # Import the requested backend into a generic module object
      if pylabcache is not None: return pylabcache
      backend_name = 'backend_'+backend.lower()
      backend_mod = __import__('matplotlib.backends.'+backend_name,
      ..snip..
      return new_figure_manager, draw_if_interactive, show

  # a hack to keep old versions of ipython working with mpl after bug
  # fix #1209354
  pylabcache = None
  if 'IPython.Shell' in sys.modules:
      pylabcache = pylab_setup()
      new_figure_manager, draw_if_interactive, show = pylabcache

Thus the symbols new_figure_manager, draw_if_interactive, show are
still defined at module level when pylab is imported from ipython.

pylab gets it draw_if_interactive symbol with

  from backends import pylab_setup
  new_figure_manager, draw_if_interactive, show = pylab_setup()

The goal is for backends.draw_if_interactive and
pylab.draw_if_interactive to be the same symbol (so Shell.py will not
fail)

But it is clear that they are not the same function

In [1]: import matplotlib.backends

In [2]: matplotlib.backends.draw_if_interactive.jdh = 'test'

In [3]: draw_if_interactive.jdh

···

------------------------------------------------------------
Traceback (most recent call last):
  File "<console>", line 1, in ?
AttributeError: 'function' object has no attribute 'jdh'

What am I missing? I verified that pylab_setup is returning
pylabcache when run from ipython, and yet the draw_if_interactive
function is not shared??

JDH

John Hunter wrote:

The goal is for backends.draw_if_interactive and
pylab.draw_if_interactive to be the same symbol (so Shell.py will not
fail)

But it is clear that they are not the same function

Strange. Sorry that I can't work with CVS today, I have a few urgent things to take care of here. Just some suggestions:

start sprinkling

print '*** object id for draw_if_interactive:',id(draw_if_interactive)

calls everywhere across that chain call. That id() call should always give the exact same value, if the draw_if_interactive name is pointing to the same object. At some point, this should show where a new object is being created (with a new id).

Sorry not to be of more help right now,

f