mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
Print message when installing repositories.
This commit is contained in:
parent
36ecf23c2e
commit
74363e6ec2
9 changed files with 78 additions and 29 deletions
|
|
@ -5,7 +5,10 @@ from pre_commit.languages import ruby
|
|||
from pre_commit.languages import script
|
||||
from pre_commit.languages import system
|
||||
|
||||
# A language implements the following two functions in its module:
|
||||
# A language implements the following constant and two functions in its module:
|
||||
#
|
||||
# # Use None for no environment
|
||||
# ENVIRONMENT_DIR = 'foo_env'
|
||||
#
|
||||
# def install_environment(repo_cmd_runner):
|
||||
# """Installs a repository in the given repository. Note that the current
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from pre_commit.prefixed_command_runner import CalledProcessError
|
|||
from pre_commit.util import clean_path_on_failure
|
||||
|
||||
|
||||
NODE_ENV = 'node_env'
|
||||
ENVIRONMENT_DIR = 'node_env'
|
||||
|
||||
|
||||
class NodeEnv(python.PythonEnv):
|
||||
|
|
@ -15,7 +15,7 @@ class NodeEnv(python.PythonEnv):
|
|||
base = super(NodeEnv, self).env_prefix
|
||||
return ' '.join([
|
||||
base,
|
||||
'. {{prefix}}{0}/bin/activate &&'.format(NODE_ENV)]
|
||||
'. {{prefix}}{0}/bin/activate &&'.format(ENVIRONMENT_DIR)]
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -27,30 +27,26 @@ def in_env(repo_cmd_runner):
|
|||
def install_environment(repo_cmd_runner):
|
||||
assert repo_cmd_runner.exists('package.json')
|
||||
|
||||
# Return immediately if we already have a virtualenv
|
||||
if repo_cmd_runner.exists(NODE_ENV):
|
||||
return
|
||||
|
||||
with clean_path_on_failure(repo_cmd_runner.path(python.PY_ENV)):
|
||||
with clean_path_on_failure(repo_cmd_runner.path(python.ENVIRONMENT_DIR)):
|
||||
repo_cmd_runner.run(
|
||||
['virtualenv', '{{prefix}}{0}'.format(python.PY_ENV)],
|
||||
['virtualenv', '{{prefix}}{0}'.format(python.ENVIRONMENT_DIR)],
|
||||
)
|
||||
|
||||
with python.in_env(repo_cmd_runner) as python_env:
|
||||
python_env.run('pip install nodeenv')
|
||||
|
||||
with clean_path_on_failure(repo_cmd_runner.path(NODE_ENV)):
|
||||
with clean_path_on_failure(repo_cmd_runner.path(ENVIRONMENT_DIR)):
|
||||
# Try and use the system level node executable first
|
||||
try:
|
||||
python_env.run(
|
||||
'nodeenv -n system {{prefix}}{0}'.format(NODE_ENV),
|
||||
'nodeenv -n system {{prefix}}{0}'.format(ENVIRONMENT_DIR),
|
||||
)
|
||||
except CalledProcessError:
|
||||
# TODO: log failure here
|
||||
# cleanup
|
||||
# TODO: local.path(NODE_ENV).delete()
|
||||
# TODO: local.path(ENVIRONMENT_DIR).delete()
|
||||
python_env.run(
|
||||
'nodeenv --jobs 4 {{prefix}}{0}'.format(NODE_ENV),
|
||||
'nodeenv --jobs 4 {{prefix}}{0}'.format(ENVIRONMENT_DIR),
|
||||
)
|
||||
|
||||
with in_env(repo_cmd_runner) as node_env:
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ from pre_commit.languages import helpers
|
|||
from pre_commit.util import clean_path_on_failure
|
||||
|
||||
|
||||
PY_ENV = 'py_env'
|
||||
ENVIRONMENT_DIR = 'py_env'
|
||||
|
||||
|
||||
class PythonEnv(helpers.Environment):
|
||||
@property
|
||||
def env_prefix(self):
|
||||
return '. {{prefix}}{0}/bin/activate &&'.format(PY_ENV)
|
||||
return '. {{prefix}}{0}/bin/activate &&'.format(ENVIRONMENT_DIR)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
|
@ -21,13 +21,10 @@ def in_env(repo_cmd_runner):
|
|||
|
||||
def install_environment(repo_cmd_runner):
|
||||
assert repo_cmd_runner.exists('setup.py')
|
||||
# Return immediately if we already have a virtualenv
|
||||
if repo_cmd_runner.exists(PY_ENV):
|
||||
return
|
||||
|
||||
# Install a virtualenv
|
||||
with clean_path_on_failure(repo_cmd_runner.path(PY_ENV)):
|
||||
repo_cmd_runner.run(['virtualenv', '{{prefix}}{0}'.format(PY_ENV)])
|
||||
with clean_path_on_failure(repo_cmd_runner.path(ENVIRONMENT_DIR)):
|
||||
repo_cmd_runner.run(['virtualenv', '{{prefix}}{0}'.format(ENVIRONMENT_DIR)])
|
||||
with in_env(repo_cmd_runner) as env:
|
||||
env.run('cd {prefix} && pip install .')
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ from pre_commit.languages import helpers
|
|||
from pre_commit.util import clean_path_on_failure
|
||||
|
||||
|
||||
RVM_ENV = 'rvm_env'
|
||||
ENVIRONMENT_DIR = 'rvm_env'
|
||||
|
||||
|
||||
class RubyEnv(helpers.Environment):
|
||||
@property
|
||||
def env_prefix(self):
|
||||
return '. {{prefix}}{0}/bin/activate &&'.format(RVM_ENV)
|
||||
return '. {{prefix}}{0}/bin/activate &&'.format(ENVIRONMENT_DIR)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
|
@ -21,11 +21,11 @@ def in_env(repo_cmd_runner):
|
|||
|
||||
def install_environment(repo_cmd_runner):
|
||||
# Return immediately if we already have a virtualenv
|
||||
if repo_cmd_runner.exists(RVM_ENV):
|
||||
if repo_cmd_runner.exists(ENVIRONMENT_DIR):
|
||||
return
|
||||
|
||||
with clean_path_on_failure(repo_cmd_runner.path(RVM_ENV)):
|
||||
repo_cmd_runner.run(['__rvm-env.sh', '{{prefix}}{0}'.format(RVM_ENV)])
|
||||
with clean_path_on_failure(repo_cmd_runner.path(ENVIRONMENT_DIR)):
|
||||
repo_cmd_runner.run(['__rvm-env.sh', '{{prefix}}{0}'.format(ENVIRONMENT_DIR)])
|
||||
with in_env(repo_cmd_runner) as env:
|
||||
env.run('cd {prefix} && bundle install')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
|
||||
ENVIRONMENT_DIR = None
|
||||
|
||||
|
||||
def install_environment(repo_cmd_runner):
|
||||
"""Installation for script type is a noop."""
|
||||
pass
|
||||
|
||||
|
||||
def run_hook(repo_cmd_runner, hook, file_args):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
|
||||
ENVIRONMENT_DIR = None
|
||||
|
||||
|
||||
def install_environment(repo_cmd_runner):
|
||||
"""Installation for system type is a noop."""
|
||||
pass
|
||||
|
||||
|
||||
def run_hook(repo_cmd_runner, hook, file_args):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue