From b282c18eb1e9328825666a6bbeb58fc1f76e7dec Mon Sep 17 00:00:00 2001 From: Chris Gilmer Date: Mon, 13 Apr 2020 15:45:22 -0700 Subject: [PATCH] Provide an environment variable to override the pre-commit command. --- pre_commit/resources/hook-tmpl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pre_commit/resources/hook-tmpl b/pre_commit/resources/hook-tmpl index 299144ec..0bdb83ba 100755 --- a/pre_commit/resources/hook-tmpl +++ b/pre_commit/resources/hook-tmpl @@ -2,6 +2,7 @@ # File generated by pre-commit: https://pre-commit.com # ID: 138fd403232d2ddd5efb44317e38bf03 import os +import shlex import sys # we try our best, but the shebang of this script is difficult to determine: @@ -25,7 +26,9 @@ 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): +if "PRE_COMMIT_CMD" in os.environ: + CMD = shlex.split(os.environ.get("PRE_COMMIT_CMD")) +elif os.access(INSTALL_PYTHON, os.X_OK): CMD = [INSTALL_PYTHON, '-mpre_commit'] elif which('pre-commit'): CMD = ['pre-commit']