Skip to content

Commit 8dd60cc

Browse files
committed
[IMP] core: make packaging optional
We don't want to add a requirement on packaging since it is not needed to run odoo by default. It should be only useful when defining a more "complex" external dependency (with version or markers) Also solve an issue with google auth adding a filter warning On google-auth import, setuptools will emit a warning in ubuntu noble when importing pkg_resources. This was not visible before the previous commits because another import of pkg_resources was made before enabling the warnings. The pkg_resources import is removed in google-auth >= 1.23.0 but the noble version is 1.5.1 (as it was in jammy) closes odoo#181768 Signed-off-by: Xavier Dollé (xdo) <[email protected]>
1 parent 62766ef commit 8dd60cc

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

odoo/modules/module.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,26 @@
1515
import warnings
1616
from os.path import join as opj, normpath
1717

18-
from packaging.requirements import InvalidRequirement, Requirement
19-
2018
import odoo
2119
import odoo.tools as tools
2220
import odoo.release as release
2321
from odoo.tools.misc import file_path
2422

23+
try:
24+
from packaging.requirements import InvalidRequirement, Requirement
25+
except ImportError:
26+
class InvalidRequirement(Exception):
27+
...
28+
29+
class Requirement:
30+
def __init__(self, pydep):
31+
if not re.fullmatch(r'\w+', pydep): # check that we have no versions or marker in pydep
32+
msg = f"Package `packaging` is required to parse `{pydep}` external dependency and is not installed"
33+
raise Exception(msg)
34+
self.marker = None
35+
self.specifier = None
36+
self.name = pydep
37+
2538

2639
MANIFEST_NAMES = ('__manifest__.py', '__openerp__.py')
2740
README = ['README.rst', 'README.md', 'README.txt']
@@ -467,9 +480,17 @@ def check_python_external_dependency(pydep):
467480
"Ignored external dependency %s because environment markers do not match",
468481
pydep
469482
)
483+
return
470484
try:
471485
version = importlib.metadata.version(requirement.name)
472486
except importlib.metadata.PackageNotFoundError as e:
487+
try:
488+
# keep compatibility with module name but log a warning instead of info
489+
importlib.import_module(pydep)
490+
_logger.warning("python external dependency on '%s' does not appear o be a valid PyPI package. Using a PyPI package name is recommended.", pydep)
491+
return
492+
except ImportError:
493+
pass
473494
msg = f"External dependency {pydep} not installed: {e}"
474495
raise Exception(msg) from e
475496
if requirement.specifier and not requirement.specifier.contains(version):

odoo/netsvc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ def init_logger():
197197
# need to be adapted later but too muchwork for this pr.
198198
warnings.filterwarnings('ignore', r'^datetime.datetime.utcnow\(\) is deprecated and scheduled for removal in a future version.*', category=DeprecationWarning)
199199

200+
# pkg_ressouce is used in google-auth < 1.23.0 (removed in https://github.com/googleapis/google-auth-library-python/pull/596)
201+
# unfortunately, in ubuntu jammy and noble, the google-auth version is 1.5.1
202+
# starting from noble, the default pkg_ressource version emits a warning on import, triggered when importing
203+
# google-auth
204+
warnings.filterwarnings('ignore', r'pkg_resources is deprecated as an API.+', category=DeprecationWarning)
205+
warnings.filterwarnings('ignore', r'Deprecated call to \`pkg_resources.declare_namespace.+', category=DeprecationWarning)
206+
200207
from .tools.translate import resetlocale
201208
resetlocale()
202209

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ num2words==0.5.13 ; python_version >= '3.12'
4141
ofxparse==0.21
4242
openpyxl==3.0.9 ; python_version < '3.12'
4343
openpyxl==3.1.2 ; python_version >= '3.12'
44-
packaging==24.0
4544
passlib==1.7.4 # min version = 1.7.2 (Focal with security backports)
4645
Pillow==9.0.1 ; python_version <= '3.10'
4746
Pillow==9.4.0 ; python_version > '3.10' and python_version < '3.12'

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
'num2words',
4242
'ofxparse',
4343
'openpyxl',
44-
'packaging',
4544
'passlib',
4645
'pillow', # windows binary http://www.lfd.uci.edu/~gohlke/pythonlibs/
4746
'polib',

0 commit comments

Comments
 (0)