Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Backpush to main changes to skeleton of python hooks #741

Draft
wants to merge 72 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
18291bd
feat: new terraform_fmt_v2 with better Windows support
ericfrederich Mar 22, 2024
9409f77
Merge remote-tracking branch 'upstream/master' into windows-support
MaxymVlasov Apr 25, 2024
ef844ce
Merge remote-tracking branch 'upstream/master' into windows-support
MaxymVlasov Apr 26, 2024
806a87a
Add linters andd apply part which not requiers tests
MaxymVlasov Apr 26, 2024
3f3fdd9
Apply suggestions from code review
MaxymVlasov Apr 26, 2024
a37971b
Apply suggestions from code review
MaxymVlasov Apr 26, 2024
85269df
fix mypy andy pylint issues
ericfrederich May 1, 2024
8fbba99
Merge branch 'master' into windows-support
MaxymVlasov Dec 24, 2024
0421801
Add proto of per-dir execution and fix style
MaxymVlasov Dec 26, 2024
1f956dc
Add first PyTests
MaxymVlasov Dec 26, 2024
59b6bac
Separate per_dir_hook logic
MaxymVlasov Dec 26, 2024
79ac415
Add simple tests for per_dir_hook
MaxymVlasov Dec 26, 2024
93cddb7
Fix common issues
MaxymVlasov Dec 26, 2024
0280a60
Fix violations to have "greenfield"
MaxymVlasov Dec 26, 2024
a14589a
Move common funtions to common.py
MaxymVlasov Dec 27, 2024
b1a466c
Rename test file
MaxymVlasov Dec 27, 2024
06d4fc6
dd tests for parse_env_vars
MaxymVlasov Dec 27, 2024
878f5bd
Init tests for parse_cmdline
MaxymVlasov Dec 27, 2024
dae3af2
Mark `get_unique_dirs` as private funtion
MaxymVlasov Dec 27, 2024
f99ca4a
Improve func docs
MaxymVlasov Dec 27, 2024
c254a5b
Decouple `parse_env_vars` from `parse_cmdline` as there much more
MaxymVlasov Dec 27, 2024
0cdbaec
Refactor `parse_env_vars` to make it more readable
MaxymVlasov Dec 27, 2024
e5914e0
Expand env vars. Improve logging
MaxymVlasov Dec 27, 2024
c033767
Implement "colorify" in sligtly different (better?) way
MaxymVlasov Dec 27, 2024
01a5850
Add get_tf_binary_path
MaxymVlasov Dec 27, 2024
c7c8e56
Import all common functions at once
MaxymVlasov Dec 27, 2024
fe92d45
Update linter settings to common project limitations
MaxymVlasov Dec 27, 2024
e010c8a
Split logger logic to separate file
MaxymVlasov Dec 27, 2024
4c459df
Add tests to terraform_fmt
MaxymVlasov Dec 27, 2024
33e1547
Itint terraform_checkov hook
MaxymVlasov Dec 27, 2024
7d9ba2f
Init part of run_hook_on_whole_repo functionality
MaxymVlasov Dec 30, 2024
3a59fe4
Merge branch 'master' into ericfrederich-windows-support-test
MaxymVlasov Dec 30, 2024
7d96f1b
Fix structure to actual in master branch. Fix pytest config
MaxymVlasov Dec 30, 2024
0c267ee
Fully init run_hook_on_whole_repo functional
MaxymVlasov Dec 30, 2024
a3e4252
Polish code and clarify TODOs
MaxymVlasov Dec 30, 2024
db3fefd
Merge branch 'master' into ericfrederich-windows-support-test
MaxymVlasov Dec 30, 2024
00674ef
💅 Introduce a Python CLI app layout
webknjaz Dec 30, 2024
b6aa20b
Add a maintainer's manual into the importable package dir
webknjaz Dec 30, 2024
60f1292
󰑌 Simplify subcommand integration to one place
webknjaz Dec 30, 2024
7dde1df
󰑌 Drop the `__main__` check per Python docs
webknjaz Dec 30, 2024
52cf580
📝 Extend the manual w/ subcommand guide
webknjaz Dec 30, 2024
c03e3fe
Merge remote-tracking branch 'webknjaz/maintenance/python-cli-structu…
MaxymVlasov Dec 30, 2024
aa71534
Merge branch 'master' into rewrite_hooks_on_python
MaxymVlasov Dec 31, 2024
3285431
Fix linter violations
MaxymVlasov Dec 31, 2024
96e44ef
fix(wip): Access `.pre-commit-hooks.yaml` as artifact (#740)
webknjaz Dec 31, 2024
2c8b44b
Clarify and consolidate args parser code
MaxymVlasov Dec 31, 2024
934202f
Disable help as it conflicts with --hook-config
MaxymVlasov Dec 31, 2024
3cbc220
Rewrite checkov hook to new structure and set CLI to hook_id
MaxymVlasov Dec 31, 2024
7e647ad
Rename CLI_SUBCOMMAND_NAME to HOOK_ID as it make more sense and make …
MaxymVlasov Dec 31, 2024
0defc96
Rewrite terraform_fmt_py to new structure
MaxymVlasov Dec 31, 2024
7b3cc6c
Fix pylint violations
MaxymVlasov Dec 31, 2024
f1d8faf
Fix mypy violations
MaxymVlasov Dec 31, 2024
2e54190
Fix most of wemake-python-styleguide violations
MaxymVlasov Dec 31, 2024
1f525fc
Split run_on_whole_repo functions to separate file and mark as internal
MaxymVlasov Dec 31, 2024
79b633e
Mark logger as internal
MaxymVlasov Dec 31, 2024
294cf79
Fix acidental refactoring artifact
MaxymVlasov Dec 31, 2024
f1673ce
Fixing and extend tests for terraform_fmt and terraform_checkov
MaxymVlasov Dec 31, 2024
0e03e68
Fix all tests
MaxymVlasov Dec 31, 2024
83c7a29
Remove not needed pytests imports and add main.py tests
MaxymVlasov Dec 31, 2024
650d90c
Add tests for cli_parsing
MaxymVlasov Dec 31, 2024
8953dd9
Add tests for cli_subcommands
MaxymVlasov Dec 31, 2024
53e2dd0
Add more tests, rename test files to `test_<filename>` pattern
MaxymVlasov Jan 3, 2025
3cf99fd
Add types tests. Deal with pytest TypeError
MaxymVlasov Jan 3, 2025
89e5a45
Use `files` from root args parser to deduplicate args
MaxymVlasov Jan 3, 2025
c2aab92
Drop parts (new hooks) which will requires new release
MaxymVlasov Jan 3, 2025
449d448
Improve naming and help output
MaxymVlasov Jan 3, 2025
ac42c51
Apply suggestions from code review
MaxymVlasov Jan 3, 2025
a278a04
Apply suggestions from code review
MaxymVlasov Jan 3, 2025
0799817
we-make-styleguide requires python 3.10
MaxymVlasov Jan 3, 2025
d3df63b
Discard changes to .github/CONTRIBUTING.md
MaxymVlasov Jan 6, 2025
56ab01e
Apply suggestions from code review
MaxymVlasov Jan 6, 2025
f622b10
Update .pre-commit-config.yaml
MaxymVlasov Jan 6, 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
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
# Skip terraform_tflint which interferes to commit pre-commit auto-fixes
- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: '3.9'
python-version: '3.10'
- name: Execute pre-commit
uses: pre-commit/action@9b88afc9cd57fd75b655d5c71bd38146d07135fe # v2.0.3
env:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
tests/results/*
__pycache__/
*.py[cod]
node_modules/
93 changes: 92 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ repos:

# Dockerfile linter
- repo: https://github.com/hadolint/hadolint
rev: v2.12.1-beta
rev: v2.13.1-beta
hooks:
- id: hadolint
args: [
Expand All @@ -66,3 +66,94 @@ repos:
- id: prettier
# https://prettier.io/docs/en/options.html#parser
files: '.json5$'


##########
# PYTHON #
##########

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
hooks:
- id: ruff
args: [--fix]
types_or: [python, pyi]
- id: ruff-format
types_or: [python, pyi]
args: [--config, format.quote-style = 'single', --config, line-length = 100]
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • I'm not a big fan of deviating from linters' default settings which (default settings) should fit vast majority of devs but instead they would need to switch their habits in pre-commit-terraform repo I guess
  • For the consistency's sake it would make sense to use one single method of defining YAML arrays: either one-line (args: […]) or multiline (as in YAML sequence) and definitely w/o single-line arrays split to multiline please.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also have this sort of comments in a draft review that I haven't yet posted in #743.

On the CLI settings, they should almost never be used not because of the defaults but because any other calls to those tools (like IDE extensions automatically picking them up w/o the user configuring anything) would not consume these settings and will result in different sets of violations reported and different behaviors of tools that aren't linters.

And for consistency, I'd rather enforce yamllint. I can send in my default config separately.

Additionally, the organization of integrations in this config is suboptimal that I'll expand on in the other review.


- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort
args: [--force-single-line, --profile=black]
exclude: |
(?x)
# Uses incorrect indentation in imports in places where it shouldn't
# https://github.com/PyCQA/isort/issues/2315#issuecomment-2566703698
(^tests/pytest/test__cli_subcommands\.py$
)

- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v2.0.4
hooks:
- id: autopep8
args:
- -i
- --max-line-length=100

# Usage: http://pylint.pycqa.org/en/latest/user_guide/message-control.html
- repo: https://github.com/PyCQA/pylint
rev: v3.3.3
hooks:
- id: pylint
args:
- --disable=import-error # E0401. Locally you could not have all imports.
- --disable=fixme # W0511. 'TODO' notations.
- --disable=logging-fstring-interpolation # Conflict with "use a single formatting" WPS323
- --disable=ungrouped-imports # ignore `if TYPE_CHECKING` case. Other do reorder-python-imports
- --disable=R0801 # Similar lines in 2 files. Currently I don't think that it possible to DRY hooks unique files boilerplate

exclude: test_.+\.py$

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.14.1
hooks:
- id: mypy
additional_dependencies:
- types-PyYAML
args: [
--ignore-missing-imports,
--disallow-untyped-calls,
--warn-redundant-casts,
]

- repo: https://github.com/wemake-services/wemake-python-styleguide
rev: 1.0.0
hooks:
- id: wemake-python-styleguide
args:
- --allowed-module-metadata=__all__ # Default to ''
- --max-local-variables=6 # Default to 5
- --max-returns=6 # Default to 5
- --max-imports=15 # Default to 12
Comment on lines +142 to +145
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- --allowed-module-metadata=__all__ # Default to ''
- --max-local-variables=6 # Default to 5
- --max-returns=6 # Default to 5
- --max-imports=15 # Default to 12
- --allowed-module-metadata=__all__ # Defaults to ''
- --max-local-variables=6 # Defaults to 5
- --max-returns=6 # Defaults to 5
- --max-imports=15 # Defaults to 12

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't accept this just yet. It shouldn't even be in this config. See my other comments.

# https://wemake-python-stylegui.de/en/latest/pages/usage/violations/index.html
- --extend-ignore=
E501 <!-- line too long (> 79 characters). Use 100 -->
WPS115 <!-- Found upper-case constant in a class. All occurrences are false positive -->
WPS226 <!-- Found string literal over-use - append > 3 -->


exclude: |
(?x)
# Ignore tests
(^tests/pytest/test_.+\.py$
# Ignore deprecated hook
|^src/pre_commit_terraform/terraform_docs_replace\.py$
)
2 changes: 1 addition & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
name: Terraform docs (overwrite README.md)
description: Overwrite content of README.md with terraform-docs.
require_serial: true
entry: python -Im pre_commit_terraform replace-docs
entry: python -Im pre_commit_terraform terraform_docs_replace
Copy link
Contributor

Choose a reason for hiding this comment

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

Plz, stick to kebab-case CLI arguments. It's rather uncommon to use snake_case in CLIs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

Copy link
Collaborator Author

@MaxymVlasov MaxymVlasov Jan 6, 2025

Choose a reason for hiding this comment

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

I want to maintain one name across everything to not create more entropy.

If hook has named terraform_docs_replace it MUST be called this way everywhere, no matter what.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's the thing — the only place for the hook subcommand name is the constant in the module, not the module itself. terraform_docs_replace.py is just a Python module that backs it, not a hook. The hook name would be terraform-docs-replace. This is a common convention, and the underlying implementation details shouldn't leak into UI/UX.

Here's some discussion in other popular CLI frameworks: fastapi/typer#341

Copy link
Contributor

Choose a reason for hiding this comment

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

Here's some public arguments discussing the ergonomics of having to use Shift-key vs. not, leaning towards kebab-space or no-delimiter:

Do you have many programs on your system that have snake_case CLIs? Could you name a few?

language: python
files: (\.tf)$
exclude: \.terraform/.*$
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
"code-block-style": false
},
"markdown.validate.enabled": true,
"python.analysis.extraPaths": [
"./src"
Copy link
Contributor

Choose a reason for hiding this comment

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

should also check the tests dirs

],
}
4 changes: 4 additions & 0 deletions hatch.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[build.targets.sdist]
include = [
'.pre-commit-hooks.yaml',
'src/',
]

Expand All @@ -8,6 +9,9 @@ packages = [
'src/pre_commit_terraform/',
]

[build.targets.wheel.force-include]
'.pre-commit-hooks.yaml' = 'pre_commit_terraform/_artifacts/.pre-commit-hooks.yaml'
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably just be picked into master directly.


[metadata.hooks.vcs.urls]
'Source Archive' = 'https://github.com/antonbabenko/pre-commit-terraform/archive/{commit_hash}.tar.gz'
'GitHub: repo' = 'https://github.com/antonbabenko/pre-commit-terraform'
Expand Down
11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ build-backend = 'hatchling.build'
name = 'pre-commit-terraform'
classifiers = [
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3 :: Only',
Copy link
Contributor

Choose a reason for hiding this comment

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

It's common to list which environments it's being tested under. And additionally, the most important bit in the metadata would be the requires-python value. The classifiers are for humans to read, but the Python requirement is for the dependency resolver to actually take into account.

'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
]
description = 'Pre-commit hooks for terraform_docs_replace'
dependencies = []
description='Pre-commit hooks for terraform'
dependencies = [
'pyyaml',
]
dynamic = [
'urls',
'version',
Expand Down
5 changes: 5 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pytest]
pythonpath = src
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not needed. And also, I've got a proper config in #742 anyway.


testpaths =
tests/pytest
6 changes: 3 additions & 3 deletions src/pre_commit_terraform/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""A runpy-style CLI entry-point module."""

from sys import argv, exit as exit_with_return_code

from ._cli import invoke_cli_app
from sys import argv
Copy link
Contributor

Choose a reason for hiding this comment

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

This will conflict with a fix in #742 FYI (this specific import is being dropped).

from sys import exit as exit_with_return_code

from pre_commit_terraform._cli import invoke_cli_app

return_code = invoke_cli_app(argv[1:])
exit_with_return_code(return_code)
19 changes: 8 additions & 11 deletions src/pre_commit_terraform/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

from sys import stderr

from ._cli_parsing import initialize_argument_parser
from ._errors import (
PreCommitTerraformBaseError,
PreCommitTerraformExit,
PreCommitTerraformRuntimeError,
)
from ._structs import ReturnCode
from ._types import ReturnCodeType
from pre_commit_terraform._cli_parsing import initialize_argument_parser
from pre_commit_terraform._errors import PreCommitTerraformBaseError
from pre_commit_terraform._errors import PreCommitTerraformExit
from pre_commit_terraform._errors import PreCommitTerraformRuntimeError
from pre_commit_terraform._structs import ReturnCode
from pre_commit_terraform._types import ReturnCodeType


def invoke_cli_app(cli_args: list[str]) -> ReturnCodeType:
Expand All @@ -21,15 +19,14 @@ 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)

try:
try: # noqa: WPS225 - Found too many `except` cases: 4 > 3
MaxymVlasov marked this conversation as resolved.
Show resolved Hide resolved
return parsed_cli_args.invoke_cli_app(parsed_cli_args)
except PreCommitTerraformExit as exit_err:
print(f'App exiting: {exit_err !s}', file=stderr)
raise
except PreCommitTerraformRuntimeError as unhandled_exc:
print(
f'App execution took an unexpected turn: {unhandled_exc !s}. '
'Exiting...',
f'App execution took an unexpected turn: {unhandled_exc !s}. Exiting...',
file=stderr,
)
return ReturnCode.ERROR
Expand Down
61 changes: 56 additions & 5 deletions src/pre_commit_terraform/_cli_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,50 @@

from argparse import ArgumentParser

from ._cli_subcommands import SUBCOMMAND_MODULES
from pre_commit_terraform._cli_subcommands import SUBCOMMAND_MODULES


def populate_common_argument_parser(parser: ArgumentParser) -> None:
"""
Populate the argument parser with the common arguments.

Args:
parser (argparse.ArgumentParser): The argument parser to populate.
Comment on lines +16 to +17
Copy link
Contributor

Choose a reason for hiding this comment

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

This API doc style is non-native to Sphinx. You might have to specify it in .darglint. But beware that darglint is deprecated and its parsing of non-native docstrings is known to be extremely slow. I once debugged it to a single Python file being linted during 11 minutes when I forgot to specify that I wanted the native one.

Here's the native syntax FYI: https://www.sphinx-doc.org/en/master/usage/domains/python.html#info-field-lists.

I haven't checked if WPS replaced darglint w/ something else, it might not be as bad.

Also, with some Sphinx extensions, there shouldn't be a need to duplicate the argument types in docstrings. Plus, since you don't have Sphinx, this is definitely not something you should be spending additional time on. Just describe the args and the return value, omitting the types as it's not worth it.

Copy link
Collaborator Author

@MaxymVlasov MaxymVlasov Jan 6, 2025

Choose a reason for hiding this comment

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

Interesting, what Google use then for docs, if that's not suported by Sphinx
https://google.github.io/styleguide/pyguide.html#383-functions-and-methods

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a custom style that's not enabled by default. It's implemented by the napoleon extension: https://sphinxcontrib-napoleon.rtfd.io / https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html.

"""
parser.add_argument(
'-a',
'--args',
action='append',
help='Arguments that configure wrapped tool behavior',
default=[],
)
parser.add_argument(
'-h',
'--hook-config',
action='append',
metavar='KEY=VALUE',
help='Arguments that configure hook behavior',
default=[],
)
parser.add_argument(
'-i',
'--tf-init-args',
'--init-args',
action='append',
help='Arguments for `tf init` command',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
help='Arguments for `tf init` command',
help='Arguments to `terraform init` command',

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There could be not only terraform, but tofu, terraform-alpha-1.11.2025.99.99 etc

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then let's abstract the name, like f.e.:

Suggested change
help='Arguments for `tf init` command',
help="Arguments to tool's `init` sub-command",

default=[],
)
parser.add_argument(
'-e',
'--env-vars',
'--envs',
dest='env_vars_strs',
metavar='KEY=VALUE',
action='append',
help='Setup additional Environment Variables during hook execution',
default=[],
)
parser.add_argument('files', nargs='*', help='Changed files paths')


def attach_subcommand_parsers_to(root_cli_parser: ArgumentParser, /) -> None:
Expand All @@ -18,19 +61,27 @@ def attach_subcommand_parsers_to(root_cli_parser: ArgumentParser, /) -> None:
"""
subcommand_parsers = root_cli_parser.add_subparsers(
dest='check_name',
help='A check to be performed.',
required=True,
)
for subcommand_module in SUBCOMMAND_MODULES:
subcommand_parser = subcommand_parsers.add_parser(subcommand_module.CLI_SUBCOMMAND_NAME)
subcommand_parser = subcommand_parsers.add_parser(
subcommand_module.HOOK_ID,
add_help=False,
Copy link
Contributor

Choose a reason for hiding this comment

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

I still maintain that it'd be useful to allow --help in subcommands.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree, but that's out of scope for now - firstly we need to reimplement same hooks in Python w/o any breaking changes about what we are aware.

Anyway, I added that as TODO in rewrite_hooks_on_python branch

)
subcommand_parser.set_defaults(
invoke_cli_app=subcommand_module.invoke_cli_app,
)
subcommand_module.populate_argument_parser(subcommand_parser)
populate_common_argument_parser(subcommand_parser)
subcommand_module.populate_hook_specific_argument_parser(subcommand_parser)


def initialize_argument_parser() -> ArgumentParser:
"""Return the root argument parser with sub-commands."""
"""
Parse the command line arguments and return the parsed arguments.

Return the root argument parser with sub-commands.
Copy link
Contributor

Choose a reason for hiding this comment

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

Only the docstring title needs to be in imperative mood. The long description paragraph doesn't need to do that, it can be more explanatory.


"""
root_cli_parser = ArgumentParser(prog=f'python -m {__package__ !s}')
attach_subcommand_parsers_to(root_cli_parser)
return root_cli_parser
Expand Down
9 changes: 3 additions & 6 deletions src/pre_commit_terraform/_cli_subcommands.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
"""A CLI sub-commands organization module."""

from . import terraform_docs_replace
from ._types import CLISubcommandModuleProtocol
from pre_commit_terraform import terraform_docs_replace
Copy link
Contributor

Choose a reason for hiding this comment

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

FTR #742 has proper configuration that can work with relative imports just fine.

from pre_commit_terraform._types import CLISubcommandModuleProtocol


SUBCOMMAND_MODULES: list[CLISubcommandModuleProtocol] = [
terraform_docs_replace,
]
SUBCOMMAND_MODULES: tuple[CLISubcommandModuleProtocol, ...] = (terraform_docs_replace,)


__all__ = ('SUBCOMMAND_MODULES',)
Loading
Loading