Skip to content

Commit 4f544c6

Browse files
committed
chore(linters): Apply ruff autofixes
1 parent e5f4170 commit 4f544c6

File tree

8 files changed

+55
-40
lines changed

8 files changed

+55
-40
lines changed

src/pre_commit_terraform/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""A runpy-style CLI entry-point module."""
22

3-
from sys import argv, exit as exit_with_return_code
3+
from sys import argv
4+
from sys import exit as exit_with_return_code
45

56
from ._cli import invoke_cli_app
67

src/pre_commit_terraform/_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def invoke_cli_app(cli_args: list[str]) -> ReturnCodeType:
2323
parsed_cli_args = root_cli_parser.parse_args(cli_args)
2424
invoke_cli_app = cast_to(
2525
# FIXME: attempt typing per https://stackoverflow.com/a/75666611/595220
26-
CLIAppEntryPointCallableType,
26+
'CLIAppEntryPointCallableType',
2727
parsed_cli_args.invoke_cli_app,
2828
)
2929

src/pre_commit_terraform/_cli_parsing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def attach_subcommand_parsers_to(root_cli_parser: ArgumentParser, /) -> None:
2222
required=True,
2323
)
2424
for subcommand_module in SUBCOMMAND_MODULES:
25-
subcommand_parser = subcommand_parsers.add_parser(subcommand_module.CLI_SUBCOMMAND_NAME)
25+
subcommand_parser = subcommand_parsers.add_parser(
26+
subcommand_module.CLI_SUBCOMMAND_NAME,
27+
)
2628
subcommand_parser.set_defaults(
2729
invoke_cli_app=subcommand_module.invoke_cli_app,
2830
)

src/pre_commit_terraform/_errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class PreCommitTerraformBaseError(Exception):
66

77

88
class PreCommitTerraformRuntimeError(
9-
PreCommitTerraformBaseError,
10-
RuntimeError,
9+
PreCommitTerraformBaseError,
10+
RuntimeError,
1111
):
1212
"""An exception representing a runtime error condition."""
1313

src/pre_commit_terraform/_types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class CLISubcommandModuleProtocol(Protocol):
1818
"""This constant contains a CLI."""
1919

2020
def populate_argument_parser(
21-
self, subcommand_parser: ArgumentParser,
21+
self,
22+
subcommand_parser: ArgumentParser,
2223
) -> None:
2324
"""Run a module hook for populating the subcommand parser."""
2425

src/pre_commit_terraform/terraform_docs_replace.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@ def populate_argument_parser(subcommand_parser: ArgumentParser) -> None:
1818
'replace the entire README.md file each time.'
1919
)
2020
subcommand_parser.add_argument(
21-
'--dest', dest='dest', default='README.md',
21+
'--dest',
22+
dest='dest',
23+
default='README.md',
2224
)
2325
subcommand_parser.add_argument(
24-
'--sort-inputs-by-required', dest='sort', action='store_true',
26+
'--sort-inputs-by-required',
27+
dest='sort',
28+
action='store_true',
2529
help='[deprecated] use --sort-by-required instead',
2630
)
2731
subcommand_parser.add_argument(
28-
'--sort-by-required', dest='sort', action='store_true',
32+
'--sort-by-required',
33+
dest='sort',
34+
action='store_true',
2935
)
3036
subcommand_parser.add_argument(
3137
'--with-aggregate-type-defaults',
@@ -50,9 +56,10 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
5056
)
5157

5258
dirs: list[str] = []
53-
for filename in cast_to(list[str], parsed_cli_args.filenames):
54-
if (os.path.realpath(filename) not in dirs and
55-
(filename.endswith(".tf") or filename.endswith(".tfvars"))):
59+
for filename in cast_to('list[str]', parsed_cli_args.filenames):
60+
if os.path.realpath(filename) not in dirs and (
61+
filename.endswith('.tf') or filename.endswith('.tfvars')
62+
):
5663
dirs.append(os.path.dirname(filename))
5764

5865
retval = ReturnCode.OK
@@ -61,16 +68,15 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
6168
try:
6269
procArgs = []
6370
procArgs.append('terraform-docs')
64-
if cast_to(bool, parsed_cli_args.sort):
71+
if cast_to('bool', parsed_cli_args.sort):
6572
procArgs.append('--sort-by-required')
6673
procArgs.append('md')
67-
procArgs.append("./{dir}".format(dir=dir))
74+
procArgs.append(f'./{dir}')
6875
procArgs.append('>')
6976
procArgs.append(
70-
'./{dir}/{dest}'.
71-
format(dir=dir, dest=cast_to(bool, parsed_cli_args.dest)),
77+
f'./{dir}/{cast_to("bool", parsed_cli_args.dest)}',
7278
)
73-
subprocess.check_call(" ".join(procArgs), shell=True)
79+
subprocess.check_call(' '.join(procArgs), shell=True)
7480
except subprocess.CalledProcessError as e:
7581
print(e)
7682
retval = ReturnCode.ERROR

tests/pytest/_cli_test.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""Tests for the high-level CLI entry point."""
22

33
from argparse import ArgumentParser, Namespace
4-
import pytest
54

5+
import pytest
66
from pre_commit_terraform import _cli_parsing as _cli_parsing_mod
77
from pre_commit_terraform._cli import invoke_cli_app
88
from pre_commit_terraform._errors import (
9-
PreCommitTerraformExit,
109
PreCommitTerraformBaseError,
10+
PreCommitTerraformExit,
1111
PreCommitTerraformRuntimeError,
1212
)
1313
from pre_commit_terraform._structs import ReturnCode
@@ -42,17 +42,19 @@
4242
),
4343
)
4444
def test_known_interrupts(
45-
capsys: pytest.CaptureFixture[str],
46-
expected_stderr: str,
47-
monkeypatch: pytest.MonkeyPatch,
48-
raised_error: BaseException,
45+
capsys: pytest.CaptureFixture[str],
46+
expected_stderr: str,
47+
monkeypatch: pytest.MonkeyPatch,
48+
raised_error: BaseException,
4949
) -> None:
5050
"""Check that known interrupts are turned into return code 1."""
51+
5152
class CustomCmdStub:
5253
CLI_SUBCOMMAND_NAME = 'sentinel'
5354

5455
def populate_argument_parser(
55-
self, subcommand_parser: ArgumentParser,
56+
self,
57+
subcommand_parser: ArgumentParser,
5658
) -> None:
5759
return None
5860

@@ -65,22 +67,24 @@ def invoke_cli_app(self, parsed_cli_args: Namespace) -> ReturnCodeType:
6567
[CustomCmdStub()],
6668
)
6769

68-
assert ReturnCode.ERROR == invoke_cli_app(['sentinel'])
70+
assert invoke_cli_app(['sentinel']) == ReturnCode.ERROR
6971

7072
captured_outputs = capsys.readouterr()
7173
assert captured_outputs.err == f'{expected_stderr !s}\n'
7274

7375

7476
def test_app_exit(
75-
capsys: pytest.CaptureFixture[str],
76-
monkeypatch: pytest.MonkeyPatch,
77+
capsys: pytest.CaptureFixture[str],
78+
monkeypatch: pytest.MonkeyPatch,
7779
) -> None:
7880
"""Check that an exit exception is re-raised."""
81+
7982
class CustomCmdStub:
8083
CLI_SUBCOMMAND_NAME = 'sentinel'
8184

8285
def populate_argument_parser(
83-
self, subcommand_parser: ArgumentParser,
86+
self,
87+
subcommand_parser: ArgumentParser,
8488
) -> None:
8589
return None
8690

tests/pytest/terraform_docs_replace_test.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
from argparse import ArgumentParser, Namespace
44
from subprocess import CalledProcessError
55

6-
import pytest
76
import pytest_mock
87

8+
import pytest
99
from pre_commit_terraform._structs import ReturnCode
1010
from pre_commit_terraform.terraform_docs_replace import (
1111
invoke_cli_app,
1212
populate_argument_parser,
13+
)
14+
from pre_commit_terraform.terraform_docs_replace import (
1315
subprocess as replace_docs_subprocess_mod,
1416
)
1517

@@ -24,8 +26,7 @@ def test_arg_parser_populated() -> None:
2426
def test_check_is_deprecated() -> None:
2527
"""Verify that `replace-docs` shows a deprecation warning."""
2628
deprecation_msg_regex = (
27-
r'^`terraform_docs_replace` hook is DEPRECATED\.'
28-
'For migration.*$'
29+
r'^`terraform_docs_replace` hook is DEPRECATED\.' 'For migration.*$'
2930
)
3031
with pytest.warns(UserWarning, match=deprecation_msg_regex):
3132
# not `pytest.deprecated_call()` due to this being a user warning
@@ -70,10 +71,10 @@ def test_check_is_deprecated() -> None:
7071
'pre_commit_terraform.terraform_docs_replace',
7172
)
7273
def test_control_flow_positive(
73-
expected_cmds: list[str],
74-
mocker: pytest_mock.MockerFixture,
75-
monkeypatch: pytest.MonkeyPatch,
76-
parsed_cli_args: Namespace,
74+
expected_cmds: list[str],
75+
mocker: pytest_mock.MockerFixture,
76+
monkeypatch: pytest.MonkeyPatch,
77+
parsed_cli_args: Namespace,
7778
) -> None:
7879
"""Check that the subcommand's happy path works."""
7980
check_call_mock = mocker.Mock()
@@ -83,10 +84,10 @@ def test_control_flow_positive(
8384
check_call_mock,
8485
)
8586

86-
assert ReturnCode.OK == invoke_cli_app(parsed_cli_args)
87+
assert invoke_cli_app(parsed_cli_args) == ReturnCode.OK
8788

8889
executed_commands = [
89-
cmd for ((cmd, ), _shell) in check_call_mock.call_args_list
90+
cmd for ((cmd,), _shell) in check_call_mock.call_args_list
9091
]
9192

9293
assert len(expected_cmds) == check_call_mock.call_count
@@ -98,8 +99,8 @@ def test_control_flow_positive(
9899
'pre_commit_terraform.terraform_docs_replace',
99100
)
100101
def test_control_flow_negative(
101-
mocker: pytest_mock.MockerFixture,
102-
monkeypatch: pytest.MonkeyPatch,
102+
mocker: pytest_mock.MockerFixture,
103+
monkeypatch: pytest.MonkeyPatch,
103104
) -> None:
104105
"""Check that the subcommand's error processing works."""
105106
parsed_cli_args = Namespace(
@@ -118,6 +119,6 @@ def test_control_flow_negative(
118119
check_call_mock,
119120
)
120121

121-
assert ReturnCode.ERROR == invoke_cli_app(parsed_cli_args)
122+
assert invoke_cli_app(parsed_cli_args) == ReturnCode.ERROR
122123

123124
check_call_mock.assert_called_once_with(expected_cmd, shell=True)

0 commit comments

Comments
 (0)