Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Forward compatibility] Custom module finders must implement an exec_module() method #72952

Closed
webknjaz opened this issue Dec 11, 2020 · 6 comments
Labels
affects_2.11 bug This issue/PR relates to a bug. files Files category python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.

Comments

@webknjaz
Copy link
Member

SUMMARY

Loader.load_module() has been deprecated since Python 3.4 (https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module) and the development branch of CPython (aka 3.10-dev) has started to actually raise an ImportWarning. Any system that sets the filterwarnings feature to error will fail loudly.

I've first encountered it coming from pkg_resources (pypa/setuptools#2481) and then, I've learned that six has the same problem (benjaminp/six#341). And since we vendor six, we'll encounter it sooner or later.

Besides, our custom collections loader import machinery also doesn't implement exec_module() which generates a similar warning as well.

For context, the original deprecation warning was introduced in CPython via https://bugs.python.org/issue26131 and python/cpython#23469.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

collection loader and the vendored six copy

ANSIBLE VERSION
devel
CONFIGURATION

N/A

OS / ENVIRONMENT

Python 3.10+

STEPS TO REPRODUCE

You should only need Python 3.10-dev (you can get one via pyenv or dnf on Fedora, although I'm not sure if the latter has it up-to-date right now — the relevant PR got merged a week ago and started failing some of my GHA CIs just yesterday) and Ansible (I checked on devel but other supported versions are expected to have the same problem).

$ python3.10 -W error -c 'from ansible.utils.collection_loader._collection_finder import _AnsibleCollectionFinder; _AnsibleCollectionFinder()._install(); import ansible_collections.ansible.builtin'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1026, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1005, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 681, in _load_unlocked
ImportWarning: _AnsibleCollectionRootPkgLoader.exec_module() not found; falling back to load_module()

$ python3.10 -W error -c 'import ansible.module_utils.six.moves'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1026, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1005, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 681, in _load_unlocked
ImportWarning: _SixMetaPathImporter.exec_module() not found; falling back to load_module()
EXPECTED RESULTS

No warning raised.

ACTUAL RESULTS
ImportWarning: _AnsibleCollectionRootPkgLoader.exec_module() not found; falling back to load_module()
ImportWarning: _SixMetaPathImporter.exec_module() not found; falling back to load_module()
@ansibot

This comment has been minimized.

@ansibot ansibot added affects_2.11 bug This issue/PR relates to a bug. files Files category module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback. labels Dec 11, 2020
@webknjaz
Copy link
Member Author

!component -lib/ansible/modules/copy.py
!component +lib/ansible/utils/collection_loader/_collection_finder.py
!component +lib/ansible/module_utils/six/init.py

@ansibot
Copy link
Contributor

ansibot commented Dec 11, 2020

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot removed the module This issue/PR relates to a module. label Dec 11, 2020
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label Dec 15, 2020
@webknjaz
Copy link
Member Author

webknjaz commented Apr 8, 2021

@nitzmahone
Copy link
Member

Yep, I've known this was coming for awhile- one of the other reasons I wanted to get the py2.x controller support stopped ASAP, so we can just reimplement the collection loader as a 3.x-only loader. During the 2.10 changes, I tried to implement it as a native 3.x loader with some 2.x shims, but it turned out to be a lot harder to do it that way without bringing along a lot of the 3.x utility code...

@nitzmahone nitzmahone added this to TODO: proposed items for 2.12 in ansible-core 2.12 via automation Apr 8, 2021
@mattclay
Copy link
Member

I've split this out into 3 separate issues to track the individual changes that are needed.

ansible-core 2.12 automation moved this from TODO: proposed items for 2.12 to Done May 11, 2021
@ansible ansible locked and limited conversation to collaborators Jun 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.11 bug This issue/PR relates to a bug. files Files category python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
No open projects
Development

No branches or pull requests

5 participants