[REF] packaging: make odoo a namespaced package

by auto-extending addons path with odoo.addons.__path__.

This patch also introduce
  * an explicit declaration of odoo.addons as a namespace package
    This is necessary because the standard way of declaring namespace
    packages in setup.py does not work as long as odoo/__init__.py
    contains code.
  * a more reliable way to find odoo root path.
This commit is contained in:
=?UTF-8?q?St=C3=A9phane=20Bidoul=20=28ACSONE=29?=
2016-09-30 12:05:49 +02:00
committed by Simon Lejeune
parent ffd3c513ed
commit 389c2ba97b
5 changed files with 11 additions and 3 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env python
__import__('pkg_resources').declare_namespace('odoo.addons')
import odoo
if __name__ == "__main__":
odoo.cli.main()
+1
View File
@@ -14,3 +14,4 @@ This module also conveniently reexports some symbols from odoo.modules.
Importing them from here is deprecated.
"""
__import__('pkg_resources').declare_namespace(__name__)
+6
View File
@@ -141,6 +141,12 @@ def initialize_sys_path():
if base_path not in ad_paths:
ad_paths.append(base_path)
# add odoo.addons.__path__
for ad in __import__('odoo.addons').addons.__path__:
ad = os.path.abspath(ad)
if ad not in ad_paths:
ad_paths.append(ad)
if not hooked:
sys.meta_path.append(AddonsHook())
sys.meta_path.append(OdooHook())
+2 -2
View File
@@ -87,7 +87,7 @@ class configmanager(object):
self.config_file = fname
self._LOGLEVELS = dict([
(getattr(loglevels, 'LOG_%s' % x), getattr(logging, x))
(getattr(loglevels, 'LOG_%s' % x), getattr(logging, x))
for x in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET')
])
@@ -427,7 +427,7 @@ class configmanager(object):
elif isinstance(self.options[arg], basestring) and self.casts[arg].type in optparse.Option.TYPE_CHECKER:
self.options[arg] = optparse.Option.TYPE_CHECKER[self.casts[arg].type](self.casts[arg], arg, self.options[arg])
self.options['root_path'] = os.path.abspath(os.path.expanduser(os.path.expandvars(os.path.dirname(odoo.__file__))))
self.options['root_path'] = os.path.abspath(os.path.expanduser(os.path.expandvars(os.path.join(os.path.dirname(__file__), '..'))))
if not self.options['addons_path'] or self.options['addons_path']=='None':
default_addons = []
base_addons = os.path.join(self.options['root_path'], 'addons')
+1
View File
@@ -1,4 +1,5 @@
#!/usr/bin/env python
__import__('pkg_resources').declare_namespace('odoo.addons')
import odoo
if __name__ == "__main__":