Skip to content

Commit

Permalink
master.ParentEnumerationMethod: Require matching pkg.__name__
Browse files Browse the repository at this point in the history
When the requested module (e.g. ansible.module_utils.distro)
- is provided by another module *e.g. distro)
- that itself was a package (e.g. distro 1.7.0)

At runtime
- ansible/module_utils/distro/__init__.py executes
- if https://pypi.org/project/distro/ is present, it's loaded as
ansible.module_utils.distro
- otherwise ansible/module_utils/distro/_distro.py is loaded

ParentEnumerationMethod would wrongly use whatever was in
sys.modules['ansible.module_utils.distro]. Instead we should ascend to
the first parent that has fullname == sys.modules[fullname].__name__.
Then descend to the appropriate .py file on disk.

This bug didn't show up before because until distro 1.7.0 (Feb 2022) the
top-level distro module was a module (distro.py) not a package
(distro/__init__.py)

fixes mitogen-hq#906
  • Loading branch information
willmerae committed Mar 25, 2022
1 parent 5b505f5 commit 754a94b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mitogen/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,9 @@ def _find_sane_parent(self, fullname):
return [], None, modpath

pkg = sys.modules.get(pkgname)
name = getattr(pkg, '__name__', None)
path = getattr(pkg, '__path__', None)
if pkg and path:
if pkg and pkgname == name and path:
return pkgname.split('.'), path, modpath

LOG.debug('%r: %r lacks __path__ attribute', self, pkgname)
Expand Down

0 comments on commit 754a94b

Please sign in to comment.