Remove unused module imports

pull/921/head
Alex Willmer 3 years ago
parent 566d75d82f
commit 18c89de5a9

@ -7,7 +7,6 @@ import signal
import sys
import ci_lib
from ci_lib import run
TESTS_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible')
@ -40,10 +39,10 @@ with ci_lib.Fold('job_setup'):
os.chdir(TESTS_DIR)
os.chmod('../data/docker/mitogen__has_sudo_pubkey.key', int('0600', 7))
run("mkdir %s", HOSTS_DIR)
ci_lib.run("mkdir %s", HOSTS_DIR)
for path in glob.glob(TESTS_DIR + '/hosts/*'):
if not path.endswith('default.hosts'):
run("ln -s %s %s", path, HOSTS_DIR)
ci_lib.run("ln -s %s %s", path, HOSTS_DIR)
inventory_path = os.path.join(HOSTS_DIR, 'target')
with open(inventory_path, 'w') as fp:
@ -63,14 +62,14 @@ with ci_lib.Fold('job_setup'):
ci_lib.dump_file(inventory_path)
if not ci_lib.exists_in_path('sshpass'):
run("sudo apt-get update")
run("sudo apt-get install -y sshpass")
ci_lib.run("sudo apt-get update")
ci_lib.run("sudo apt-get install -y sshpass")
with ci_lib.Fold('ansible'):
playbook = os.environ.get('PLAYBOOK', 'all.yml')
try:
run('./run_ansible_playbook.py %s -i "%s" %s',
ci_lib.run('./run_ansible_playbook.py %s -i "%s" %s',
playbook, HOSTS_DIR, ' '.join(sys.argv[1:]))
except:
pause_if_interactive()

@ -1,4 +1,3 @@
from __future__ import absolute_import
from __future__ import print_function

@ -6,7 +6,6 @@ import subprocess
import sys
import ci_lib
from ci_lib import run
TESTS_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible')
@ -52,11 +51,11 @@ with ci_lib.Fold('machine_prep'):
if os.path.expanduser('~mitogen__user1') == '~mitogen__user1':
os.chdir(IMAGE_PREP_DIR)
run("ansible-playbook -c local -i localhost, _user_accounts.yml")
ci_lib.run("ansible-playbook -c local -i localhost, _user_accounts.yml")
with ci_lib.Fold('ansible'):
os.chdir(TESTS_DIR)
playbook = os.environ.get('PLAYBOOK', 'all.yml')
run('./run_ansible_playbook.py %s -l target %s',
ci_lib.run('./run_ansible_playbook.py %s -l target %s',
playbook, ' '.join(sys.argv[1:]))

@ -40,10 +40,8 @@ import time
import ansible.constants as C
import ansible.errors
import ansible.plugins.connection
import ansible.utils.shlex
import mitogen.core
import mitogen.fork
import mitogen.utils
import ansible_mitogen.mixins

@ -32,6 +32,8 @@ Stable names for PluginLoader instances across Ansible versions.
from __future__ import absolute_import
import ansible.errors
import ansible_mitogen.utils
__all__ = [

@ -36,8 +36,8 @@ import mitogen.utils
try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()
import ansible.utils.display
display = ansible.utils.display.Display()
#: The process name set via :func:`set_process_name`.

@ -43,11 +43,10 @@ import os
import random
import re
from ansible.executor import module_common
from ansible.collections.list import list_collection_dirs
import ansible.collections.list
import ansible.errors
import ansible.module_utils
import ansible.release
import ansible.executor.module_common
import mitogen.core
import mitogen.select
@ -192,7 +191,7 @@ class BinaryPlanner(Planner):
@classmethod
def detect(cls, path, source):
return module_common._is_binary(source)
return ansible.executor.module_common._is_binary(source)
def get_push_files(self):
return [mitogen.core.to_text(self._inv.module_path)]
@ -269,7 +268,7 @@ class JsonArgsPlanner(ScriptPlanner):
@classmethod
def detect(cls, path, source):
return module_common.REPLACER_JSONARGS in source
return ansible.executor.module_common.REPLACER_JSONARGS in source
class WantJsonPlanner(ScriptPlanner):
@ -362,7 +361,7 @@ class NewStylePlanner(ScriptPlanner):
module_name='ansible_module_%s' % (self._inv.module_name,),
module_path=self._inv.module_path,
search_path=self.get_search_path(),
builtin_path=module_common._MODULE_UTILS_PATH,
builtin_path=ansible.executor.module_common._MODULE_UTILS_PATH,
context=self._inv.connection.context,
)
return self._module_map
@ -405,7 +404,7 @@ class ReplacerPlanner(NewStylePlanner):
@classmethod
def detect(cls, path, source):
return module_common.REPLACER in source
return ansible.executor.module_common.REPLACER in source
class OldStylePlanner(ScriptPlanner):
@ -427,12 +426,6 @@ _planners = [
]
try:
_get_ansible_module_fqn = module_common._get_ansible_module_fqn
except AttributeError:
_get_ansible_module_fqn = None
def py_modname_from_path(name, path):
"""
Fetch the logical name of a new-style module as it might appear in
@ -442,9 +435,10 @@ def py_modname_from_path(name, path):
package hierarchy approximated on the target, enabling relative imports
to function correctly. For example, "ansible.modules.system.setup".
"""
if _get_ansible_module_fqn:
try:
return _get_ansible_module_fqn(path)
return ansible.executor.module_common._get_ansible_module_fqn(path)
except AttributeError:
pass
except ValueError:
pass
@ -564,7 +558,7 @@ def _load_collections(invocation):
Goes through all collection path possibilities and stores paths to installed collections
Stores them on the current invocation to later be passed to the master service
"""
for collection_path in list_collection_dirs():
for collection_path in ansible.collections.list.list_collection_dirs():
invocation._extra_sys_paths.add(collection_path.decode('utf-8'))

@ -31,8 +31,7 @@ from __future__ import absolute_import
import os.path
import sys
from ansible.errors import AnsibleConnectionFailure
from ansible.module_utils.six import iteritems
import ansible.errors
try:
import ansible_mitogen
@ -61,7 +60,7 @@ class Connection(ansible_mitogen.connection.Connection):
def __init__(self, *args, **kwargs):
if not _get_result:
raise AnsibleConnectionFailure(self.not_supported_msg)
raise ansible.errors.AnsibleConnectionFailure(self.not_supported_msg)
super(Connection, self).__init__(*args, **kwargs)
def get_extra_args(self):
@ -72,8 +71,10 @@ class Connection(ansible_mitogen.connection.Connection):
# Ansible >= 2.10, _get_result is a get_with_context_result
connection_options = _get_result.object.connection_options
parameters = []
for key, option in iteritems(connection_options):
if self.get_task_var('ansible_' + key) is not None:
parameters += [ option, self.get_task_var('ansible_' + key) ]
for key in connection_options:
task_var_name = 'ansible_%s' % key
task_var = self.get_task_var(task_var_name)
if task_var is not None:
parameters += [connection_options[key], task_var]
return parameters

@ -44,13 +44,12 @@ from __future__ import unicode_literals
import logging
import os
import os.path
import sys
import threading
import ansible.constants
import mitogen
import mitogen.core
import mitogen.service
import mitogen.utils
import ansible_mitogen.loaders

@ -43,7 +43,7 @@ import ansible_mitogen.mixins
import ansible_mitogen.process
import ansible.executor.process.worker
from ansible.utils.sentinel import Sentinel
import ansible.utils.sentinel
def _patch_awx_callback():
@ -54,12 +54,11 @@ def _patch_awx_callback():
# AWX uses sitecustomize.py to force-load this package. If it exists, we're
# running under AWX.
try:
from awx_display_callback.events import EventContext
from awx_display_callback.events import event_context
import awx_display_callback.events
except ImportError:
return
if hasattr(EventContext(), '_local'):
if hasattr(awx_display_callback.events.EventContext(), '_local'):
# Patched version.
return
@ -68,8 +67,8 @@ def _patch_awx_callback():
ctx = tls.setdefault('_ctx', {})
ctx.update(kwargs)
EventContext._local = threading.local()
EventContext.add_local = patch_add_local
awx_display_callback.events.EventContext._local = threading.local()
awx_display_callback.events.EventContext.add_local = patch_add_local
_patch_awx_callback()
@ -279,7 +278,7 @@ class StrategyMixin(object):
name=task.action,
class_only=True,
)
if play_context.connection is not Sentinel:
if play_context.connection is not ansible.utils.sentinel.Sentinel:
# 2.8 appears to defer computing this until inside the worker.
# TODO: figure out where it has moved.
ansible_mitogen.loaders.connection_loader.get(

@ -51,7 +51,6 @@ import types
logging = __import__('logging')
import mitogen.core
import mitogen.fork
import mitogen.parent
import mitogen.service
from mitogen.core import b

@ -30,7 +30,6 @@
import logging
import mitogen.core
import mitogen.parent

@ -103,7 +103,6 @@ import tempfile
import threading
import mitogen.core
import mitogen.master
import mitogen.parent
from mitogen.core import LOG, IOLOG

@ -28,7 +28,6 @@
# !mitogen: minify_safe
import mitogen.core
import mitogen.parent

@ -28,7 +28,6 @@
# !mitogen: minify_safe
import mitogen.core
import mitogen.parent

@ -28,7 +28,6 @@
# !mitogen: minify_safe
import mitogen.core
import mitogen.parent

@ -31,7 +31,6 @@
import logging
import mitogen.core
import mitogen.parent

@ -31,7 +31,6 @@
import grp
import logging
import os
import os.path
import pprint
import pwd
import stat

@ -33,10 +33,8 @@ import logging
import os
import sys
import mitogen
import mitogen.core
import mitogen.master
import mitogen.parent
iteritems = getattr(dict, 'iteritems', dict.items)

@ -1,3 +1,2 @@
def path():
return "integration/module_utils/roles/modrole/module_utils/external2.py"

@ -1,11 +1,11 @@
#!/usr/bin/python
import json
from ansible.module_utils.basic import path
import ansible.module_utils.basic
def main():
print(json.dumps({
'path': path()
'path': ansible.module_utils.basic.path()
}))
if __name__ == '__main__':

@ -17,7 +17,7 @@
- custom_python_run_script:
script: |
import atexit, shutil
import atexit, os, shutil
path = '{{path}}'
os.mkdir(path, int('777', 8))
atexit.register(shutil.rmtree, path)

@ -1,8 +1,5 @@
import traceback
import sys
from ansible.plugins.strategy import StrategyBase
from ansible.plugins.action import ActionBase

@ -1,8 +1,5 @@
import traceback
import sys
from ansible.plugins.strategy import StrategyBase
from ansible.plugins.action import ActionBase

@ -1,4 +1,3 @@
import sys
from ansible.plugins.strategy import StrategyBase

@ -5,9 +5,7 @@ required for reliable LRU tests.
import ansible_mitogen.connection
import ansible_mitogen.services
import mitogen.service
from ansible.plugins.strategy import StrategyBase
from ansible.plugins.action import ActionBase

@ -1,4 +1,3 @@
# Monkey-patch os.fork() to produce a latency histogram on run completion.
# Requires 'hdrhsitograms' PyPI module.

@ -1,7 +1,6 @@
from __future__ import unicode_literals
import io
import os
import sys
from ansible import constants as C
from ansible.module_utils import six

@ -1,4 +1,3 @@
from ansible.module_utils._text import to_text

@ -1,3 +1,2 @@
def path():
return "ansible/lib/module_utils/external2.py"

@ -1,3 +1,2 @@
def path():
return 'ansible/lib/module_utils/externalpkg/extmod.py'

@ -4,7 +4,6 @@
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_module_path
from ansible.module_utils import six
import os
import pwd

@ -1,8 +1,6 @@
#!/usr/bin/python
# I am an Ansible Python JSONARGS module. I should receive an encoding string.
import sys
json_arguments = """<<INCLUDE_ANSIBLE_MODULE_JSON_ARGS>>"""
print("{")

@ -5,9 +5,6 @@
from ansible.module_utils.basic import AnsibleModule
import os
import pwd
import socket
import sys
def main():

@ -2,13 +2,6 @@
# issue #555: I'm a module that cutpastes an old hack.
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_module_path
from ansible.module_utils import six
import os
import pwd
import socket
import sys
import sys
reload(sys)

@ -3,12 +3,7 @@
# parameter.
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_module_path
from ansible.module_utils import six
import os
import pwd
import socket
import sys

@ -1,4 +1,3 @@
import multiprocessing
import os
import sys

@ -1,17 +1,12 @@
from __future__ import absolute_import
import os
import os.path
import subprocess
import tempfile
import time
import mock
import ansible.errors
import ansible.playbook.play_context
import mitogen.core
import mitogen.utils
import ansible_mitogen.connection
import ansible_mitogen.plugins.connection.mitogen_local
@ -25,7 +20,6 @@ class MuxProcessMixin(object):
@classmethod
def setUpClass(cls):
#mitogen.utils.log_to_file()
cls.model = ansible_mitogen.process.get_classic_worker_model(
_init_logging=False
)

@ -1,5 +1,4 @@
import os
import sys
import tempfile
import testlib

@ -1,4 +1,3 @@
from __future__ import absolute_import
import os.path
import subprocess

@ -1,10 +1,5 @@
# Verify _receive_one() quadratic behaviour fixed.
import subprocess
import time
import socket
import mitogen
import mitogen.core

@ -3,9 +3,7 @@ Measure latency of IPC between two local threads.
"""
import threading
import time
import mitogen
import mitogen.core
import mitogen.utils
import ansible_mitogen.affinity

@ -2,8 +2,6 @@
Measure latency of .local() setup.
"""
import time
import mitogen
import mitogen.core
import mitogen.utils

@ -2,7 +2,6 @@
import sys
import os
import time
import mitogen.core

@ -2,9 +2,6 @@
Measure latency of local RPC.
"""
import time
import mitogen
import mitogen.core
import mitogen.utils
import ansible_mitogen.affinity

@ -1,9 +1,6 @@
"""
Measure latency of local service RPC.
"""
import time
import mitogen
import mitogen.core
import mitogen.service

@ -3,9 +3,7 @@ Measure latency of SSH RPC.
"""
import sys
import time
import mitogen
import mitogen.core
import mitogen.utils
import ansible_mitogen.affinity

@ -1,11 +1,7 @@
# Verify throughput over sudo and SSH at various compression levels.
import os
import random
import socket
import subprocess
import tempfile
import time
import mitogen
import mitogen.core

@ -1,7 +1,5 @@
import os
import mitogen
import testlib

@ -1,9 +1,7 @@
import logging
import time
import mitogen.core
import mitogen.parent
import mitogen.master
from mitogen.core import str_partition
import testlib

@ -1,4 +1,3 @@
import os
import signal
import sys

@ -1,4 +1,3 @@
import pickle
import mitogen.core

@ -1,9 +1,7 @@
import fcntl
import os
import stat
import sys
import time
import tempfile
import mitogen.core

@ -1,6 +1,2 @@
import sys
def say_hi():
print('hi')

@ -1,3 +1,2 @@
from __future__ import absolute_import
from module_finder_testmod.regular_mod import say_hi

@ -1,4 +1,3 @@
import simple_pkg.b

@ -1,3 +1,2 @@
def subtract_one(n):
return n - 1

@ -1,5 +1,3 @@
def ping(*args):
return args

@ -1,4 +1,3 @@
import logging
import mitogen.master

@ -2,7 +2,6 @@
import json
import os
import subprocess
import sys
os.environ['ORIGINAL_ARGV'] = json.dumps(sys.argv)

@ -2,7 +2,6 @@
import json
import os
import subprocess
import sys
import time

@ -1,9 +1,7 @@
import os
import mitogen
import mitogen.core
import mitogen.doas
import mitogen.parent
import testlib

@ -1,7 +1,5 @@
import os
import mitogen
import testlib

@ -1,4 +1,3 @@
import os
import shutil
import unittest

@ -1,4 +1,3 @@
import sys
import mitogen.service

@ -1,4 +1,3 @@
import subprocess
import mitogen.parent

@ -1,7 +1,5 @@
import os
import random
import struct
import sys
import unittest

@ -1,4 +1,3 @@
import sys
import threading
import types

@ -1,4 +1,3 @@
import errno
import select

@ -1,12 +1,7 @@
import unittest
import mock
import mitogen.core
import testlib
try:
next
except NameError:

@ -1,9 +1,5 @@
import os
import mitogen
import mitogen.parent
import testlib

@ -1,9 +1,5 @@
import os
import mitogen
import mitogen.parent
import testlib

@ -1,4 +1,3 @@
import sys
import threading

@ -1,9 +1,6 @@
import os
import sys
import mitogen
import testlib

@ -1,4 +1,3 @@
import logging
import mock
import sys

@ -1,7 +1,7 @@
import os
import mitogen
import mitogen.lxc
import mitogen.parent
try:
any

@ -1,6 +1,5 @@
import os
import mitogen
import mitogen.lxd
import mitogen.parent

@ -1,5 +1,4 @@
import inspect
import unittest
import testlib
import mitogen.master
@ -15,7 +14,6 @@ class ScanCodeImportsTest(testlib.TestCase):
SIMPLE_EXPECT = [
(level, 'inspect', ()),
(level, 'unittest', ()),
(level, 'testlib', ()),
(level, 'mitogen.master', ()),
]

@ -1,4 +1,3 @@
import sys
import struct
import unittest

@ -1,4 +1,3 @@
import mock
import mitogen.core

@ -7,7 +7,6 @@ import mitogen.master
from mitogen.core import b
import testlib
from testlib import MODS_DIR
class ConstructorTest(testlib.TestCase):
@ -87,14 +86,14 @@ class PkgutilMethodTest(testlib.TestCase):
def test_empty_source_pkg(self):
path, src, is_pkg = self.call('module_finder_testmod')
self.assertEqual(path,
os.path.join(MODS_DIR, 'module_finder_testmod/__init__.py'))
os.path.join(testlib.MODS_DIR, 'module_finder_testmod/__init__.py'))
self.assertEqual(mitogen.core.b(''), src)
self.assertTrue(is_pkg)
def test_empty_source_module(self):
path, src, is_pkg = self.call('module_finder_testmod.empty_mod')
self.assertEqual(path,
os.path.join(MODS_DIR, 'module_finder_testmod/empty_mod.py'))
os.path.join(testlib.MODS_DIR, 'module_finder_testmod/empty_mod.py'))
self.assertEqual(mitogen.core.b(''), src)
self.assertFalse(is_pkg)
@ -102,7 +101,7 @@ class PkgutilMethodTest(testlib.TestCase):
from module_finder_testmod import regular_mod
path, src, is_pkg = self.call('module_finder_testmod.regular_mod')
self.assertEqual(path,
os.path.join(MODS_DIR, 'module_finder_testmod/regular_mod.py'))
os.path.join(testlib.MODS_DIR, 'module_finder_testmod/regular_mod.py'))
self.assertEqual(mitogen.core.to_text(src),
inspect.getsource(regular_mod))
self.assertFalse(is_pkg)
@ -165,7 +164,7 @@ class GetModuleViaParentEnumerationTest(testlib.TestCase):
# plumbum has been eating too many rainbow-colored pills
import pkg_like_plumbum.colors
path, src, is_pkg = self.call('pkg_like_plumbum.colors')
modpath = os.path.join(MODS_DIR, 'pkg_like_plumbum/colors.py')
modpath = os.path.join(testlib.MODS_DIR, 'pkg_like_plumbum/colors.py')
self.assertEqual(path, modpath)
with open(modpath, 'rb') as f:
@ -183,7 +182,7 @@ class GetModuleViaParentEnumerationTest(testlib.TestCase):
# ensure we can resolve the subpackage.
path, src, is_pkg = self.call('pkg_like_ansible.module_utils.distro')
modpath = os.path.join(MODS_DIR,
modpath = os.path.join(testlib.MODS_DIR,
'pkg_like_ansible/module_utils/distro/__init__.py')
self.assertEqual(path, modpath)
with open(modpath, 'rb') as f:
@ -194,7 +193,7 @@ class GetModuleViaParentEnumerationTest(testlib.TestCase):
path, src, is_pkg = self.call(
'pkg_like_ansible.module_utils.distro._distro'
)
modpath = os.path.join(MODS_DIR,
modpath = os.path.join(testlib.MODS_DIR,
'pkg_like_ansible/module_utils/distro/_distro.py')
self.assertEqual(path, modpath)
with open(modpath, 'rb') as f:
@ -213,7 +212,7 @@ class GetModuleViaParentEnumerationTest(testlib.TestCase):
# ensure we can resolve the subpackage.
path, src, is_pkg = self.call('pkg_like_ansible.module_utils.sys_distro')
modpath = os.path.join(MODS_DIR,
modpath = os.path.join(testlib.MODS_DIR,
'pkg_like_ansible/module_utils/sys_distro/__init__.py')
self.assertEqual(path, modpath)
with open(modpath, 'rb') as f:
@ -224,7 +223,7 @@ class GetModuleViaParentEnumerationTest(testlib.TestCase):
path, src, is_pkg = self.call(
'pkg_like_ansible.module_utils.sys_distro._distro'
)
modpath = os.path.join(MODS_DIR,
modpath = os.path.join(testlib.MODS_DIR,
'pkg_like_ansible/module_utils/sys_distro/_distro.py')
self.assertEqual(path, modpath)
with open(modpath, 'rb') as f:
@ -268,7 +267,6 @@ class FakeSshTest(testlib.TestCase):
self.assertEqual(related, [
'mitogen',
'mitogen.core',
'mitogen.master',
'mitogen.parent',
])
@ -282,8 +280,6 @@ class FindRelatedTest(testlib.TestCase):
SIMPLE_EXPECT = set([
u'mitogen',
u'mitogen.core',
u'mitogen.master',
u'mitogen.minify',
u'mitogen.parent',
])
@ -302,7 +298,7 @@ class FindRelatedTest(testlib.TestCase):
if sys.version_info > (2, 6):
class DjangoMixin(object):
WEBPROJECT_PATH = os.path.join(MODS_DIR, 'webproject')
WEBPROJECT_PATH = os.path.join(testlib.MODS_DIR, 'webproject')
# TODO: rip out Django and replace with a static tree of weird imports
# that don't depend on .. Django! The hack below is because the version

@ -1,7 +1,5 @@
import os
import mitogen
import testlib

@ -1,4 +1,3 @@
import errno
import os
import select

@ -1,4 +1,3 @@
import testlib
import mitogen.core

@ -1,5 +1,3 @@
import os
import tempfile
import mitogen.core

@ -1,4 +1,3 @@
import signal
import testlib

@ -1,4 +1,3 @@
import sys
import threading
import unittest

@ -1,4 +1,3 @@
import mock
import textwrap
import subprocess

@ -1,7 +1,6 @@
import errno
import os
import sys
import time
import zlib
import testlib

@ -1,3 +1,4 @@
import mitogen.core
import mitogen.select
import testlib

@ -1,11 +1,8 @@
import os
import socket
import sys
import unittest
import mitogen
import mitogen.parent
import mitogen.core
import testlib

@ -1,4 +1,3 @@
import testlib
import mitogen.core

@ -7,7 +7,6 @@ weirdness. Useful for exposing otherwise difficult to hit races in the library.
import ctypes
import multiprocessing
import os
import time
LIBC = ctypes.CDLL('libc.so.6')
sched_yield = LIBC.sched_yield

@ -1,8 +1,6 @@
import os
import sys
import tempfile
import mitogen
import mitogen.ssh
import mitogen.utils

@ -1,7 +1,6 @@
import os
import mitogen
import mitogen.core
import mitogen.su
import testlib

@ -1,9 +1,5 @@
import os
import mitogen
import mitogen.sudo
import testlib

@ -1,4 +1,3 @@
import errno
import logging
import os

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save