[MERGE] use an import hook instead of appending to sys.path.
authorVo Minh Thu <vmt@openerp.com>
Wed, 18 Jan 2012 10:45:05 +0000 (11:45 +0100)
committerVo Minh Thu <vmt@openerp.com>
Wed, 18 Jan 2012 10:45:05 +0000 (11:45 +0100)
commit14acff6cc493e75e53e38cf12a8619dbe7e76716
tree941fe218bcaac16d3573c840b65ce236e41943d5
parent7e18a0c31d526e6bf42ed08ebd8a34aa3ca22a76
parent0ed4377cf84eb9f9c8176781daf3811a2e968c7a
[MERGE] use an import hook instead of appending to sys.path.

This replaces sys.path mutation with an import hook. It removes the clash
between our own 'resource' addons and the standard Python resource module. It
provides a transition between our current practice and a cleaner
'openerp.addons' namespace.

The import hook makes it possible to either 'import openerp.addons.hr' or
'import hr' in the addons (ie. both paths are set in sys.modules). When trying
to import an already existing (non-openerp) Python module (e.g. resource), it
will indeed load the Python module and print a warning (to invite you to use
openerp.addons.resource if this is the one you want).

Unfortunately, the import hook doesn't support self-referential imports. E.g.
hr.wizard.xxx can't use 'import hr.yyy' or 'from hr import yyy'. Python will
fail to load hr with cryptic error messages or even a segmentation fault.

Beginning with this patch, 'import openerp.addons.xxx' is the way to go,
'import xxx' is deprecated. Once 'import xxx' support can be removed, we will
probably support pkgutil or setuptool namespaces.

bzr revid: vmt@openerp.com-20120118104505-tns626ga47dwl7it