Address compat issue for collection loading on py26 (#68219)

* Address compat issue for collection loading on py26

* Move import_module shim to utils for compat across the codebase

* Enable collection tests on py2.6

* Update changelog fragment

* Simplify code using sys.moduls

* Move compat to module_utils/compat/importlib

* Add back errantly deleted newline

* Remove hack comment

Co-Authored-By: Matt Clay <matt@mystile.com>

Co-authored-by: Matt Clay <matt@mystile.com>
This commit is contained in:
Matt Martz 2020-03-13 15:47:34 -05:00
parent 41f6c73be0
commit 26da443fd2
10 changed files with 25 additions and 34 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- Create an ``import_module`` compat util, for use across the codebase, to allow collection loading to work properly on Python26

View file

@ -37,6 +37,7 @@ from ansible.errors import AnsibleError
from ansible.executor.interpreter_discovery import InterpreterDiscoveryRequiredError
from ansible.executor.powershell import module_manifest as ps_manifest
from ansible.module_utils._text import to_bytes, to_text, to_native
from ansible.module_utils.compat.importlib import import_module
from ansible.plugins.loader import module_utils_loader
# Must import strategy and use write_locks from there
# If we import write_locks directly then we end up binding a
@ -53,13 +54,6 @@ try:
except ImportError:
import imp
# HACK: keep Python 2.6 controller tests happy in CI until they're properly split
try:
from importlib import import_module
except ImportError:
import_module = __import__
# if we're on a Python that doesn't have FNFError, redefine it as IOError (since that's what we'll see)
try:
FileNotFoundError

View file

@ -14,15 +14,10 @@ import re
from distutils.version import LooseVersion
# HACK: keep Python 2.6 controller tests happy in CI until they're properly split
try:
from importlib import import_module
except ImportError:
import_module = __import__
from ansible import constants as C
from ansible.errors import AnsibleError
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.module_utils.compat.importlib import import_module
from ansible.plugins.loader import ps_module_utils_loader

View file

@ -0,0 +1,18 @@
# Copyright (c) 2020 Matt Martz <matt@sivel.net>
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import sys
try:
from importlib import import_module
except ImportError:
# importlib.import_module returns the tail
# whereas __import__ returns the head
# compat to work like importlib.import_module
def import_module(name):
__import__(name)
return sys.modules[name]

View file

@ -18,6 +18,7 @@ from collections import defaultdict
from ansible import constants as C
from ansible.errors import AnsibleError
from ansible.module_utils._text import to_bytes, to_text, to_native
from ansible.module_utils.compat.importlib import import_module
from ansible.module_utils.six import string_types
from ansible.parsing.utils.yaml import from_yaml
from ansible.parsing.yaml.loader import AnsibleLoader
@ -32,12 +33,6 @@ try:
except ImportError:
import imp
# HACK: keep Python 2.6 controller tests happy in CI until they're properly split
try:
from importlib import import_module
except ImportError:
import_module = __import__
display = Display()

View file

@ -45,6 +45,7 @@ from ansible.module_utils.six import iteritems, string_types, text_type
from ansible.module_utils._text import to_native, to_text, to_bytes
from ansible.module_utils.common._collections_compat import Sequence, Mapping, MutableMapping
from ansible.module_utils.common.collections import is_sequence
from ansible.module_utils.compat.importlib import import_module
from ansible.plugins.loader import filter_loader, lookup_loader, test_loader
from ansible.template.safe_eval import safe_eval
from ansible.template.template import AnsibleJ2Template
@ -53,12 +54,6 @@ from ansible.utils.collection_loader import AnsibleCollectionRef
from ansible.utils.display import Display
from ansible.utils.unsafe_proxy import wrap_var
# HACK: keep Python 2.6 controller tests happy in CI until they're properly split
try:
from importlib import import_module
except ImportError:
import_module = __import__
display = Display()

View file

@ -13,15 +13,10 @@ import sys
from types import ModuleType
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.module_utils.compat.importlib import import_module
from ansible.module_utils.six import iteritems, string_types, with_metaclass
from ansible.utils.singleton import Singleton
# HACK: keep Python 2.6 controller tests happy in CI until they're properly split
try:
from importlib import import_module
except ImportError:
import_module = __import__
_SYNTHETIC_PACKAGES = {
# these provide fallback package definitions when there are no on-disk paths
'ansible_collections': dict(type='pkg_only', allow_external_subpackages=True),

View file

@ -1,5 +1,4 @@
posix
shippable/posix/group4
shippable/windows/group1
skip/python2.6
windows

View file

@ -1,2 +1 @@
shippable/posix/group1
skip/python2.6

View file

@ -1,2 +1 @@
shippable/posix/group1
skip/python2.6