From af9d96409ae27b4bace9b54981c1e771f7c1a60f Mon Sep 17 00:00:00 2001 From: dann frazier Date: Sun, 25 May 2025 20:07:30 -0400 Subject: [PATCH 1/3] pre-commit: Drop autopep8 and flake8 in lieu of ruff format Let's choose a parent to live with, and not leave it up to the kids. ruff includes linters based on these tools already, so they are redundant. And, painfully, they can disagree with ruff formatting. Signed-off-by: dann frazier --- .pre-commit-config.yaml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dd677a1..3d558a7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,14 +34,6 @@ repos: hooks: - id: pyupgrade args: [--py39-plus] - - repo: https://github.com/hhatto/autopep8 - rev: 4046ad49e25b7fa1db275bf66b1b7d60600ac391 # frozen: v2.3.2 - hooks: - - id: autopep8 - - repo: https://github.com/PyCQA/flake8 - rev: 4b5e89b4b108a6c1a000c591d334a99a80d34c7b # frozen: 7.2.0 - hooks: - - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy rev: f40886d54c729f533f864ed6ce584e920feb0af7 # frozen: v1.15.0 hooks: From bf32bca1aa2d5917c9d08bec8286b01a4d929a5a Mon Sep 17 00:00:00 2001 From: dann frazier Date: Sun, 25 May 2025 20:15:56 -0400 Subject: [PATCH 2/3] Allow passing arguments through to shellcheck This can be used to exclude certain tests. Signed-off-by: dann frazier --- pre_commit_hooks/shellcheck_run_steps.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/pre_commit_hooks/shellcheck_run_steps.py b/pre_commit_hooks/shellcheck_run_steps.py index a8a2fc7..c54b1b3 100644 --- a/pre_commit_hooks/shellcheck_run_steps.py +++ b/pre_commit_hooks/shellcheck_run_steps.py @@ -17,6 +17,7 @@ def do_shellcheck( melange_cfg: Mapping[str, Any], shellcheck: list[str], + shellcheck_args: list[str], ) -> None: if melange_cfg == {}: return @@ -53,6 +54,7 @@ def do_shellcheck( shfile.close() subprocess.check_call( ["/usr/bin/shellcheck"] + + shellcheck_args + ["--shell=busybox", "--"] + [os.path.basename(f.name) for _, f in all_steps], cwd=os.getcwd(), @@ -61,7 +63,12 @@ def do_shellcheck( def main(argv: Sequence[str] | None = None) -> int: parser = argparse.ArgumentParser() - parser.add_argument("filenames", nargs="*", help="Filenames to check.") + parser.add_argument( + "filenames", + nargs="*", + help="Filenames to check. You can also pass " + "arguments to shellcheck before a '--' separator.", + ) parser.add_argument( "--shellcheck", default=[ @@ -76,9 +83,16 @@ def main(argv: Sequence[str] | None = None) -> int: help="shellcheck command", ) args = parser.parse_args(argv) + try: + idx = args.filenames.index("--") + shellcheck_args = args.filenames[:idx] + filenames = args.filenames[idx + 1 :] + except ValueError: + shellcheck_args = [] + filenames = args.filenames melange_cfg = {} - for filename in args.filenames: + for filename in filenames: with tempfile.NamedTemporaryFile( "w", delete_on_close=False, @@ -97,7 +111,11 @@ def main(argv: Sequence[str] | None = None) -> int: try: with open(compiled_out.name) as compiled_in: melange_cfg = yaml.load(compiled_in) - do_shellcheck(melange_cfg, args.shellcheck) + do_shellcheck( + melange_cfg, + args.shellcheck, + shellcheck_args, + ) except ruamel.yaml.YAMLError as exc: print(exc) return 1 From e03541c24b06dbd768c88fe6ce5eed04170109c5 Mon Sep 17 00:00:00 2001 From: dann frazier Date: Mon, 26 May 2025 12:57:44 -0400 Subject: [PATCH 3/3] shellcheck_run_steps: Avoid failure when YAML contains no run steps Signed-off-by: dann frazier --- pre_commit_hooks/shellcheck_run_steps.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pre_commit_hooks/shellcheck_run_steps.py b/pre_commit_hooks/shellcheck_run_steps.py index c54b1b3..c685cd4 100644 --- a/pre_commit_hooks/shellcheck_run_steps.py +++ b/pre_commit_hooks/shellcheck_run_steps.py @@ -49,6 +49,8 @@ def do_shellcheck( ), ), ) + if len(all_steps) == 0: + return for step, shfile in all_steps: shfile.write(step["runs"]) shfile.close()