Skip to content

Commit 23928fb

Browse files
authored
chore(linters): Apply ruff-format (#861)
1 parent e5f4170 commit 23928fb

File tree

6 files changed

+44
-30
lines changed

6 files changed

+44
-30
lines changed

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 & 9 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',
@@ -51,8 +57,9 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
5157

5258
dirs: list[str] = []
5359
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"))):
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
@@ -64,13 +71,14 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
6471
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('./{dir}'.format(dir=dir))
6875
procArgs.append('>')
6976
procArgs.append(
70-
'./{dir}/{dest}'.
71-
format(dir=dir, dest=cast_to(bool, parsed_cli_args.dest)),
77+
'./{dir}/{dest}'.format(
78+
dir=dir, dest=cast_to(bool, parsed_cli_args.dest)
79+
),
7280
)
73-
subprocess.check_call(" ".join(procArgs), shell=True)
81+
subprocess.check_call(' '.join(procArgs), shell=True)
7482
except subprocess.CalledProcessError as e:
7583
print(e)
7684
retval = ReturnCode.ERROR

tests/pytest/_cli_test.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -72,15 +74,17 @@ def invoke_cli_app(self, parsed_cli_args: Namespace) -> ReturnCodeType:
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: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ def test_arg_parser_populated() -> None:
2424
def test_check_is_deprecated() -> None:
2525
"""Verify that `replace-docs` shows a deprecation warning."""
2626
deprecation_msg_regex = (
27-
r'^`terraform_docs_replace` hook is DEPRECATED\.'
28-
'For migration.*$'
27+
r'^`terraform_docs_replace` hook is DEPRECATED\.For migration.*$'
2928
)
3029
with pytest.warns(UserWarning, match=deprecation_msg_regex):
3130
# not `pytest.deprecated_call()` due to this being a user warning
@@ -70,10 +69,10 @@ def test_check_is_deprecated() -> None:
7069
'pre_commit_terraform.terraform_docs_replace',
7170
)
7271
def test_control_flow_positive(
73-
expected_cmds: list[str],
74-
mocker: pytest_mock.MockerFixture,
75-
monkeypatch: pytest.MonkeyPatch,
76-
parsed_cli_args: Namespace,
72+
expected_cmds: list[str],
73+
mocker: pytest_mock.MockerFixture,
74+
monkeypatch: pytest.MonkeyPatch,
75+
parsed_cli_args: Namespace,
7776
) -> None:
7877
"""Check that the subcommand's happy path works."""
7978
check_call_mock = mocker.Mock()
@@ -86,7 +85,7 @@ def test_control_flow_positive(
8685
assert ReturnCode.OK == invoke_cli_app(parsed_cli_args)
8786

8887
executed_commands = [
89-
cmd for ((cmd, ), _shell) in check_call_mock.call_args_list
88+
cmd for ((cmd,), _shell) in check_call_mock.call_args_list
9089
]
9190

9291
assert len(expected_cmds) == check_call_mock.call_count
@@ -98,8 +97,8 @@ def test_control_flow_positive(
9897
'pre_commit_terraform.terraform_docs_replace',
9998
)
10099
def test_control_flow_negative(
101-
mocker: pytest_mock.MockerFixture,
102-
monkeypatch: pytest.MonkeyPatch,
100+
mocker: pytest_mock.MockerFixture,
101+
monkeypatch: pytest.MonkeyPatch,
103102
) -> None:
104103
"""Check that the subcommand's error processing works."""
105104
parsed_cli_args = Namespace(

0 commit comments

Comments
 (0)