From 4273689423bdf6c1ee09631b46ad929bd298746c Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Thu, 13 Jul 2023 15:24:30 -0400 Subject: [PATCH] Enable pylint codes C0411, E1101, R0205 --- pyproject.toml | 3 +++ src/ansible_runner/config/_base.py | 9 ++++----- src/ansible_runner/config/runner.py | 2 +- .../display_callback/callback/awx_display.py | 4 ++-- src/ansible_runner/loader.py | 2 +- src/ansible_runner/runner.py | 6 +++--- src/ansible_runner/streaming.py | 13 +++++++------ src/ansible_runner/utils/__init__.py | 8 ++++---- 8 files changed, 25 insertions(+), 22 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 86757d59c..773336878 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,9 @@ disable = [ enable = [ "C0209", # consider-using-f-string + "C0411", # wrong-import-order + "E1101", # no-member + "R0205", # useless-object-inheritance "W0102", # dangerous-default-value "W1202", # logging-format-interpolation "W1203", # logging-fstring-interpolation diff --git a/src/ansible_runner/config/_base.py b/src/ansible_runner/config/_base.py index 009562476..b7836f399 100644 --- a/src/ansible_runner/config/_base.py +++ b/src/ansible_runner/config/_base.py @@ -19,16 +19,15 @@ import json import logging import os -import pexpect import re import stat import tempfile import shutil - from base64 import b64encode from uuid import uuid4 from collections.abc import Mapping +import pexpect from six import iteritems, string_types from ansible_runner import defaults @@ -48,7 +47,7 @@ logger = logging.getLogger('ansible-runner') -class BaseExecutionMode(): +class BaseExecutionMode: NONE = 0 # run ansible commands either locally or within EE ANSIBLE_COMMANDS = 1 @@ -56,7 +55,7 @@ class BaseExecutionMode(): GENERIC_COMMANDS = 2 -class BaseConfig(object): +class BaseConfig: def __init__(self, private_data_dir=None, host_cwd=None, envvars=None, passwords=None, settings=None, @@ -462,7 +461,7 @@ def wrap_args_for_containerization(self, args, execution_mode, cmdline_args): new_args = [self.process_isolation_executable] new_args.extend(['run', '--rm']) - if self.runner_mode == 'pexpect' or hasattr(self, 'input_fd') and self.input_fd is not None: + if self.runner_mode == 'pexpect' or getattr(self, 'input_fd', False): new_args.extend(['--tty']) new_args.append('--interactive') diff --git a/src/ansible_runner/config/runner.py b/src/ansible_runner/config/runner.py index 7f291bdc2..08ed6f493 100644 --- a/src/ansible_runner/config/runner.py +++ b/src/ansible_runner/config/runner.py @@ -22,9 +22,9 @@ import shlex import stat import tempfile -import six import shutil +import six from six import string_types, text_type from ansible_runner import output diff --git a/src/ansible_runner/display_callback/callback/awx_display.py b/src/ansible_runner/display_callback/callback/awx_display.py index 83d37ed60..0474efeec 100644 --- a/src/ansible_runner/display_callback/callback/awx_display.py +++ b/src/ansible_runner/display_callback/callback/awx_display.py @@ -118,7 +118,7 @@ def set(self, key, value): os.rename(write_location, dropoff_location) -class EventContext(object): +class EventContext: ''' Store global and local (per thread/process) data associated with callback events and other display output methods. @@ -417,7 +417,7 @@ def set_task(self, task, local=False): task_ctx['task_path'] = task.get_path() except AttributeError: pass - if C.DISPLAY_ARGS_TO_STDOUT: + if C.DISPLAY_ARGS_TO_STDOUT: # pylint: disable=E1101 if task.no_log: task_ctx['task_args'] = "the output has been hidden due to the fact that 'no_log: true' was specified for this result" else: diff --git a/src/ansible_runner/loader.py b/src/ansible_runner/loader.py index 565bbf6bb..2ec82761d 100644 --- a/src/ansible_runner/loader.py +++ b/src/ansible_runner/loader.py @@ -27,7 +27,7 @@ from ansible_runner.output import debug -class ArtifactLoader(object): +class ArtifactLoader: ''' Handles loading and caching file contents from disk diff --git a/src/ansible_runner/runner.py b/src/ansible_runner/runner.py index 61ed8c03f..c235dd2d0 100644 --- a/src/ansible_runner/runner.py +++ b/src/ansible_runner/runner.py @@ -10,20 +10,20 @@ import collections import datetime import logging - import six import pexpect import ansible_runner.plugins +from ansible_runner.output import debug from .utils import OutputEventFilter, cleanup_artifact_dir, ensure_str, collect_new_events from .exceptions import CallbackError, AnsibleRunnerException -from ansible_runner.output import debug + logger = logging.getLogger('ansible-runner') -class Runner(object): +class Runner: def __init__(self, config, cancel_callback=None, remove_partials=True, event_handler=None, artifacts_handler=None, finished_callback=None, status_handler=None): diff --git a/src/ansible_runner/streaming.py b/src/ansible_runner/streaming.py index 2558870c0..76c71189e 100644 --- a/src/ansible_runner/streaming.py +++ b/src/ansible_runner/streaming.py @@ -9,15 +9,16 @@ import uuid import traceback +from collections.abc import Mapping +from functools import wraps +from threading import Event, RLock, Thread + import ansible_runner from ansible_runner.exceptions import ConfigurationError from ansible_runner.loader import ArtifactLoader import ansible_runner.plugins from ansible_runner.utils import register_for_cleanup from ansible_runner.utils.streaming import stream_dir, unstream_dir -from collections.abc import Mapping -from functools import wraps -from threading import Event, RLock, Thread class UUIDEncoder(json.JSONEncoder): @@ -27,12 +28,12 @@ def default(self, obj): return json.JSONEncoder.default(self, obj) -class MockConfig(object): +class MockConfig: def __init__(self, settings): self.settings = settings -class Transmitter(object): +class Transmitter: def __init__(self, _output=None, **kwargs): if _output is None: _output = sys.stdout.buffer @@ -239,7 +240,7 @@ def finished_callback(self, runner_obj): self._output.flush() -class Processor(object): +class Processor: def __init__(self, _input=None, status_handler=None, event_handler=None, artifacts_handler=None, cancel_callback=None, finished_callback=None, **kwargs): if _input is None: diff --git a/src/ansible_runner/utils/__init__.py b/src/ansible_runner/utils/__init__.py index 6700d9c3b..57e187a4d 100644 --- a/src/ansible_runner/utils/__init__.py +++ b/src/ansible_runner/utils/__init__.py @@ -19,12 +19,12 @@ import atexit import signal -from ansible_runner.exceptions import ConfigurationError - from collections.abc import Iterable, MutableMapping from io import StringIO from six import string_types, PY2, PY3, text_type, binary_type +from ansible_runner.exceptions import ConfigurationError + def cleanup_folder(folder): """Deletes folder, returns True or False based on whether a change happened.""" @@ -58,7 +58,7 @@ def is_dir_owner(directory): return bool(current_user == callback_owner) -class Bunch(object): +class Bunch: ''' Collect a bunch of variables together in an object. @@ -276,7 +276,7 @@ def collect_new_events(event_path, old_events): yield event, old_events -class OutputEventFilter(object): +class OutputEventFilter: ''' File-like object that looks for encoded job events in stdout data. '''