[GRASS-user] problems compiling grass 7

Glynn Clements glynn at gclements.plus.com
Fri Jun 19 04:03:04 EDT 2009


G. Allegri wrote:

> >> IMHO, this line shouldn't be written in either case. Code wishing to
> >> use the SWIG bindings should explicitly use "import grass.lib". Or,
> >> preferably, import "grass.lib.grass" etc. Loading a dozen libraries
> >> "just in case" is a waste of resources and a potential source of
> >> errors.
> >>
> >> Actually, I see no reason for grass/__init__.py to exist. Code can
> >> just import grass.script or grass.lib or both as required.
> >
> > probably I misunderstand, but if I remove __init__.py, import fails, e.g.
> >
> >>>> import grass.script as grass
> > Traceback (most recent call last):
> >  File "<stdin>", line 1, in <module>
> > ImportError: No module named grass.script
> 
> It fails because "/etc/python/grass" isn't referenced as a package
> without the __init__.py.

Sorry; the __init__.py files for the packages need to exist, but they
shouldn't import the modules/packages. As it stands,
"import grass.lib.grass" will load *all* of the binary modules, and
all of their dependencies (i.e. including GDAL, and all of its
dependencies).

The __init__.py files are supposed to contain an __all__ array listing
the modules and/or sub-packages. This matters on Windows, so that e.g. 
"from grass.lib import *" imports the modules with the correct case in
the event that the filesystem entries have been converted to
upper-case or camel-case.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list