Jeff Whitaker wrote: > Ted Drain wrote: >> Could someone point me at a discussion/article that explains the need >> for namespace packages? I'm sure there is some good reason for it but >> on the surface it seems very confusing. I've always thought that the >> purpose of the __init__ file is to define the public interface for a >> package. So when you say: >> >> import foo >> >> You get foo defined in the way it should be. I'm not sure how doing : >> >> import foo.api as foo >> >> is an improvement. Whether the api is defined in __init__.py or >> api.py doesn't seem to matter (though I'm sure this is where I'm not >> understanding things...). I've googled and found references to >> needing to install and distribute sub-packages separately but that >> doesn't really seem to explain why __init__ can't be used in the >> sub-package. Is this primarily a limitation in the distribution and >> setup tools? >> >> Can someone shed some light on this for me? >> >> Ted > > Ted: I was wrong in my previous email - only the __init__.py in the > top-level toolkits directory (now called mpl_toolkits) needs to be > empty. So in the case of basemap, this means that the import has > changed from > > from matplotlib.toolkits.basemap import Basemap > > to > > from mpl_toolkits.basemap import Basemap. > > We don't actually need to stuff things into an api.py file.
But the reason you had to move to an independent mpl_toolkits package (which is a namespace package) is because mpl itself can't be a namespace package, because it has an __init__.py stuffed full of goodies. Right? Not that having an independent mpl_toolkits is a bad thing; it may make sense anyway. I think it simplifies the directory structure of basemap (which seemed needlessly deeply nested), doesn't it? Also, the namespace package constraint is inherent in distributing subpackages as eggs, correct? Without eggs there would be no such constraint. Subpackages would physically land in subdirectories of the main package upon installation. Eric ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace _______________________________________________ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel