From e104ebfec5f1f427992ee85a767290539abf7b3f Mon Sep 17 00:00:00 2001 From: "Bradley A. Thornton" Date: Thu, 27 Jun 2024 11:46:40 -0700 Subject: [PATCH] Cleaup ruff config with latest version (#4243) - update constraints to pull in ruff .5 - Remove unused ruff config --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .config/constraints.txt | 4 ++-- .pre-commit-config.yaml | 4 ++-- pyproject.toml | 6 ------ src/molecule/command/idempotence.py | 6 +----- src/molecule/console.py | 4 +--- tests/unit/driver/test_delegated.py | 18 +++++++++--------- tests/unit/provisioner/test_ansible.py | 6 +++--- .../unit/provisioner/test_ansible_playbook.py | 4 ++-- tests/unit/test_config.py | 4 ++-- tests/unit/test_scenario.py | 16 ++++++++-------- tests/unit/test_scenarios.py | 2 +- tests/unit/test_util.py | 18 +++++++++--------- tests/unit/verifier/test_ansible.py | 4 ++-- tests/unit/verifier/test_testinfra.py | 2 +- 14 files changed, 43 insertions(+), 55 deletions(-) diff --git a/.config/constraints.txt b/.config/constraints.txt index 9fb52c073..9289dee0a 100644 --- a/.config/constraints.txt +++ b/.config/constraints.txt @@ -89,7 +89,7 @@ pluggy==1.5.0 pre-commit==3.7.1 ptyprocess==0.7.0 pycparser==2.22 -pydoclint==0.5.1 +pydoclint==0.5.3 pygments==2.18.0 pylint==3.2.4 pymdown-extensions==10.8.1 @@ -113,7 +113,7 @@ rich==13.7.1 rpds-py==0.18.1 ruamel-yaml==0.18.6 ruamel-yaml-clib==0.2.8 -ruff==0.4.10 +ruff==0.5.0 six==1.16.0 soupsieve==2.5 subprocess-tee==0.4.2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 22eb437d2..526564390 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -59,7 +59,7 @@ repos: - id: tox-ini-fmt - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.10 + rev: v0.5.0 hooks: - id: ruff args: @@ -72,7 +72,7 @@ repos: name: Spell check with cspell - repo: https://github.com/jsh9/pydoclint - rev: 0.5.1 + rev: 0.5.3 hooks: - id: pydoclint # This allows automatic reduction of the baseline file when needed. diff --git a/pyproject.toml b/pyproject.toml index be0d37273..6eab3a2b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -348,17 +348,11 @@ verbosity_assertions = 2 [tool.ruff] builtins = ["__"] cache-dir = "./.cache/.ruff" -external = [ - "DOC" # pydoclint -] fix = true line-length = 100 target-version = "py310" [tool.ruff.lint] -extend-ignore = [ - "ANN101" # missing-type-self (deprecated) -] select = ["ALL"] [tool.ruff.lint.flake8-pytest-style] diff --git a/src/molecule/command/idempotence.py b/src/molecule/command/idempotence.py index aac8b458f..f26fa3a35 100644 --- a/src/molecule/command/idempotence.py +++ b/src/molecule/command/idempotence.py @@ -71,11 +71,7 @@ def _is_idempotent(self, output): # type: ignore[no-untyped-def] # noqa: ANN00 # Look for any non-zero changed lines changed = re.search(r"(changed=[1-9][0-9]*)", output) - if changed: - # Not idempotent - return False - - return True + return not bool(changed) def _non_idempotent_tasks(self, output): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202 """Parse the output to identify the non idempotent tasks. diff --git a/src/molecule/console.py b/src/molecule/console.py index 62571c824..034e43ac5 100644 --- a/src/molecule/console.py +++ b/src/molecule/console.py @@ -36,9 +36,7 @@ def to_bool(a: Any) -> bool: # noqa: ANN401 return bool(a) if isinstance(a, str): a = a.lower() - if a in ("yes", "on", "1", "true", 1): - return True - return False + return a in ("yes", "on", "1", "true", 1) def should_do_markup() -> bool: diff --git a/tests/unit/driver/test_delegated.py b/tests/unit/driver/test_delegated.py index d913e83f9..8bfe5e607 100644 --- a/tests/unit/driver/test_delegated.py +++ b/tests/unit/driver/test_delegated.py @@ -63,10 +63,10 @@ def test_delegated_config_private_member(_instance): # type: ignore[no-untyped- def test_delegated_options_property2(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert { + assert _instance.testinfra_options == { "connection": "ansible", "ansible-inventory": _instance._config.provisioner.inventory_directory, - } == _instance.testinfra_options + } def test_delegated_name_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 @@ -118,11 +118,11 @@ def test_login_cmd_template_property_when_managed(_instance): # type: ignore[no def test_safe_files_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert [] == _instance.safe_files + assert _instance.safe_files == [] def test_default_safe_files_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert [] == _instance.default_safe_files + assert _instance.default_safe_files == [] def test_delegated_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 @@ -139,7 +139,7 @@ def test_managed_property(_instance): # type: ignore[no-untyped-def] # noqa: A indirect=True, ) def test_default_ssh_connection_options_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert [] == _instance.default_ssh_connection_options + assert _instance.default_ssh_connection_options == [] @pytest.mark.parametrize( @@ -167,7 +167,7 @@ def test_default_ssh_connection_options_property_when_managed(_instance): # typ indirect=True, ) def test_login_options(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert {"instance": "foo"} == _instance.login_options("foo") + assert _instance.login_options("foo") == {"instance": "foo"} @pytest.mark.parametrize( @@ -281,7 +281,7 @@ def test_ansible_connection_options_handles_missing_instance_config_managed( # m = mocker.patch("molecule.util.safe_load_file") m.side_effect = IOError - assert {} == _instance.ansible_connection_options("foo") + assert _instance.ansible_connection_options("foo") == {} def test_ansible_connection_options_handles_missing_results_key_when_managed( # type: ignore[no-untyped-def] # noqa: ANN201, D103 @@ -291,7 +291,7 @@ def test_ansible_connection_options_handles_missing_results_key_when_managed( # m = mocker.patch("molecule.util.safe_load_file") m.side_effect = StopIteration - assert {} == _instance.ansible_connection_options("foo") + assert _instance.ansible_connection_options("foo") == {} def test_instance_config_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 @@ -309,7 +309,7 @@ def test_instance_config_property(_instance): # type: ignore[no-untyped-def] # indirect=True, ) def test_ssh_connection_options_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert [] == _instance.ssh_connection_options + assert _instance.ssh_connection_options == [] def test_status(mocker: MockerFixture, _instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, ARG001, D103 diff --git a/tests/unit/provisioner/test_ansible.py b/tests/unit/provisioner/test_ansible.py index c71cd7adf..c7ff56878 100644 --- a/tests/unit/provisioner/test_ansible.py +++ b/tests/unit/provisioner/test_ansible.py @@ -130,7 +130,7 @@ def test_default_config_options_property(instance): # type: ignore[no-untyped-d def test_provisioner_default_options_property(instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, D103 - assert {"skip-tags": "molecule-notest,notest"} == instance.default_options + assert instance.default_options == {"skip-tags": "molecule-notest,notest"} def test_ansible_default_env_property(instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, D103 @@ -192,7 +192,7 @@ def test_ansible_options_property_does_not_merge(instance): # type: ignore[no-u for action in ["create", "destroy"]: instance._config.action = action - assert {"skip-tags": "molecule-notest,notest"} == instance.options + assert instance.options == {"skip-tags": "molecule-notest,notest"} def test_provisioner_ansible_options_property_handles_cli_args(instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, D103 @@ -300,7 +300,7 @@ def test_hosts_property(instance): # type: ignore[no-untyped-def] # noqa: ANN0 def test_links_property(instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, D103 - assert {} == instance.links + assert instance.links == {} def test_inventory_directory_property(instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, D103 diff --git a/tests/unit/provisioner/test_ansible_playbook.py b/tests/unit/provisioner/test_ansible_playbook.py index defdcdc3d..643120052 100644 --- a/tests/unit/provisioner/test_ansible_playbook.py +++ b/tests/unit/provisioner/test_ansible_playbook.py @@ -258,10 +258,10 @@ def test_executes_catches_and_exits_return_code( # type: ignore[no-untyped-def] def test_add_cli_arg(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert {} == _instance._cli + assert _instance._cli == {} _instance.add_cli_arg("foo", "bar") - assert {"foo": "bar"} == _instance._cli + assert _instance._cli == {"foo": "bar"} def test_add_env_arg(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index 8c115fcbe..2f5cb0a56 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -31,7 +31,7 @@ def test_args_member(config_instance: config.Config): # type: ignore[no-untyped-def] # noqa: ANN201, D103 - assert {} == config_instance.args + assert config_instance.args == {} def test_command_args_member(config_instance: config.Config): # type: ignore[no-untyped-def] # noqa: ANN201, D103 @@ -344,7 +344,7 @@ def test_set_env_from_file_returns_original_env_when_env_file_not_found( # type ): env = config.set_env_from_file({}, "file-not-found") - assert {} == env + assert env == {} def test_write_config(config_instance: config.Config): # type: ignore[no-untyped-def] # noqa: ANN201, D103 diff --git a/tests/unit/test_scenario.py b/tests/unit/test_scenario.py index 433638879..b81718da1 100644 --- a/tests/unit/test_scenario.py +++ b/tests/unit/test_scenario.py @@ -129,27 +129,27 @@ def test_create_sequence_property(_instance): # type: ignore[no-untyped-def] # def test_dependency_sequence_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert ["dependency"] == _instance.dependency_sequence + assert _instance.dependency_sequence == ["dependency"] def test_destroy_sequence_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert ["dependency", "cleanup", "destroy"] == _instance.destroy_sequence + assert _instance.destroy_sequence == ["dependency", "cleanup", "destroy"] def test_idempotence_sequence_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert ["idempotence"] == _instance.idempotence_sequence + assert _instance.idempotence_sequence == ["idempotence"] def test_prepare_sequence_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert ["prepare"] == _instance.prepare_sequence + assert _instance.prepare_sequence == ["prepare"] def test_side_effect_sequence_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert ["side_effect"] == _instance.side_effect_sequence + assert _instance.side_effect_sequence == ["side_effect"] def test_syntax_sequence_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert ["syntax"] == _instance.syntax_sequence + assert _instance.syntax_sequence == ["syntax"] def test_test_sequence_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 @@ -172,13 +172,13 @@ def test_test_sequence_property(_instance): # type: ignore[no-untyped-def] # n def test_verify_sequence_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert ["verify"] == _instance.verify_sequence + assert _instance.verify_sequence == ["verify"] def test_sequence_property_with_invalid_subcommand(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 _instance.config.command_args = {"subcommand": "invalid"} - assert [] == _instance.sequence + assert _instance.sequence == [] def test_setup_creates_ephemeral_and_inventory_directories(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 diff --git a/tests/unit/test_scenarios.py b/tests/unit/test_scenarios.py index 6cec4bbbd..72304017c 100644 --- a/tests/unit/test_scenarios.py +++ b/tests/unit/test_scenarios.py @@ -134,7 +134,7 @@ def test_filter_for_scenario(_instance): # type: ignore[no-untyped-def] # noqa _instance._scenario_name = "invalid" result = _instance._filter_for_scenario() - assert [] == result + assert result == [] def test_get_matrix(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py index 2d5087c41..628c49725 100644 --- a/tests/unit/test_util.py +++ b/tests/unit/test_util.py @@ -237,11 +237,11 @@ def test_safe_dump_with_increase_indent(): # type: ignore[no-untyped-def] # no def test_safe_load() -> None: # noqa: D103 - assert {"foo": "bar"} == util.safe_load("foo: bar") + assert util.safe_load("foo: bar") == {"foo": "bar"} def test_safe_load_returns_empty_dict_on_empty_string() -> None: # noqa: D103 - assert {} == util.safe_load("") + assert util.safe_load("") == {} def test_safe_load_exits_when_cannot_parse() -> None: # noqa: D103 @@ -265,7 +265,7 @@ def test_safe_load_file(test_cache_path: Path) -> None: path = test_cache_path / "test_safe_load_file.yml" util.write_file(str(path), "foo: bar") - assert {"foo": "bar"} == util.safe_load_file(str(path)) + assert util.safe_load_file(str(path)) == {"foo": "bar"} def test_instance_with_scenario_name() -> None: # noqa: D103 @@ -275,25 +275,25 @@ def test_instance_with_scenario_name() -> None: # noqa: D103 def test_verbose_flag() -> None: # noqa: D103 options = {"verbose": True, "v": True} - assert ["-v"] == util.verbose_flag(options) # type: ignore[no-untyped-call] + assert util.verbose_flag(options) == ["-v"] # type: ignore[no-untyped-call] # pylint: disable=use-implicit-booleaness-not-comparison - assert {} == options + assert options == {} def test_verbose_flag_extra_verbose() -> None: # noqa: D103 options = {"verbose": True, "vvv": True} - assert ["-vvv"] == util.verbose_flag(options) # type: ignore[no-untyped-call] + assert util.verbose_flag(options) == ["-vvv"] # type: ignore[no-untyped-call] # pylint: disable=use-implicit-booleaness-not-comparison - assert {} == options + assert options == {} def test_verbose_flag_preserves_verbose_option() -> None: # noqa: D103 options = {"verbose": True} # pylint: disable=use-implicit-booleaness-not-comparison - assert [] == util.verbose_flag(options) # type: ignore[no-untyped-call] - assert {"verbose": True} == options + assert util.verbose_flag(options) == [] # type: ignore[no-untyped-call] + assert options == {"verbose": True} def test_filter_verbose_permutation() -> None: # noqa: D103 diff --git a/tests/unit/verifier/test_ansible.py b/tests/unit/verifier/test_ansible.py index 0813caf54..b9535bcd3 100644 --- a/tests/unit/verifier/test_ansible.py +++ b/tests/unit/verifier/test_ansible.py @@ -36,7 +36,7 @@ def test_verifier_config_private_member(_instance): # type: ignore[no-untyped-d def test_verifier_default_options_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 - assert {} == _instance.default_options + assert _instance.default_options == {} def test_verifier_ansible_default_env_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 @@ -66,7 +66,7 @@ def test_ansible_enabled_property(_instance): # type: ignore[no-untyped-def] # def test_verifier_directory_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 parts = _instance.directory.split(os.path.sep) # Unused by Ansible verifier - assert ["molecule", "default", "tests"] == parts[-3:] + assert parts[-3:] == ["molecule", "default", "tests"] @pytest.mark.parametrize( diff --git a/tests/unit/verifier/test_testinfra.py b/tests/unit/verifier/test_testinfra.py index 3163954a8..72ab33187 100644 --- a/tests/unit/verifier/test_testinfra.py +++ b/tests/unit/verifier/test_testinfra.py @@ -161,7 +161,7 @@ def test_testinfra_enabled_property(_instance): # type: ignore[no-untyped-def] def test_testinfra_directory_property(_instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103 parts = _instance.directory.split(os.path.sep) - assert ["molecule", "default", "tests"] == parts[-3:] + assert parts[-3:] == ["molecule", "default", "tests"] @pytest.fixture()