summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author=?UTF-8?q?St=C3=A9phane=20Bidoul=20=28ACSONE=29?= <stephane.bidoul@acsone.eu>2016-09-27 12:00:44 +0200
committerSimon Lejeune <sle@openerp.com>2016-09-30 12:05:49 +0200
commit389c2ba97ba83dea01949d2a3cad295bd710d9ef (patch)
tree9505bb68bce48a29df770936a25fe49744dbcca9
parentffd3c513ed3178fc87a79b9244ef5967d5ebcdef (diff)
[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.
-rwxr-xr-xodoo-bin2
-rw-r--r--odoo/addons/__init__.py1
-rw-r--r--odoo/modules/module.py6
-rw-r--r--odoo/tools/config.py4
-rw-r--r--setup/odoo1
5 files changed, 11 insertions, 3 deletions
diff --git a/odoo-bin b/odoo-bin
index c417b226d87..b2a0e17ff83 100755
--- a/odoo-bin
+++ b/odoo-bin
@@ -1,6 +1,6 @@
#!/usr/bin/env python
+__import__('pkg_resources').declare_namespace('odoo.addons')
import odoo
if __name__ == "__main__":
odoo.cli.main()
-
diff --git a/odoo/addons/__init__.py b/odoo/addons/__init__.py
index 8f2c331e5c0..d3a3e7e9ba2 100644
--- a/odoo/addons/__init__.py
+++ b/odoo/addons/__init__.py
@@ -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__)
diff --git a/odoo/modules/module.py b/odoo/modules/module.py
index 77fb1433d13..ed4318d9641 100644
--- a/odoo/modules/module.py
+++ b/odoo/modules/module.py
@@ -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())
diff --git a/odoo/tools/config.py b/odoo/tools/config.py
index c400f61531b..07af83e7e3e 100644
--- a/odoo/tools/config.py
+++ b/odoo/tools/config.py
@@ -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')
diff --git a/setup/odoo b/setup/odoo
index 3cd3358ee23..b2a0e17ff83 100644
--- a/setup/odoo
+++ b/setup/odoo
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+__import__('pkg_resources').declare_namespace('odoo.addons')
import odoo
if __name__ == "__main__":