Skip to content

Commit 8bf06ad

Browse files
sbidoulodony
authored andcommitted
[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 odoo#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 odoo#19517 Fixes odoo#15718
1 parent 5d51950 commit 8bf06ad

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

odoo-bin

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# set server timezone in UTC before time module imported
44
__import__('os').environ['TZ'] = 'UTC'
5-
__import__('pkg_resources').declare_namespace('odoo.addons')
65
import odoo
76

87
if __name__ == "__main__":

odoo/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
""" OpenERP core library."""
55

6+
#----------------------------------------------------------
7+
# odoo must be a namespace package for odoo.addons to become one too
8+
# https://packaging.python.org/guides/packaging-namespace-packages/
9+
#----------------------------------------------------------
10+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
11+
612
#----------------------------------------------------------
713
# Running mode flags (gevent, prefork)
814
#----------------------------------------------------------

odoo/addons/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@
1414
Importing them from here is deprecated.
1515
1616
"""
17-
__import__('pkg_resources').declare_namespace(__name__)
17+
# make odoo.addons a namespace package, while keeping this __init__.py
18+
# present, for python 2 compatibility
19+
# https://packaging.python.org/guides/packaging-namespace-packages/
20+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)

setup/odoo

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# set server timezone in UTC before time module imported
44
__import__('os').environ['TZ'] = 'UTC'
5-
__import__('pkg_resources').declare_namespace('odoo.addons')
65
import odoo
76

87
if __name__ == "__main__":

0 commit comments

Comments
 (0)