From cedeef3cb10197c6d28e073011561dab8328aabf Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Mon, 26 May 2025 11:27:28 -0400 Subject: [PATCH] pre-commit: Workaround broken shebang on Windows Using "python" in the shebang breaks those scripts when ran outside of pre-commit venv. Part-of: --- .pre-commit-config.yaml | 11 +++++++++-- scripts/gst-indent-all.py | 3 ++- scripts/gst-indent.py | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 34637d5fb0..6ed0101d36 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,10 @@ +# Notes: +# - Python commands must be prefixed with `python` because pre-commit refuses to +# special-case shebangs on Windows where `python3` does not commonly exists. +# Luckily, the `python` command exists in the virtualenv created by pre-commit +# on all platforms. https://github.com/pre-commit/pre-commit/issues/3415, +# https://github.com/pre-commit/pre-commit/issues/3468 + fail_fast: false repos: - repo: https://github.com/jorisroovers/gitlint @@ -16,7 +23,7 @@ repos: - id: gst-indent name: gst-indent language: python - entry: ./scripts/gst-indent-all.py + entry: python ./scripts/gst-indent-all.py pass_filenames: false types_or: ["c", "c++"] additional_dependencies: ["gst-indent==1.0.0"] @@ -30,6 +37,6 @@ repos: - id: doc-checks name: doc-checks language: python - entry: ./scripts/git-hooks/pre-commit-python.hook + entry: python ./scripts/git-hooks/pre-commit-python.hook pass_filenames: false additional_dependencies: ["autopep8==2.3.2", "pycodestyle==2.12.1"] diff --git a/scripts/gst-indent-all.py b/scripts/gst-indent-all.py index a933608561..d90eddac9e 100755 --- a/scripts/gst-indent-all.py +++ b/scripts/gst-indent-all.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from itertools import filterfalse import os @@ -6,6 +6,7 @@ import re import subprocess from gst_indent_common import indent + def readfile(f): if os.path.exists(f): expressions = open(f, 'r', encoding='utf-8').read().splitlines() diff --git a/scripts/gst-indent.py b/scripts/gst-indent.py index 7ef82e1d23..d9467983e6 100755 --- a/scripts/gst-indent.py +++ b/scripts/gst-indent.py @@ -1,8 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from sys import argv from gst_indent_common import indent if __name__ == '__main__': - indent(argv[1:]) + indent(*argv[1:])