pre-commit: Workaround broken shebang on Windows

Using "python" in the shebang breaks those scripts when ran outside of
pre-commit venv.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9080>
This commit is contained in:
Xavier Claessens 2025-05-26 11:27:28 -04:00 committed by GStreamer Marge Bot
parent 7fe08e057c
commit cedeef3cb1
3 changed files with 13 additions and 5 deletions

@ -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"]

@ -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()

@ -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:])