mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-12 03:50:23 -06:00
Resolves cwd problem
This commit is contained in:
@@ -1,34 +1,35 @@
|
||||
|
||||
import contextlib
|
||||
from plumbum import local
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
|
||||
|
||||
PY_ENV = 'py_env'
|
||||
|
||||
|
||||
class PythonEnv(helpers.Environment):
|
||||
@property
|
||||
def env_prefix(self):
|
||||
return '. {0}/bin/activate &&'.format(PY_ENV)
|
||||
return '. {{prefix}}{0}/bin/activate &&'.format(PY_ENV)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def in_env():
|
||||
yield PythonEnv()
|
||||
def in_env(repo_cmd_runner):
|
||||
yield PythonEnv(repo_cmd_runner)
|
||||
|
||||
|
||||
def install_environment():
|
||||
assert local.path('setup.py').exists()
|
||||
def install_environment(repo_cmd_runner):
|
||||
assert repo_cmd_runner.exists('setup.py')
|
||||
# Return immediately if we already have a virtualenv
|
||||
if local.path(PY_ENV).exists():
|
||||
if repo_cmd_runner.exists(PY_ENV):
|
||||
return
|
||||
|
||||
# Install a virtualenv
|
||||
local['virtualenv'][PY_ENV]()
|
||||
with in_env() as env:
|
||||
env.run('pip install .')
|
||||
repo_cmd_runner.run(['virtualenv', '{{prefix}}{0}'.format(PY_ENV)])
|
||||
with in_env(repo_cmd_runner) as env:
|
||||
env.run('cd {0} && pip install .'.format(repo_cmd_runner.prefix_dir))
|
||||
|
||||
|
||||
def run_hook(hook, file_args):
|
||||
with in_env() as env:
|
||||
def run_hook(repo_cmd_runner, hook, file_args):
|
||||
with in_env(repo_cmd_runner) as env:
|
||||
return helpers.run_hook(env, hook, file_args)
|
||||
|
||||
Reference in New Issue
Block a user