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
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 23 additions & 3 deletions pre_commit_hooks/shellcheck_run_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
def do_shellcheck(
melange_cfg: Mapping[str, Any],
shellcheck: list[str],
shellcheck_args: list[str],
) -> None:
if melange_cfg == {}:
return
Expand Down Expand Up @@ -48,11 +49,14 @@ def do_shellcheck(
),
),
)
if len(all_steps) == 0:
return
for step, shfile in all_steps:
shfile.write(step["runs"])
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(),
Expand All @@ -61,7 +65,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=[
Expand All @@ -76,9 +85,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,
Expand All @@ -97,7 +113,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
Expand Down
Loading