|
1 | | -#!/usr/bin/env python3 |
| 1 | +#!/usr/bin/env bash |
2 | 2 | # File generated by pre-commit: https://pre-commit.com |
3 | 3 | # ID: 138fd403232d2ddd5efb44317e38bf03 |
4 | | -import os |
5 | | -import sys |
6 | | - |
7 | | -# we try our best, but the shebang of this script is difficult to determine: |
8 | | -# - macos doesn't ship with python3 |
9 | | -# - windows executables are almost always `python.exe` |
10 | | -# therefore we continue to support python2 for this small script |
11 | | -if sys.version_info < (3, 3): |
12 | | - from distutils.spawn import find_executable as which |
13 | | -else: |
14 | | - from shutil import which |
15 | | - |
16 | | -# work around https://github.com/Homebrew/homebrew-core/issues/30445 |
17 | | -os.environ.pop('__PYVENV_LAUNCHER__', None) |
18 | 4 |
|
19 | 5 | # start templated |
20 | | -INSTALL_PYTHON = '' |
21 | | -ARGS = ['hook-impl'] |
| 6 | +INSTALL_PYTHON='' |
| 7 | +ARGS=(hook-impl) |
22 | 8 | # end templated |
23 | | -ARGS.extend(('--hook-dir', os.path.realpath(os.path.dirname(__file__)))) |
24 | | -ARGS.append('--') |
25 | | -ARGS.extend(sys.argv[1:]) |
26 | | - |
27 | | -DNE = '`pre-commit` not found. Did you forget to activate your virtualenv?' |
28 | | -if os.access(INSTALL_PYTHON, os.X_OK): |
29 | | - CMD = [INSTALL_PYTHON, '-mpre_commit'] |
30 | | -elif which('pre-commit'): |
31 | | - CMD = ['pre-commit'] |
32 | | -else: |
33 | | - raise SystemExit(DNE) |
34 | 9 |
|
35 | | -CMD.extend(ARGS) |
36 | | -if sys.platform == 'win32': # https://bugs.python.org/issue19124 |
37 | | - import subprocess |
| 10 | +HERE="$(cd "$(dirname "$0")" && pwd)" |
| 11 | +ARGS+=(--hook-dir "$HERE" -- "$@") |
38 | 12 |
|
39 | | - if sys.version_info < (3, 7): # https://bugs.python.org/issue25942 |
40 | | - raise SystemExit(subprocess.Popen(CMD).wait()) |
41 | | - else: |
42 | | - raise SystemExit(subprocess.call(CMD)) |
43 | | -else: |
44 | | - os.execvp(CMD[0], CMD) |
| 13 | +if [ -x "$INSTALL_PYTHON" ]; then |
| 14 | + exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}" |
| 15 | +elif command -v pre-commit; then |
| 16 | + exec pre-commit "${ARGS[@]}" |
| 17 | +else |
| 18 | + echo '`pre-commit` not found. Did you forget to activate your virtualenv?' 1>&2 |
| 19 | + exit 1 |
| 20 | +fi |
0 commit comments