mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 17:14:43 +04:00
Merge pull request #2 from pre-commit/asottile_install_dependencies
Fixups + make the tests work
This commit is contained in:
commit
3581f94b32
4 changed files with 25 additions and 27 deletions
|
|
@ -50,8 +50,7 @@ def install_environment(
|
||||||
node_env.run(
|
node_env.run(
|
||||||
"cd '{prefix}' && npm install -g " +
|
"cd '{prefix}' && npm install -g " +
|
||||||
' '.join(
|
' '.join(
|
||||||
[shell_escape(dep) for dep in
|
shell_escape(dep) for dep in additional_dependencies
|
||||||
additional_dependencies]
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,15 +93,14 @@ def install_environment(
|
||||||
if version != 'default':
|
if version != 'default':
|
||||||
_install_ruby(ruby_env, version)
|
_install_ruby(ruby_env, version)
|
||||||
ruby_env.run(
|
ruby_env.run(
|
||||||
'cd {prefix} && gem build *.gemspec'
|
'cd {prefix} && gem build *.gemspec && '
|
||||||
' && gem install --no-ri --no-rdoc *.gem',
|
'gem install --no-ri --no-rdoc *.gem',
|
||||||
)
|
)
|
||||||
if additional_dependencies:
|
if additional_dependencies:
|
||||||
ruby_env.run(
|
ruby_env.run(
|
||||||
'cd {prefix} && gem install --no-document ' +
|
'cd {prefix} && gem install --no-ri --no-rdoc ' +
|
||||||
' '.join(
|
' '.join(
|
||||||
shell_escape(dep) for dep in
|
shell_escape(dep) for dep in additional_dependencies
|
||||||
additional_dependencies
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ def install_environment(
|
||||||
def run_hook(repo_cmd_runner, hook, file_args):
|
def run_hook(repo_cmd_runner, hook, file_args):
|
||||||
return repo_cmd_runner.run(
|
return repo_cmd_runner.run(
|
||||||
['xargs', '-0', '{{prefix}}{0}'.format(hook['entry'])] + hook['args'],
|
['xargs', '-0', '{{prefix}}{0}'.format(hook['entry'])] + hook['args'],
|
||||||
# TODO: this is duplicated in pre_commit/languages/helpers.py
|
|
||||||
stdin=file_args_to_stdin(file_args),
|
stdin=file_args_to_stdin(file_args),
|
||||||
retcode=None,
|
retcode=None,
|
||||||
encoding=None,
|
encoding=None,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import io
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import shutil
|
import shutil
|
||||||
from collections import defaultdict
|
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
@ -14,8 +13,9 @@ from pre_commit import five
|
||||||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||||
from pre_commit.clientlib.validate_config import validate_config_extra
|
from pre_commit.clientlib.validate_config import validate_config_extra
|
||||||
from pre_commit.jsonschema_extensions import apply_defaults
|
from pre_commit.jsonschema_extensions import apply_defaults
|
||||||
from pre_commit.languages.python import norm_version
|
from pre_commit.languages import node
|
||||||
from pre_commit.languages.python import PythonEnv
|
from pre_commit.languages import python
|
||||||
|
from pre_commit.languages import ruby
|
||||||
from pre_commit.repository import Repository
|
from pre_commit.repository import Repository
|
||||||
from pre_commit.util import cmd_output
|
from pre_commit.util import cmd_output
|
||||||
from pre_commit.util import cwd
|
from pre_commit.util import cwd
|
||||||
|
|
@ -311,44 +311,45 @@ def test_additional_dependencies(tempdir_factory, store):
|
||||||
config = make_config_from_repo(path)
|
config = make_config_from_repo(path)
|
||||||
config['hooks'][0]['additional_dependencies'] = ['pep8']
|
config['hooks'][0]['additional_dependencies'] = ['pep8']
|
||||||
repo = Repository.create(config, store)
|
repo = Repository.create(config, store)
|
||||||
expected_deps = defaultdict(lambda: defaultdict(set))
|
assert repo.additional_dependencies['python']['default'] == set(('pep8',))
|
||||||
expected_deps['python']['default'].update(['pep8'])
|
|
||||||
assert repo.additional_dependencies == expected_deps
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_additional_python_dependencies_installed(tempdir_factory, store):
|
def test_additional_python_dependencies_installed(tempdir_factory, store):
|
||||||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||||
config = make_config_from_repo(path)
|
config = make_config_from_repo(path)
|
||||||
config['hooks'][0]['additional_dependencies'] = ['pep8']
|
config['hooks'][0]['additional_dependencies'] = ['mccabe']
|
||||||
repo = Repository.create(config, store)
|
repo = Repository.create(config, store)
|
||||||
repo.run_hook(repo.hooks[0][1], [])
|
repo.run_hook(repo.hooks[0][1], [])
|
||||||
output = repo.cmd_runner.run(['pip', 'freeze'])
|
with python.in_env(repo.cmd_runner, 'default') as env:
|
||||||
assert 'pep8' in output[1]
|
output = env.run('pip freeze -l')[1]
|
||||||
|
assert 'mccabe' in output
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_additional_ruby_dependencies_installed(tempdir_factory, store):
|
def test_additional_ruby_dependencies_installed(tempdir_factory, store):
|
||||||
path = make_repo(tempdir_factory, 'ruby_hooks_repo')
|
path = make_repo(tempdir_factory, 'ruby_hooks_repo')
|
||||||
config = make_config_from_repo(path)
|
config = make_config_from_repo(path)
|
||||||
config['hooks'][0]['additional_dependencies'] = ['rubocop']
|
config['hooks'][0]['additional_dependencies'] = ['mime-types']
|
||||||
repo = Repository.create(config, store)
|
repo = Repository.create(config, store)
|
||||||
repo.run_hook(repo.hooks[0][1], [])
|
repo.run_hook(repo.hooks[0][1], [])
|
||||||
output = repo.cmd_runner.run(['gem', 'list', '--local'])
|
with ruby.in_env(repo.cmd_runner, 'default') as env:
|
||||||
assert 'rubocop' in output[1]
|
output = env.run('gem list --local')[1]
|
||||||
|
assert 'mime-types' in output
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_additional_node_dependencies_installed(tempdir_factory, store):
|
def test_additional_node_dependencies_installed(tempdir_factory, store):
|
||||||
path = make_repo(tempdir_factory, 'node_hooks_repo')
|
path = make_repo(tempdir_factory, 'node_hooks_repo')
|
||||||
config = make_config_from_repo(path)
|
config = make_config_from_repo(path)
|
||||||
config['hooks'][0]['additional_dependencies'] = ['eslint']
|
# Careful to choose a small package that's not depped by npm
|
||||||
|
config['hooks'][0]['additional_dependencies'] = ['lodash']
|
||||||
repo = Repository.create(config, store)
|
repo = Repository.create(config, store)
|
||||||
repo.run_hook(repo.hooks[0][1], [])
|
repo.run_hook(repo.hooks[0][1], [])
|
||||||
repo.cmd_runner.run(['npm', 'config', 'set', 'global', 'true',
|
with node.in_env(repo.cmd_runner, 'default') as env:
|
||||||
'&&', 'npm', 'ls'])
|
env.run('npm config set global true')
|
||||||
output = repo.cmd_runner.run(['npm', 'ls'])
|
output = env.run(('npm ls'))[1]
|
||||||
assert 'eslint' in output[1]
|
assert 'lodash' in output
|
||||||
|
|
||||||
|
|
||||||
def test_reinstall(tempdir_factory, store, log_info_mock):
|
def test_reinstall(tempdir_factory, store, log_info_mock):
|
||||||
|
|
@ -383,7 +384,7 @@ def test_control_c_control_c_on_install(tempdir_factory, store):
|
||||||
# raise as well.
|
# raise as well.
|
||||||
with pytest.raises(MyKeyboardInterrupt):
|
with pytest.raises(MyKeyboardInterrupt):
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
PythonEnv, 'run', side_effect=MyKeyboardInterrupt,
|
python.PythonEnv, 'run', side_effect=MyKeyboardInterrupt,
|
||||||
):
|
):
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
shutil, 'rmtree', side_effect=MyKeyboardInterrupt,
|
shutil, 'rmtree', side_effect=MyKeyboardInterrupt,
|
||||||
|
|
@ -474,5 +475,5 @@ def test_norm_version_expanduser(): # pragma: no cover
|
||||||
else:
|
else:
|
||||||
path = '~/.pyenv/versions/3.4.3/bin/python'
|
path = '~/.pyenv/versions/3.4.3/bin/python'
|
||||||
expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
|
expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
|
||||||
result = norm_version(path)
|
result = python.norm_version(path)
|
||||||
assert result == expected_path
|
assert result == expected_path
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue