diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-12-04 03:57:54 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-12-04 03:57:54 +0000 |
commit | fc1651ef0b7ccedc604b28d5893f5cd486cd4091 (patch) | |
tree | 3ea033abb546734a46b2e947756e0d9f792b0e80 /pre_commit/commands/install_uninstall.py | |
parent | Releasing debian version 2.15.0-1. (diff) | |
download | pre-commit-fc1651ef0b7ccedc604b28d5893f5cd486cd4091.tar.xz pre-commit-fc1651ef0b7ccedc604b28d5893f5cd486cd4091.zip |
Merging upstream version 2.16.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/commands/install_uninstall.py')
-rw-r--r-- | pre_commit/commands/install_uninstall.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/pre_commit/commands/install_uninstall.py b/pre_commit/commands/install_uninstall.py index 73c8d60..7974423 100644 --- a/pre_commit/commands/install_uninstall.py +++ b/pre_commit/commands/install_uninstall.py @@ -1,6 +1,7 @@ import itertools import logging import os.path +import shlex import shutil import sys from typing import Optional @@ -100,19 +101,17 @@ def _install_hook_script( args = ['hook-impl', f'--config={config_file}', f'--hook-type={hook_type}'] if skip_on_missing_config: args.append('--skip-on-missing-config') - params = {'INSTALL_PYTHON': sys.executable, 'ARGS': args} with open(hook_path, 'w') as hook_file: contents = resource_text('hook-tmpl') before, rest = contents.split(TEMPLATE_START) - to_template, after = rest.split(TEMPLATE_END) - - before = before.replace('#!/usr/bin/env python3', shebang()) + _, after = rest.split(TEMPLATE_END) hook_file.write(before + TEMPLATE_START) - for line in to_template.splitlines(): - var = line.split()[0] - hook_file.write(f'{var} = {params[var]!r}\n') + hook_file.write(f'INSTALL_PYTHON={shlex.quote(sys.executable)}\n') + # TODO: python3.8+: shlex.join + args_s = ' '.join(shlex.quote(part) for part in args) + hook_file.write(f'ARGS=({args_s})\n') hook_file.write(TEMPLATE_END + after) make_executable(hook_path) |