mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Pick a better python shebang for hook executable
This commit is contained in:
parent
748c2ad273
commit
de942894ff
2 changed files with 33 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ import sys
|
|||
|
||||
from pre_commit import git
|
||||
from pre_commit import output
|
||||
from pre_commit.languages import python
|
||||
from pre_commit.repository import repositories
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import make_executable
|
||||
|
|
@ -43,6 +44,16 @@ def is_our_script(filename):
|
|||
return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)
|
||||
|
||||
|
||||
def shebang():
|
||||
if sys.platform == 'win32':
|
||||
py = 'python'
|
||||
else:
|
||||
py = python.get_default_version()
|
||||
if py == 'default':
|
||||
py = 'python'
|
||||
return '#!/usr/bin/env {}'.format(py)
|
||||
|
||||
|
||||
def install(
|
||||
runner, store, overwrite=False, hooks=False, hook_type='pre-commit',
|
||||
skip_on_missing_conf=False,
|
||||
|
|
@ -84,6 +95,8 @@ def install(
|
|||
before, rest = contents.split(TEMPLATE_START)
|
||||
to_template, after = rest.split(TEMPLATE_END)
|
||||
|
||||
before = before.replace('#!/usr/bin/env python', shebang())
|
||||
|
||||
hook_file.write(before + TEMPLATE_START)
|
||||
for line in to_template.splitlines():
|
||||
var = line.split()[0]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue