Commit 5b7c94b9 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Monkey patch astroid: Namespace package handling only...

ZODB Components: Monkey patch astroid: Namespace package handling only considered the top-level module.

This did not work with Shared.DC.ZRDB (Shared.DC namespace package) as it only
considers Shared to be a namespace package and not Shared.DC:
  No name 'ZRDB' in module 'Shared.DC' (no-name-in-module)
parent 42afc8e2
Pipeline #9112 failed with stage
in 0 seconds
...@@ -253,5 +253,27 @@ _what_not_even_god_should_do = [] ...@@ -253,5 +253,27 @@ _what_not_even_god_should_do = []
register_module_extender(MANAGER, 'AccessControl.PermissionRole', register_module_extender(MANAGER, 'AccessControl.PermissionRole',
AccessControl_PermissionRole_transform) AccessControl_PermissionRole_transform)
# Properly search for namespace packages: original astroid (as of 1.3.8) only
# checks at top-level and it doesn't work for Shared.DC.ZRDB (defined in
# Products.ZSQLMethods; Shared and Shared.DC being a namespace package defined
# in Zope2) as Shared (rather than Shared.DC) is considered...
from astroid import modutils
modutils__module_file = modutils._module_file
def _module_file(modpath, path=None):
if modutils.pkg_resources is not None:
i = len(modpath) - 1
while i > 0:
package = '.'.join(modpath[0:i])
if (package in modutils.pkg_resources._namespace_packages and
package in sys.modules):
modpath = modpath[i:]
path = sys.modules[package].__path__
break
i -= 1
return modutils__module_file(modpath, path)
modutils._module_file = _module_file
if sys.modules['isort'] is None: if sys.modules['isort'] is None:
del sys.modules['isort'] del sys.modules['isort']
...@@ -2233,6 +2233,10 @@ class FooBar(ValidationFailed): ...@@ -2233,6 +2233,10 @@ class FooBar(ValidationFailed):
# Transforms for Zope which should ideally be upstream'ed # Transforms for Zope which should ideally be upstream'ed
from AccessControl.PermissionRole import rolesForPermissionOn, PermissionRole, imPermissionRole, _what_not_even_god_should_do # pylint: disable=unused-import from AccessControl.PermissionRole import rolesForPermissionOn, PermissionRole, imPermissionRole, _what_not_even_god_should_do # pylint: disable=unused-import
# Monkey patch of astroid 1.3.8: it raised 'no-name-in-module' because
# Shared.DC was not considered a namespace package
from Shared.DC.ZRDB.Results import Results # pylint: disable=unused-import
""" % (dict(namespace=namespace, """ % (dict(namespace=namespace,
reference1=imported_reference1, reference1=imported_reference1,
module2=imported_module2, module2=imported_module2,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment