From 8bf06adc8d78c1bff8dc80ce53d6646e3ad22fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul=20=28ACSONE=29?= Date: Sun, 17 Sep 2017 16:44:02 +0200 Subject: [PATCH] [FIX] namespace packages: move from pkg_resources-style to pkg_util Deprecates the previous pkg_resources-style packages. Our use was not entirely spec compliant, and it broke with setuptools 31. More information in https://github.com/odoo/odoo/pull/15718 Instead, use the pkgutil-style namespace packages. This is spec compliant as long as all other distributions providing odoo.addons use PEP 420 namespace packages (i.e. no __init__.py). So this mechanism fully works on Python 3 only, but does not break anything on Python 2. See also: https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages Closes #19517 Fixes #15718 --- odoo-bin | 1 - odoo/__init__.py | 6 ++++++ odoo/addons/__init__.py | 5 ++++- setup/odoo | 1 - 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/odoo-bin b/odoo-bin index 535ea47f60f..fae9bf233b6 100755 --- a/odoo-bin +++ b/odoo-bin @@ -2,7 +2,6 @@ # set server timezone in UTC before time module imported __import__('os').environ['TZ'] = 'UTC' -__import__('pkg_resources').declare_namespace('odoo.addons') import odoo if __name__ == "__main__": diff --git a/odoo/__init__.py b/odoo/__init__.py index 3c3b14fdadc..2814706b57a 100644 --- a/odoo/__init__.py +++ b/odoo/__init__.py @@ -3,6 +3,12 @@ """ OpenERP core library.""" +#---------------------------------------------------------- +# odoo must be a namespace package for odoo.addons to become one too +# https://packaging.python.org/guides/packaging-namespace-packages/ +#---------------------------------------------------------- +__path__ = __import__('pkgutil').extend_path(__path__, __name__) + #---------------------------------------------------------- # Running mode flags (gevent, prefork) #---------------------------------------------------------- diff --git a/odoo/addons/__init__.py b/odoo/addons/__init__.py index d3a3e7e9ba2..c0058937588 100644 --- a/odoo/addons/__init__.py +++ b/odoo/addons/__init__.py @@ -14,4 +14,7 @@ This module also conveniently reexports some symbols from odoo.modules. Importing them from here is deprecated. """ -__import__('pkg_resources').declare_namespace(__name__) +# make odoo.addons a namespace package, while keeping this __init__.py +# present, for python 2 compatibility +# https://packaging.python.org/guides/packaging-namespace-packages/ +__path__ = __import__('pkgutil').extend_path(__path__, __name__) diff --git a/setup/odoo b/setup/odoo index 535ea47f60f..fae9bf233b6 100644 --- a/setup/odoo +++ b/setup/odoo @@ -2,7 +2,6 @@ # set server timezone in UTC before time module imported __import__('os').environ['TZ'] = 'UTC' -__import__('pkg_resources').declare_namespace('odoo.addons') import odoo if __name__ == "__main__":