Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this avoids some version-specific code in python this also makes the bootstrap script slightly more portable
- Loading branch information
Showing
3 changed files
with
20 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,20 @@ | ||
#!/usr/bin/env python3 | ||
#!/usr/bin/env bash | ||
# File generated by pre-commit: https://pre-commit.com | ||
# ID: 138fd403232d2ddd5efb44317e38bf03 | ||
import os | ||
import sys | ||
|
||
# we try our best, but the shebang of this script is difficult to determine: | ||
# - macos doesn't ship with python3 | ||
# - windows executables are almost always `python.exe` | ||
# therefore we continue to support python2 for this small script | ||
if sys.version_info < (3, 3): | ||
from distutils.spawn import find_executable as which | ||
else: | ||
from shutil import which | ||
|
||
# work around https://github.com/Homebrew/homebrew-core/issues/30445 | ||
os.environ.pop('__PYVENV_LAUNCHER__', None) | ||
|
||
# start templated | ||
INSTALL_PYTHON = '' | ||
ARGS = ['hook-impl'] | ||
INSTALL_PYTHON='' | ||
ARGS=(hook-impl) | ||
# end templated | ||
ARGS.extend(('--hook-dir', os.path.realpath(os.path.dirname(__file__)))) | ||
ARGS.append('--') | ||
ARGS.extend(sys.argv[1:]) | ||
|
||
DNE = '`pre-commit` not found. Did you forget to activate your virtualenv?' | ||
if os.access(INSTALL_PYTHON, os.X_OK): | ||
CMD = [INSTALL_PYTHON, '-mpre_commit'] | ||
elif which('pre-commit'): | ||
CMD = ['pre-commit'] | ||
else: | ||
raise SystemExit(DNE) | ||
|
||
CMD.extend(ARGS) | ||
if sys.platform == 'win32': # https://bugs.python.org/issue19124 | ||
import subprocess | ||
HERE="$(cd "$(dirname "$0")" && pwd)" | ||
ARGS+=(--hook-dir "$HERE" -- "$@") | ||
|
||
if sys.version_info < (3, 7): # https://bugs.python.org/issue25942 | ||
raise SystemExit(subprocess.Popen(CMD).wait()) | ||
else: | ||
raise SystemExit(subprocess.call(CMD)) | ||
else: | ||
os.execvp(CMD[0], CMD) | ||
if [ -x "$INSTALL_PYTHON" ]; then | ||
exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}" | ||
elif command -v pre-commit; then | ||
exec pre-commit "${ARGS[@]}" | ||
else | ||
echo '`pre-commit` not found. Did you forget to activate your virtualenv?' 1>&2 | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e622f79
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asottile - I am curious as to the motivation of this change. Doesn't it effectively make pre-commit incompatible with Windows, which doesn't have bash?
e622f79
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@R0ll1ngSt0ne git itself has parts implemented with bash so if you have git you have bash