Re: [matplotlib-devel] Cairo backend prospects
On Mon, 2007-01-08 at 11:24 -0500, Darren Dale wrote: > > > What would need to be done in mpl, and how hard would it be? > > > > The cairo backend can already be used for png, ps, pdf and gtk output so > > I don't think there would be much to do. Mostly, it needs testing - > > running all the mpl examples and checking the output looks OK. > > I had to alter the following lines from backend_gtkcairo, from > > import matplotlib.backends.backend_cairo as be_cairo > from matplotlib.backends.backend_gtk import * > > to > > import backend_cairo as be_cairo > from backend_gtk import * > > in order to prevent the following traceback: > > Traceback (most recent call last): > File "/usr/bin/ipython", line 27, in ? > IPython.Shell.start().mainloop() > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line 1034, in > start > return shell(user_ns = user_ns) > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line 945, in > __init__ > shell_class=MatplotlibMTShell) > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line 622, in > __init__ > on_kill=[mainquit]) > File "/usr/lib64/python2.4/site-packages/IPython/ipmaker.py", line 90, in > make_IPython > embedded=embedded,**kw) > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line 506, in > __init__ > user_ns,b2 = self._matplotlib_config(name,user_ns) > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line 397, in > _matplotlib_config > from matplotlib import backends > File "/usr/lib64/python2.4/site-packages/matplotlib/backends/__init__.py", > line 55, in ? > new_figure_manager, draw_if_interactive, show = pylab_setup() > File "/usr/lib64/python2.4/site-packages/matplotlib/backends/__init__.py", > line 23, in pylab_setup > globals(),locals(),[backend_name]) > > File > "/usr/lib64/python2.4/site-packages/matplotlib/backends/backend_gtkcairo.py", > line 11, in ? > import matplotlib.backends.backend_cairo as be_cairo > AttributeError: 'module' object has no attribute 'backends' The original matplotlib code is correct, you should be editing IPython and correcting their bug! Matplotlib does use a lot of relative imports which I think is bad style. See PEP 8 "Style Guide for Python Code" http://www.python.org/dev/peps/pep-0008/ - Relative imports for intra-package imports are highly discouraged. Always use the absolute package path for all imports. Even now that PEP 328 [7] is fully implemented in Python 2.5, its style of explicit relative imports is actively discouraged; absolute imports are more portable and usually more readable. There was a recent "Coding Guide" thread on this list (which I admit I just skimmed through). Instead of reinventing the wheel, how about stating at the top of CODING_GUIDE that PEP 8 is the default style for matplotlib, and the following notes give in-depth matplotlib examples (or possibly override PEP 8 if necessary). Steve Send instant messages to your online friends http://au.messenger.yahoo.com - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Cairo backend prospects
> "Steve" == Steve Chaplin <[EMAIL PROTECTED]> writes: Steve> Matplotlib does use a lot of relative imports which I think Steve> is bad style. Steve> See PEP 8 "Style Guide for Python Code" Steve> http://www.python.org/dev/peps/pep-0008/ Steve> - Relative imports for intra-package imports are highly Steve> discouraged. Always use the absolute package path for all Steve> imports. Even now that PEP 328 [7] is fully implemented in Steve> Python 2.5, its style of explicit relative imports is Steve> actively discouraged; absolute imports are more portable Steve> and usually more readable. I have never run into a problem with relative imports, though I don't object to removing them. Why are they bad style and what is the danger? Steve> There was a recent "Coding Guide" thread on this list Steve> (which I admit I just skimmed through). Instead of Steve> reinventing the wheel, how about stating at the top of Steve> CODING_GUIDE that PEP 8 is the default style for Steve> matplotlib, and the following notes give in-depth Steve> matplotlib examples (or possibly override PEP 8 if Steve> necessary). Agreed -- I'll update the coding style section to refer to this document, and provide a few comments in line. JDH - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Cairo backend prospects
> I have never run into a problem with relative imports, though I don't > object to removing them. Why are they bad style and what is the danger? I had assumed because it would not be as obvious that the imports were local modules, but might be wrong... Best, Matthew - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Cairo backend prospects
On Wed, 2007-01-10 at 11:55 -0600, John Hunter wrote: > > "Steve" == Steve Chaplin <[EMAIL PROTECTED]> writes: > > Steve> Matplotlib does use a lot of relative imports which I think > Steve> is bad style. > > Steve> See PEP 8 "Style Guide for Python Code" > Steve> http://www.python.org/dev/peps/pep-0008/ > > Steve> - Relative imports for intra-package imports are highly > Steve> discouraged. Always use the absolute package path for all > Steve> imports. Even now that PEP 328 [7] is fully implemented in > Steve> Python 2.5, its style of explicit relative imports is > Steve> actively discouraged; absolute imports are more portable > Steve> and usually more readable. > > I have never run into a problem with relative imports, though I don't > object to removing them. Why are they bad style and what is the danger? Its because you can unwittingly end up with module name clashes. There can be two different modules in two different directories with the same name and you import the wrong module by mistake. It happened to me once when I created a 'calendar.py' module and didn't realize that Python already has a calendar module. Its hard to debug because you get a traceback which makes no sense. >From PEP328 http://www.python.org/dev/peps/pep-0328/ Rationale for Absolute Imports In Python 2.4 and earlier, if you're reading a module located inside a package, it is not clear whether import foo refers to a top-level module or to another module inside the package. As Python's library expands, more and more existing package internal modules suddenly shadow standard library modules by accident. It's a particularly difficult problem inside packages because there's no way to specify which module is meant. To resolve the ambiguity, it is proposed that foo will always be a module or package reachable from sys.path. This is called an absolute import. Steve Send instant messages to your online friends http://au.messenger.yahoo.com - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Cairo backend prospects
On 1/10/07, Steve Chaplin <[EMAIL PROTECTED]> wrote: > On Mon, 2007-01-08 at 11:24 -0500, Darren Dale wrote: > > I had to alter the following lines from backend_gtkcairo, from > > > > import matplotlib.backends.backend_cairo as be_cairo > > from matplotlib.backends.backend_gtk import * > > > > to > > > > import backend_cairo as be_cairo > > from backend_gtk import * > > > > in order to prevent the following traceback: > > > > Traceback (most recent call last): > > File "/usr/bin/ipython", line 27, in ? > > IPython.Shell.start().mainloop() > > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line 1034, in > > start > > return shell(user_ns = user_ns) > > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line 945, in > > __init__ > > shell_class=MatplotlibMTShell) > > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line 622, in > > __init__ > > on_kill=[mainquit]) > > File "/usr/lib64/python2.4/site-packages/IPython/ipmaker.py", line 90, in > > make_IPython > > embedded=embedded,**kw) > > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line 506, in > > __init__ > > user_ns,b2 = self._matplotlib_config(name,user_ns) > > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line 397, in > > _matplotlib_config > > from matplotlib import backends > > File "/usr/lib64/python2.4/site-packages/matplotlib/backends/__init__.py", > > line 55, in ? > > new_figure_manager, draw_if_interactive, show = pylab_setup() > > File "/usr/lib64/python2.4/site-packages/matplotlib/backends/__init__.py", > > line 23, in pylab_setup > > globals(),locals(),[backend_name]) > > > > File > > "/usr/lib64/python2.4/site-packages/matplotlib/backends/backend_gtkcairo.py", > > line 11, in ? > > import matplotlib.backends.backend_cairo as be_cairo > > AttributeError: 'module' object has no attribute 'backends' > > The original matplotlib code is correct, you should be editing IPython > and correcting their bug! Well, I'd be delighted to correct the ipython bug, if only I understood exactly what the problem was... As far as I can see, that code in ipython is simply calling # Initialize matplotlib to interactive mode always import matplotlib from matplotlib import backends inside a function (the _matplotlib_config method). I don't see a bug in that, but if you provide some pointers, I'll be happy to fix any issues that are on ipython's side of the fence. Cheers, f - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel