From e20bb717d803cabca348a2c20c7d33b65894bd8c Mon Sep 17 00:00:00 2001 From: "Bradley A. Thornton" Date: Fri, 6 Oct 2023 07:34:59 -0700 Subject: [PATCH] Disable FA100, FA102 --- plugins/action/git_publish.py | 31 +++++++++++++-------------- plugins/action/git_retrieve.py | 37 ++++++++++++++++----------------- plugins/plugin_utils/command.py | 16 +++++++------- pyproject.toml | 16 +++++--------- tests/unit/test_smoke.py | 12 +++++------ 5 files changed, 51 insertions(+), 61 deletions(-) diff --git a/plugins/action/git_publish.py b/plugins/action/git_publish.py index 7cfd1342..6f9645b3 100644 --- a/plugins/action/git_publish.py +++ b/plugins/action/git_publish.py @@ -3,18 +3,24 @@ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) """The git_publish action plugin.""" -from __future__ import absolute_import, annotations, division, print_function +from __future__ import absolute_import, division, print_function import shutil import webbrowser from contextlib import suppress -from dataclasses import asdict -from typing import TYPE_CHECKING, Dict, List, TypeVar, Union +from dataclasses import asdict, dataclass +from typing import Dict, List, Optional, TypeVar, Union from ansible.errors import AnsibleActionFail - -# pylint: disable=import-error, useless-suppression +from ansible.parsing.dataloader import DataLoader +from ansible.playbook.play_context import PlayContext +from ansible.playbook.task import Task +from ansible.plugins import loader as plugin_loader +from ansible.plugins.connection.local import Connection +from ansible.template import Templar + +# pylint: disable=import-error from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import ( AnsibleArgSpecValidator, ) @@ -24,21 +30,14 @@ from ..plugin_utils.git_base import ActionInit, GitBase, ResultBase -if TYPE_CHECKING: - from ansible.parsing.dataloader import DataLoader - from ansible.playbook.play_context import PlayContext - from ansible.playbook.task import Task - from ansible.plugins import loader as plugin_loader - from ansible.plugins.connection.local import Connection - from ansible.template import Templar - - # pylint: disable=invalid-name __metaclass__ = type # pylint: enable=invalid-name JSONTypes = Union[bool, int, str, Dict, List] + +@dataclass(frozen=False) class Result(ResultBase): """Data structure for the task result.""" @@ -249,8 +248,8 @@ def _remove_repo(self: T) -> None: def run( self: T, tmp: None = None, - task_vars: dict[str, JSONTypes] | None = None, - ) -> dict[str, JSONTypes]: + task_vars: Optional[Dict[str, JSONTypes]] = None, + ) -> Dict[str, JSONTypes]: """Run the action plugin. :param tmp: The temporary directory diff --git a/plugins/action/git_retrieve.py b/plugins/action/git_retrieve.py index 760a74bf..4fa2b9b4 100644 --- a/plugins/action/git_retrieve.py +++ b/plugins/action/git_retrieve.py @@ -3,19 +3,25 @@ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) """The git_retrieve action plugin.""" -from __future__ import absolute_import, annotations, division, print_function +from __future__ import absolute_import, division, print_function import datetime import re import tempfile -from dataclasses import asdict +from dataclasses import asdict, dataclass, field from pathlib import Path -from typing import TYPE_CHECKING, ClassVar, Dict, List, TypeVar, Union +from typing import Dict, List, Optional, Tuple, TypeVar, Union from ansible.errors import AnsibleActionFail - -# pylint: disable=import-error, useless-suppression +from ansible.parsing.dataloader import DataLoader +from ansible.playbook.play_context import PlayContext +from ansible.playbook.task import Task +from ansible.plugins import loader as plugin_loader +from ansible.plugins.connection.local import Connection +from ansible.template import Templar + +# pylint: disable=import-error from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import ( AnsibleArgSpecValidator, ) @@ -25,26 +31,19 @@ from ..plugin_utils.git_base import ActionInit, GitBase, ResultBase -if TYPE_CHECKING: - from ansible.parsing.dataloader import DataLoader - from ansible.playbook.play_context import PlayContext - from ansible.playbook.task import Task - from ansible.plugins import loader as plugin_loader - from ansible.plugins.connection.local import Connection - from ansible.template import Templar - - # pylint: disable=invalid-name __metaclass__ = type # pylint: enable=invalid-name JSONTypes = Union[bool, int, str, Dict, List] + +@dataclass(frozen=False) class Result(ResultBase): """Data structure for the task result.""" branch_name: str = "" - branches: ClassVar[list[str]] = [] + branches: List[str] = field(default_factory=list) name: str = "" path: str = "" @@ -89,8 +88,8 @@ def __init__( # noqa: PLR0913 ), ) - self._base_command: tuple[str, ...] - self._branches: list[str] + self._base_command: Tuple[str, ...] + self._branches: List[str] self._branch_name: str self._parent_directory: str self._repo_path: str @@ -327,8 +326,8 @@ def _pull_upstream(self: T) -> None: def run( self: T, tmp: None = None, - task_vars: dict[str, JSONTypes] | None = None, - ) -> dict[str, JSONTypes]: + task_vars: Optional[Dict[str, JSONTypes]] = None, + ) -> Dict[str, JSONTypes]: """Run the action plugin. :param tmp: The temporary directory diff --git a/plugins/plugin_utils/command.py b/plugins/plugin_utils/command.py index 7646a09e..622cdb2b 100644 --- a/plugins/plugin_utils/command.py +++ b/plugins/plugin_utils/command.py @@ -1,5 +1,5 @@ """Definitions for the command runner.""" -from __future__ import absolute_import, annotations, division, print_function +from __future__ import absolute_import, division, print_function import shlex @@ -10,7 +10,7 @@ from dataclasses import dataclass, field -from typing import TypeVar +from typing import Dict, List, Optional, TypeVar, Union T = TypeVar("T", bound="Command") # pylint: disable=invalid-name, useless-suppression @@ -26,16 +26,16 @@ class Command: # pylint: disable=too-many-instance-attributes - command_parts: list[str] + command_parts: List[str] fail_msg: str - env: dict[str, str] | None = None - no_log: dict[str, str] = field(default_factory=dict) + env: Optional[Dict[str, str]] = None + no_log: Dict[str, str] = field(default_factory=dict) return_code: int = -1 stdout: str = "" stderr: str = "" - stdout_lines: list[str] = field(default_factory=list) - stderr_lines: list[str] = field(default_factory=list) + stdout_lines: List[str] = field(default_factory=list) + stderr_lines: List[str] = field(default_factory=list) @property def command(self: T) -> str: @@ -46,7 +46,7 @@ def command(self: T) -> str: return shlex.join(self.command_parts) @property - def cleaned(self: T) -> dict[str, int | dict[str, str] | list[str] | str]: + def cleaned(self: T) -> Dict[str, Union[int, Dict[str, str], List[str], str]]: """Return the sanitized details of the command for the log. :return: The sanitized details of the command for the log. diff --git a/pyproject.toml b/pyproject.toml index da151d32..7203f68e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,14 +32,7 @@ enable = [ # Run with xdist 1 until molecule has shared scenario state [tool.pytest.ini_options] -addopts = [ - "-n", - "1", - "--log-level", - "WARNING", - "--color", - "yes" -] +addopts = ["-n", "1", "--log-level", "WARNING", "--color", "yes"] testpaths = ["tests"] filterwarnings = ['ignore:AnsibleCollectionFinder has already been configured'] @@ -51,8 +44,9 @@ select = ["ALL"] # ARG = flake8 argument, overlap with pylint # FBT = flake8 boolean, silly # TID = flake8 tidy imports, need relative for pylint -ignore = ["ARG", "FBT", "TID"] -target-version = "py38" +# FA100, FA102 issues with 3.8/3.9 + 2.12 +ignore = ["ARG", "FBT", "TID", "FA100", "FA102"] +# target-version = "py38" [tool.ruff.per-file-ignores] # D100 Missing docstring in public module (ansible) @@ -80,7 +74,7 @@ target-version = "py38" lines-after-imports = 2 # Ensures consistency for cases when there's variable vs function/class definitions after imports lines-between-types = 1 # Separate import/from with 1 line required-imports = [ - "from __future__ import absolute_import, division, print_function" + "from __future__ import absolute_import, division, print_function", ] [tool.ruff.pydocstyle] diff --git a/tests/unit/test_smoke.py b/tests/unit/test_smoke.py index db3b079f..d5b3255a 100644 --- a/tests/unit/test_smoke.py +++ b/tests/unit/test_smoke.py @@ -1,19 +1,19 @@ """Some basic smoke tests.""" -from __future__ import absolute_import, annotations, division, print_function +from __future__ import absolute_import, division, print_function # pylint: disable=invalid-name __metaclass__ = type # pylint: enable=invalid-name -from typing import TYPE_CHECKING +from typing import Union import pytest from ansible.errors import AnsibleActionFail -# pylint: disable=import-error, useless-suppression +# pylint: disable=import-error from ansible_collections.ansible.scm.plugins.action.git_publish import ( ActionModule as GitPublishActionModule, ) @@ -21,9 +21,7 @@ ActionModule as GitRetrieveActionModule, ) - -if TYPE_CHECKING: - from .definitions import ActionModuleInit +from .definitions import ActionModuleInit @pytest.mark.parametrize( @@ -33,7 +31,7 @@ ) def test_fail_argspec( action_init: ActionModuleInit, - module: GitPublishActionModule | GitRetrieveActionModule, + module: Union[GitPublishActionModule, GitRetrieveActionModule], ) -> None: """Test an argspec failure.