mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 04:20:28 -06:00
Move PrefixedCommandRunner -> Prefix
This commit is contained in:
@@ -33,8 +33,8 @@ def get_env_patch(venv):
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def in_env(repo_cmd_runner, language_version):
|
||||
envdir = repo_cmd_runner.path(
|
||||
def in_env(prefix, language_version):
|
||||
envdir = prefix.path(
|
||||
helpers.environment_dir(ENVIRONMENT_DIR, language_version),
|
||||
)
|
||||
with envcontext(get_env_patch(envdir)):
|
||||
@@ -98,8 +98,8 @@ def get_default_version():
|
||||
return get_default_version()
|
||||
|
||||
|
||||
def healthy(repo_cmd_runner, language_version):
|
||||
with in_env(repo_cmd_runner, language_version):
|
||||
def healthy(prefix, language_version):
|
||||
with in_env(prefix, language_version):
|
||||
retcode, _, _ = cmd_output(
|
||||
'python', '-c', 'import ctypes, datetime, io, os, ssl, weakref',
|
||||
retcode=None,
|
||||
@@ -127,29 +127,26 @@ def norm_version(version):
|
||||
return os.path.expanduser(version)
|
||||
|
||||
|
||||
def install_environment(repo_cmd_runner, version, additional_dependencies):
|
||||
def install_environment(prefix, version, additional_dependencies):
|
||||
additional_dependencies = tuple(additional_dependencies)
|
||||
directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
|
||||
|
||||
# Install a virtualenv
|
||||
with clean_path_on_failure(repo_cmd_runner.path(directory)):
|
||||
venv_cmd = [
|
||||
sys.executable, '-m', 'virtualenv',
|
||||
'{{prefix}}{}'.format(directory),
|
||||
]
|
||||
env_dir = prefix.path(directory)
|
||||
with clean_path_on_failure(env_dir):
|
||||
venv_cmd = [sys.executable, '-m', 'virtualenv', env_dir]
|
||||
if version != 'default':
|
||||
venv_cmd.extend(['-p', norm_version(version)])
|
||||
else:
|
||||
venv_cmd.extend(['-p', os.path.realpath(sys.executable)])
|
||||
venv_env = dict(os.environ, VIRTUALENV_NO_DOWNLOAD='1')
|
||||
repo_cmd_runner.run(venv_cmd, cwd='/', env=venv_env)
|
||||
with in_env(repo_cmd_runner, version):
|
||||
cmd_output(*venv_cmd, cwd='/', env=venv_env)
|
||||
with in_env(prefix, version):
|
||||
helpers.run_setup_cmd(
|
||||
repo_cmd_runner,
|
||||
('pip', 'install', '.') + additional_dependencies,
|
||||
prefix, ('pip', 'install', '.') + additional_dependencies,
|
||||
)
|
||||
|
||||
|
||||
def run_hook(repo_cmd_runner, hook, file_args):
|
||||
with in_env(repo_cmd_runner, hook['language_version']):
|
||||
def run_hook(prefix, hook, file_args):
|
||||
with in_env(prefix, hook['language_version']):
|
||||
return xargs(helpers.to_cmd(hook), file_args)
|
||||
|
||||
Reference in New Issue
Block a user