[PEAK] Question regarding lazyModule

Phillip J. Eby pje at telecommunity.com
Mon Jun 19 08:26:57 EDT 2006


At 01:31 AM 6/19/2006 -0400, Vineet Jain wrote:
>I've migrated my application to use lazy module and it has been working 
>well. I'm trying to figure out why the matplotlib (distributed as an egg) 
>gets imported when I do:
>
>    from peak.util.imports import lazyModule

When pkg_resources is imported, it imports all namespace packages for all 
eggs on sys.path.  If you don't want matplotlib to be imported, you need to 
either use "easy_install -m matplotlib" to make it not be on sys.path by 
default, or else you need to upgrade to the 0.7 development version of 
setuptools ("ez_setup.py setuptools==dev"), which doesn't have this behavior.

Technically, the author of matplotlib is doing a very bad thing by having 
his namespace package *do* things when imported.  A namespace package by 
definition must *not* EVER *do* anything.  Ever. Not just when imported, 
but *ever*, because if somebody installs it with e.g. RPM or bdist_wininst, 
that code isn't even going to be installed!  (When using such packaging 
tools, namespace package __init__.py files are simply not installed, to 
avoid file conflicts between different RPMs or other system packaging 
tools.)  So, the matplotlib distribution is seriously broken in this 
regard.  It shouldn't even be defining functions in a namespace package, 
let alone looking for configuration files or making directories.




More information about the PEAK mailing list