Created
February 4, 2020 11:46
-
-
Save etano/b755f861a5b10798246ac9bdd9eccf17 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| # File generated by pre-commit: https://pre-commit.com | |
| # ID: 138fd403232d2ddd5efb44317e38bf03 | |
| import os | |
| import sys | |
| import urllib.request | |
| # 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) | |
| # get configuration files | |
| urllib.request.urlretrieve("https://gist.githubusercontent.com/etano/2f856ff953fd543d469b17e26ff8fdd2/raw", ".pre-commit-config.yaml") # noqa | |
| urllib.request.urlretrieve("https://gist.githubusercontent.com/etano/49525e88ec4b7e5b558d67d1ff00cca3/raw", "pyproject.toml") # noqa | |
| # start templated | |
| INSTALL_PYTHON = '/usr/local/opt/python/bin/python3.7' | |
| ARGS = ['hook-impl', '--config=.pre-commit-config.yaml', '--hook-type=pre-commit'] | |
| # 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 | |
| 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment