From 27c7d5bb01f15dc89021a6019c07c10a03ed7035 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 20 Dec 2018 10:07:49 -0800 Subject: [PATCH] Move the arguments module into cli/ and context_objects into utils * Note: Python2 is not as intelligent at detecting false import loops as Python3. context_objects.py cannot be added to cli/arguments because it would set up an import loop between cli/__init__.py, cli/arguments/context_objects.py, and context.py on Python2. ci_complete --- lib/ansible/cli/__init__.py | 2 +- lib/ansible/cli/adhoc.py | 2 +- lib/ansible/{ => cli}/arguments/__init__.py | 0 lib/ansible/{ => cli}/arguments/optparse_helpers.py | 0 lib/ansible/cli/console.py | 2 +- lib/ansible/cli/doc.py | 2 +- lib/ansible/cli/galaxy.py | 2 +- lib/ansible/cli/inventory.py | 2 +- lib/ansible/cli/playbook.py | 2 +- lib/ansible/cli/pull.py | 2 +- lib/ansible/cli/vault.py | 2 +- lib/ansible/context.py | 6 +++++- lib/ansible/{arguments => utils}/context_objects.py | 2 +- test/units/{ => cli}/arguments/test_optparse_helpers.py | 2 +- test/units/cli/test_galaxy.py | 8 ++++---- test/units/executor/test_playbook_executor.py | 2 +- test/units/executor/test_task_queue_manager_callbacks.py | 2 +- test/units/playbook/test_play_context.py | 6 +++--- test/units/{arguments => utils}/test_context_objects.py | 2 +- 19 files changed, 26 insertions(+), 22 deletions(-) rename lib/ansible/{ => cli}/arguments/__init__.py (100%) rename lib/ansible/{ => cli}/arguments/optparse_helpers.py (100%) rename lib/ansible/{arguments => utils}/context_objects.py (98%) rename test/units/{ => cli}/arguments/test_optparse_helpers.py (88%) rename test/units/{arguments => utils}/test_context_objects.py (98%) diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index 4b2a2da1b9..5fc33c285a 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -18,7 +18,7 @@ from abc import ABCMeta, abstractmethod from ansible import constants as C from ansible import context -from ansible.arguments import optparse_helpers as opt_help +from ansible.cli.arguments import optparse_helpers as opt_help from ansible.errors import AnsibleOptionsError, AnsibleError from ansible.inventory.manager import InventoryManager from ansible.module_utils.six import with_metaclass, string_types diff --git a/lib/ansible/cli/adhoc.py b/lib/ansible/cli/adhoc.py index be9341b0d3..3d92af00f8 100644 --- a/lib/ansible/cli/adhoc.py +++ b/lib/ansible/cli/adhoc.py @@ -7,8 +7,8 @@ __metaclass__ = type from ansible import constants as C from ansible import context -from ansible.arguments import optparse_helpers as opt_help from ansible.cli import CLI +from ansible.cli.arguments import optparse_helpers as opt_help from ansible.errors import AnsibleError, AnsibleOptionsError from ansible.executor.task_queue_manager import TaskQueueManager from ansible.module_utils._text import to_text diff --git a/lib/ansible/arguments/__init__.py b/lib/ansible/cli/arguments/__init__.py similarity index 100% rename from lib/ansible/arguments/__init__.py rename to lib/ansible/cli/arguments/__init__.py diff --git a/lib/ansible/arguments/optparse_helpers.py b/lib/ansible/cli/arguments/optparse_helpers.py similarity index 100% rename from lib/ansible/arguments/optparse_helpers.py rename to lib/ansible/cli/arguments/optparse_helpers.py diff --git a/lib/ansible/cli/console.py b/lib/ansible/cli/console.py index 03edda1fa7..5f3a414275 100644 --- a/lib/ansible/cli/console.py +++ b/lib/ansible/cli/console.py @@ -26,8 +26,8 @@ import sys from ansible import constants as C from ansible import context -from ansible.arguments import optparse_helpers as opt_help from ansible.cli import CLI +from ansible.cli.arguments import optparse_helpers as opt_help from ansible.executor.task_queue_manager import TaskQueueManager from ansible.module_utils._text import to_native, to_text from ansible.module_utils.parsing.convert_bool import boolean diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py index 4eb14b1a29..4853d9c975 100644 --- a/lib/ansible/cli/doc.py +++ b/lib/ansible/cli/doc.py @@ -16,8 +16,8 @@ import ansible.plugins.loader as plugin_loader from ansible import constants as C from ansible import context -from ansible.arguments import optparse_helpers as opt_help from ansible.cli import CLI +from ansible.cli.arguments import optparse_helpers as opt_help from ansible.errors import AnsibleError, AnsibleOptionsError from ansible.module_utils._text import to_native from ansible.module_utils.common._collections_compat import Sequence diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 6ad128c6a7..ca957bdce3 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -16,8 +16,8 @@ from jinja2 import Environment, FileSystemLoader import ansible.constants as C from ansible import context -from ansible.arguments import optparse_helpers as opt_help from ansible.cli import CLI +from ansible.cli.arguments import optparse_helpers as opt_help from ansible.errors import AnsibleError, AnsibleOptionsError from ansible.galaxy import Galaxy from ansible.galaxy.api import GalaxyAPI diff --git a/lib/ansible/cli/inventory.py b/lib/ansible/cli/inventory.py index 26b27f6699..f011f0d563 100644 --- a/lib/ansible/cli/inventory.py +++ b/lib/ansible/cli/inventory.py @@ -10,8 +10,8 @@ from operator import attrgetter from ansible import constants as C from ansible import context -from ansible.arguments import optparse_helpers as opt_help from ansible.cli import CLI +from ansible.cli.arguments import optparse_helpers as opt_help from ansible.errors import AnsibleError, AnsibleOptionsError from ansible.inventory.host import Host from ansible.plugins.loader import vars_loader diff --git a/lib/ansible/cli/playbook.py b/lib/ansible/cli/playbook.py index 44dddb2ea7..66dfc56861 100644 --- a/lib/ansible/cli/playbook.py +++ b/lib/ansible/cli/playbook.py @@ -9,8 +9,8 @@ import os import stat from ansible import context -from ansible.arguments import optparse_helpers as opt_help from ansible.cli import CLI +from ansible.cli.arguments import optparse_helpers as opt_help from ansible.errors import AnsibleError, AnsibleOptionsError from ansible.executor.playbook_executor import PlaybookExecutor from ansible.playbook.block import Block diff --git a/lib/ansible/cli/pull.py b/lib/ansible/cli/pull.py index 2d34c5bcdb..92c790928b 100644 --- a/lib/ansible/cli/pull.py +++ b/lib/ansible/cli/pull.py @@ -16,8 +16,8 @@ import time from ansible import constants as C from ansible import context -from ansible.arguments import optparse_helpers as opt_help from ansible.cli import CLI +from ansible.cli.arguments import optparse_helpers as opt_help from ansible.errors import AnsibleOptionsError from ansible.module_utils._text import to_native, to_text from ansible.plugins.loader import module_loader diff --git a/lib/ansible/cli/vault.py b/lib/ansible/cli/vault.py index 9a941dcdd0..96dc1588f0 100644 --- a/lib/ansible/cli/vault.py +++ b/lib/ansible/cli/vault.py @@ -10,8 +10,8 @@ import sys from ansible import constants as C from ansible import context -from ansible.arguments import optparse_helpers as opt_help from ansible.cli import CLI +from ansible.cli.arguments import optparse_helpers as opt_help from ansible.errors import AnsibleOptionsError from ansible.module_utils._text import to_text, to_bytes from ansible.parsing.dataloader import DataLoader diff --git a/lib/ansible/context.py b/lib/ansible/context.py index 3b2c56a182..67786a0292 100644 --- a/lib/ansible/context.py +++ b/lib/ansible/context.py @@ -15,14 +15,18 @@ running the ansible command line tools. These APIs are still in flux so do not use them unless you are willing to update them with every Ansible release """ -from ansible.arguments.context_objects import CLIArgs, GlobalCLIArgs +from ansible.utils.context_objects import CLIArgs, GlobalCLIArgs +__all__ = ('CLIARGS',) + # Note: this is not the singleton version. The Singleton is only created once the program has # actually parsed the args CLIARGS = CLIArgs({}) +# This should be called immediately after cli_args are processed (parsed, validated, and any +# normalization performed on them). No other code should call it def _init_global_context(cli_args): """Initialize the global context objects""" global CLIARGS diff --git a/lib/ansible/arguments/context_objects.py b/lib/ansible/utils/context_objects.py similarity index 98% rename from lib/ansible/arguments/context_objects.py rename to lib/ansible/utils/context_objects.py index b7ed0889ff..7124174958 100644 --- a/lib/ansible/arguments/context_objects.py +++ b/lib/ansible/utils/context_objects.py @@ -1,4 +1,4 @@ -# Copyright: (c) 2018, Toshio Kuratomi +# Copyright: (c) 2018, Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # Make coding more python3-ish diff --git a/test/units/arguments/test_optparse_helpers.py b/test/units/cli/arguments/test_optparse_helpers.py similarity index 88% rename from test/units/arguments/test_optparse_helpers.py rename to test/units/cli/arguments/test_optparse_helpers.py index e4fdda33f8..5c6a632941 100644 --- a/test/units/arguments/test_optparse_helpers.py +++ b/test/units/cli/arguments/test_optparse_helpers.py @@ -8,7 +8,7 @@ __metaclass__ = type import pytest -from ansible.arguments import optparse_helpers as opt_help +from ansible.cli.arguments import optparse_helpers as opt_help class TestOptparseHelpersVersion: diff --git a/test/units/cli/test_galaxy.py b/test/units/cli/test_galaxy.py index 56d3c0c22d..966f66b660 100644 --- a/test/units/cli/test_galaxy.py +++ b/test/units/cli/test_galaxy.py @@ -27,13 +27,13 @@ import tempfile import yaml from ansible import context -from ansible.arguments import context_objects as co -from ansible.arguments import optparse_helpers as opt_help +from ansible.cli.arguments import optparse_helpers as opt_help from ansible.cli.galaxy import GalaxyCLI -from units.compat import unittest -from units.compat.mock import call, patch from ansible.errors import AnsibleError, AnsibleOptionsError from ansible.module_utils.six import PY3 +from ansible.utils import context_objects as co +from units.compat import unittest +from units.compat.mock import call, patch class TestGalaxy(unittest.TestCase): diff --git a/test/units/executor/test_playbook_executor.py b/test/units/executor/test_playbook_executor.py index bd2c678fb5..529eda36f3 100644 --- a/test/units/executor/test_playbook_executor.py +++ b/test/units/executor/test_playbook_executor.py @@ -22,10 +22,10 @@ __metaclass__ = type from units.compat import unittest from units.compat.mock import MagicMock -from ansible.arguments import context_objects as co from ansible.executor.playbook_executor import PlaybookExecutor from ansible.playbook import Playbook from ansible.template import Templar +from ansible.utils import context_objects as co from units.mock.loader import DictDataLoader diff --git a/test/units/executor/test_task_queue_manager_callbacks.py b/test/units/executor/test_task_queue_manager_callbacks.py index 044fe15910..b23c9580de 100644 --- a/test/units/executor/test_task_queue_manager_callbacks.py +++ b/test/units/executor/test_task_queue_manager_callbacks.py @@ -22,10 +22,10 @@ from units.compat import unittest from units.compat.mock import MagicMock from ansible import context -from ansible.arguments import context_objects as co from ansible.executor.task_queue_manager import TaskQueueManager from ansible.playbook import Playbook from ansible.plugins.callback import CallbackBase +from ansible.utils import context_objects as co __metaclass__ = type diff --git a/test/units/playbook/test_play_context.py b/test/units/playbook/test_play_context.py index c7e51cd8a4..451b0c6a3b 100644 --- a/test/units/playbook/test_play_context.py +++ b/test/units/playbook/test_play_context.py @@ -13,12 +13,12 @@ import pytest from ansible import constants as C from ansible import context -from ansible.arguments import context_objects as co -from ansible.arguments import optparse_helpers as opt_help -from units.compat import unittest +from ansible.cli.arguments import optparse_helpers as opt_help from ansible.errors import AnsibleError, AnsibleParserError from ansible.module_utils.six.moves import shlex_quote from ansible.playbook.play_context import PlayContext +from ansible.utils import context_objects as co +from units.compat import unittest from units.mock.loader import DictDataLoader diff --git a/test/units/arguments/test_context_objects.py b/test/units/utils/test_context_objects.py similarity index 98% rename from test/units/arguments/test_context_objects.py rename to test/units/utils/test_context_objects.py index d843da2c98..8e96fe7f3c 100644 --- a/test/units/arguments/test_context_objects.py +++ b/test/units/utils/test_context_objects.py @@ -15,8 +15,8 @@ import optparse import pytest -from ansible.arguments import context_objects as co from ansible.module_utils.common.collections import ImmutableDict +from ansible.utils import context_objects as co MAKE_IMMUTABLE_DATA = ((u'くらとみ', u'くらとみ'),