Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7e1dd4f
chore(linters): Introduce ruff and fix issues
MaxymVlasov Feb 27, 2025
9430c1a
Merge branch 'master' into introduce_ruff
MaxymVlasov Mar 25, 2025
8dc8451
Apply review suggestions
MaxymVlasov Mar 25, 2025
8c3d385
Address review suggestions
MaxymVlasov Mar 25, 2025
53bb73f
Address review suggestions
MaxymVlasov Mar 25, 2025
8831b60
decrease diff
MaxymVlasov Mar 25, 2025
665d46c
Adress review comments
MaxymVlasov Mar 25, 2025
87273be
Discard changes to tests/pytest/terraform_docs_replace_test.py
MaxymVlasov Mar 25, 2025
fa302b0
Discard changes to src/pre_commit_terraform/terraform_docs_replace.py
MaxymVlasov Mar 25, 2025
f74ef59
Disable ruff for deprecated hook
MaxymVlasov Mar 25, 2025
e3c1272
Discard changes to src/pre_commit_terraform/__main__.py
MaxymVlasov Mar 25, 2025
71e794e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 25, 2025
b309d69
Address review suggestions and DOC501
MaxymVlasov Mar 25, 2025
948a36d
fix tests
MaxymVlasov Mar 25, 2025
7765818
Merge branch 'master' into introduce_ruff
MaxymVlasov Mar 26, 2025
51d9a93
Merge branch 'master' into introduce_ruff
MaxymVlasov Mar 26, 2025
bd24ee0
Merge branch 'master' into introduce_ruff
MaxymVlasov Mar 26, 2025
8384a66
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 26, 2025
460031a
Merge branch 'master' into introduce_ruff
MaxymVlasov Mar 27, 2025
49f5087
Merge branch 'master' into introduce_ruff
MaxymVlasov Apr 3, 2025
593fe3d
Implement review suggestions and fix leftovers
MaxymVlasov Apr 3, 2025
585571d
fix tests by reverting PTH120
MaxymVlasov Apr 3, 2025
28aad2b
Merge branch 'master' into introduce_ruff
MaxymVlasov Apr 3, 2025
c6cd747
Discard changes to .gitignore
MaxymVlasov Apr 4, 2025
a6c9b5f
Address review suggestions regarding S404
MaxymVlasov Apr 4, 2025
641399c
fix violations
MaxymVlasov Apr 4, 2025
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
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ repos:
- id: shellcheck

# Python
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
Comment thread
MaxymVlasov marked this conversation as resolved.
exclude: /terraform_docs_replace(_test)?\.py$
Comment thread
MaxymVlasov marked this conversation as resolved.
Outdated

- repo: https://github.com/pre-commit/mirrors-mypy.git
rev: v1.15.0
hooks:
Expand Down
39 changes: 39 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Assume Python 3.9
target-version = "py39"

line-length = 79 # To decrease PR diff size

namespace-packages = ["src/pre_commit_terraform/", "tests/pytest/"]

[format]
quote-style = "single"

[lint.flake8-quotes]
inline-quotes = "single"

[lint.pydocstyle]
convention = "pep257"

[lint]
select = ["ALL"]
preview = true
ignore = [
"CPY001", # Missing copyright notice at top of file
]

[lint.isort]
# force-single-line = true # To decrease PR diff size
lines-after-imports = 2

[lint.flake8-pytest-style]
parametrize-values-type = "tuple"

[lint.per-file-ignores]
# Ignore in the `tests/` directory.
"tests/**.py" = [
"S101", # Use of `assert` detected
"PLC2701", # We need import marked as internal files for testing
]

"src/pre_commit_terraform/terraform_docs_replace.py" = ["ALL"] # Deprecated hook
"tests/pytest/terraform_docs_replace_test.py" = ["ALL"] # Tests for deprecated hook
Comment thread
MaxymVlasov marked this conversation as resolved.
Outdated
13 changes: 8 additions & 5 deletions src/pre_commit_terraform/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,38 @@ def invoke_cli_app(cli_args: list[str]) -> ReturnCodeType:

Returns:
ReturnCodeType: The return code of the app.
Comment thread
MaxymVlasov marked this conversation as resolved.

Raises:
PreCommitTerraformExit: If the app is exiting with error.
"""
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
Comment thread
MaxymVlasov marked this conversation as resolved.
Outdated
Comment thread
MaxymVlasov marked this conversation as resolved.
Outdated
'CLIAppEntryPointCallableType',
Comment thread
MaxymVlasov marked this conversation as resolved.
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)
print(f'App exiting: {exit_err !s}', file=sys.stderr) # noqa: T201 FIXME
raise
except PreCommitTerraformRuntimeError as unhandled_exc:
print(
print( # noqa: T201 FIXME
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 FIXME
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 FIXME
f'User-initiated interrupt: {ctrl_c_exc !s}. Exiting...',
file=sys.stderr,
)
Expand Down
2 changes: 1 addition & 1 deletion src/pre_commit_terraform/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ class PreCommitTerraformRuntimeError(
"""An exception representing a runtime error condition."""


class PreCommitTerraformExit(PreCommitTerraformBaseError, SystemExit):
class PreCommitTerraformExit(PreCommitTerraformBaseError, SystemExit): # noqa: N818 FIXME
Comment thread
MaxymVlasov marked this conversation as resolved.
Outdated
"""An exception for terminating execution from deep app layers."""
15 changes: 9 additions & 6 deletions tests/pytest/_cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def test_known_interrupts(
class CustomCmdStub:
CLI_SUBCOMMAND_NAME = 'sentinel'

def populate_argument_parser(
def populate_argument_parser( # noqa: PLR6301
Comment thread
MaxymVlasov marked this conversation as resolved.
Outdated
self,
subcommand_parser: ArgumentParser,
subcommand_parser: ArgumentParser, # noqa: ARG002
) -> None:
return None

def invoke_cli_app(self, parsed_cli_args: Namespace) -> ReturnCodeType:
def invoke_cli_app(self, parsed_cli_args: Namespace) -> ReturnCodeType: # noqa: PLR6301, ARG002
raise raised_error

monkeypatch.setattr(
Expand All @@ -81,13 +81,16 @@ def test_app_exit(
class CustomCmdStub:
CLI_SUBCOMMAND_NAME = 'sentinel'

def populate_argument_parser(
def populate_argument_parser( # noqa: PLR6301
self,
subcommand_parser: ArgumentParser,
subcommand_parser: ArgumentParser, # noqa: ARG002
) -> None:
return None

def invoke_cli_app(self, parsed_cli_args: Namespace) -> ReturnCodeType:
def invoke_cli_app(
self,
parsed_cli_args: Namespace, # noqa: ARG002
) -> ReturnCodeType:
raise PreCommitTerraformExit(self.CLI_SUBCOMMAND_NAME)

monkeypatch.setattr(
Expand Down
Loading