Print message when installing repositories.

This commit is contained in:
Anthony Sottile 2014-04-03 23:31:45 -07:00
parent 36ecf23c2e
commit 74363e6ec2
9 changed files with 78 additions and 29 deletions

View file

@ -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

View file

@ -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:

View file

@ -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 .')

View file

@ -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')

View file

@ -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):

View file

@ -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):

View file

@ -1,4 +1,6 @@
from __future__ import print_function
import contextlib
from plumbum import local
@ -63,6 +65,10 @@ class Repository(object):
# Project already exists, no reason to re-create it
return
# Checking out environment for the first time
print('Installing environment for {0}.'.format(self.repo_url))
print('Once installed this environment will be reused.')
print('This may take a few minutes...')
with clean_path_on_failure(unicode(local.path(self.sha))):
local['git']['clone', '--no-checkout', self.repo_url, self.sha]()
with self.in_checkout():
@ -73,6 +79,7 @@ class Repository(object):
return
self.install(cmd_runner)
self.__installed = True
def install(self, cmd_runner):
"""Install the hook repository.
@ -82,8 +89,15 @@ class Repository(object):
"""
self.require_created()
repo_cmd_runner = self.get_cmd_runner(cmd_runner)
for language in self.languages:
languages[language].install_environment(repo_cmd_runner)
for language_name in self.languages:
language = languages[language_name]
if (
language.ENVIRONMENT_DIR is None or
repo_cmd_runner.exists(language.ENVIRONMENT_DIR)
):
# The language is already installed
continue
language.install_environment(repo_cmd_runner)
@contextlib.contextmanager
def in_checkout(self):