Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/pre_commit_terraform/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,32 @@ def invoke_cli_app(cli_args: list[str]) -> ReturnCodeType:
root_cli_parser = initialize_argument_parser()
parsed_cli_args = root_cli_parser.parse_args(cli_args)
invoke_cli_app = cast_to(
# FIXME: attempt typing per https://stackoverflow.com/a/75666611/595220
# FIXME: attempt typing per https://stackoverflow.com/a/75666611/595220 # noqa: TD001, TD002, TD003, FIX001, E501 All these suppressions caused by "FIXME" comment
'CLIAppEntryPointCallableType',
parsed_cli_args.invoke_cli_app,
)

try:
return invoke_cli_app(parsed_cli_args)
except PreCommitTerraformExit as exit_err:
print(f'App exiting: {exit_err !s}', file=sys.stderr)
# T201 - FIXME here and below - we will replace 'print' with logging later
Copy link
Copy Markdown
Collaborator Author

@MaxymVlasov MaxymVlasov Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need issue for it, as logging already implemented in different branch, so it will be set right after we finally add all ruff-related changes

print(f'App exiting: {exit_err !s}', file=sys.stderr) # noqa: T201
raise
except PreCommitTerraformRuntimeError as unhandled_exc:
print(
print( # noqa: T201
f'App execution took an unexpected turn: {unhandled_exc !s}. '
'Exiting...',
file=sys.stderr,
)
return ReturnCode.ERROR
except PreCommitTerraformBaseError as unhandled_exc:
print(
print( # noqa: T201
f'A surprising exception happened: {unhandled_exc !s}. Exiting...',
file=sys.stderr,
)
return ReturnCode.ERROR
except KeyboardInterrupt as ctrl_c_exc:
print(
print( # noqa: T201
f'User-initiated interrupt: {ctrl_c_exc !s}. Exiting...',
file=sys.stderr,
)
Expand Down
5 changes: 4 additions & 1 deletion src/pre_commit_terraform/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ class PreCommitTerraformRuntimeError(
"""An exception representing a runtime error condition."""


class PreCommitTerraformExit(PreCommitTerraformBaseError, SystemExit):
# N818 - The name mimics the built-in SystemExit and is meant to have exactly
# the same semantics. For this reason, it shouldn't have Error in the name to
# maintain resemblance.
class PreCommitTerraformExit(PreCommitTerraformBaseError, SystemExit): # noqa: N818
"""An exception for terminating execution from deep app layers."""
15 changes: 11 additions & 4 deletions src/pre_commit_terraform/terraform_docs_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
if os.path.realpath(filename) not in dirs and (
filename.endswith(('.tf', '.tfvars'))
):
dirs.append(os.path.dirname(filename))
# PTH120 - It should use 'pathlib', but this hook is deprecated and
# we don't want to spent time on testing fixes for it
dirs.append(os.path.dirname(filename)) # noqa: PTH120

retval = ReturnCode.OK

Expand All @@ -89,8 +91,13 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
),
),
)
subprocess.check_call(' '.join(proc_args), shell=True)
except subprocess.CalledProcessError as e:
print(e)
# S602 - 'shell=True' is insecure, but this hook is deprecated and
# we don't want to spent time on testing fixes for it
subprocess.check_call(' '.join(proc_args), shell=True) # noqa: S602
# PERF203 - try-except shouldn't be in a loop, but it's deprecated
# hook, so leave as is
except subprocess.CalledProcessError as e: # noqa: PERF203
# T201 - Leave print statement as is, as this is deprecated hook
print(e) # noqa: T201
retval = ReturnCode.ERROR
return retval
5 changes: 3 additions & 2 deletions tests/pytest/terraform_docs_replace_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,6 @@ def test_control_flow_negative(
)

assert invoke_cli_app(parsed_cli_args) == ReturnCode.ERROR

check_call_mock.assert_called_once_with(expected_cmd, shell=True)
# S604 - 'shell=True' is insecure, but this hook is deprecated and we don't
# want to spent time on testing fixes for it
check_call_mock.assert_called_once_with(expected_cmd, shell=True) # noqa: S604
Loading