[FIX] core: importlib find_module is deprecated

As find_module has been deprecated since python 3.4:

https://github.com/python/cpython/blob/05c28b08f6e2fc8782472b026c98a3fdd61a2ba9/Lib/importlib/_bootstrap.py#L1347

and warnings added in python 3.10:

https://github.com/python/cpython/blob/f91dfdf5ff9f68a4b012e1b70ab9997c6dc1542d/Lib/importlib/_bootstrap.py#L764

to respect the PEP-451 specification : https://peps.python.org/pep-0451/

So, override the find_spec() method to display depreaction warnings if
applicable.

X-original-commit: 000ce83492d67febc8b45b902500d57304455d04

---

This commit should have been merged by odoo/odoo#128924, but has been
wrongly ignored.
This oversight has been detected due to a fix inside the `find_spec`
method (odoo/odoo#145800) that couldn't be forward-ported.

This commit is therefore the combinaison of those two patches and the
removal of the depreacted `find_module` method.

closes odoo/odoo#146205

X-original-commit: df63a8aede024f7d4423f80f270a4aa662150e3e
Signed-off-by: Christophe Simonis (chs) <chs@odoo.com>
Co-authored-by: Enric Tobella <etobella@creublanca.es>
Co-authored-by: Christophe Simonis <chs@odoo.com>
This commit is contained in:
Denis Roussel
2023-12-15 01:35:59 +00:00
committed by Christophe Simonis
co-authored by Enric Tobella Christophe Simonis
parent 9f4341d784
commit 1069763b3a
+3 -3
View File
@@ -68,13 +68,13 @@ _logger = logging.getLogger(__name__)
class UpgradeHook(object):
"""Makes the legacy `migrations` package being `odoo.upgrade`"""
def find_module(self, name, path=None):
if re.match(r"^odoo\.addons\.base\.maintenance\.migrations\b", name):
def find_spec(self, fullname, path=None, target=None):
if re.match(r"^odoo\.addons\.base\.maintenance\.migrations\b", fullname):
# We can't trigger a DeprecationWarning in this case.
# In order to be cross-versions, the multi-versions upgrade scripts (0.0.0 scripts),
# the tests, and the common files (utility functions) still needs to import from the
# legacy name.
return self
return importlib.util.spec_from_loader(fullname, self)
def load_module(self, name):
assert name not in sys.modules