Skip to content

Commit

Permalink
Cleaup ruff config with latest version (#4243)
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
cidrblock and pre-commit-ci[bot] committed Jun 27, 2024
1 parent 033910c commit e104ebf
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .config/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down
6 changes: 0 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 1 addition & 5 deletions src/molecule/command/idempotence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions src/molecule/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/driver/test_delegated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/provisioner/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/provisioner/test_ansible_playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/verifier/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/verifier/test_testinfra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e104ebf

Please sign in to comment.