Skip to content

Commit

Permalink
[FIX] namespace packages: move from pkg_resources-style to pkg_util
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sbidoul authored and odony committed Sep 18, 2017
1 parent 5d51950 commit 8bf06ad
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion odoo-bin
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
6 changes: 6 additions & 0 deletions odoo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#----------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion odoo/addons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
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__)
1 change: 0 additions & 1 deletion setup/odoo
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit 8bf06ad

Please sign in to comment.