mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Keep additional_dependencies in the order in which they are specified
This commit is contained in:
parent
7f18b03201
commit
397efa8080
2 changed files with 28 additions and 3 deletions
|
|
@ -64,7 +64,7 @@ class Repository(object):
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def additional_dependencies(self):
|
def additional_dependencies(self):
|
||||||
dep_dict = defaultdict(lambda: defaultdict(set))
|
dep_dict = defaultdict(lambda: defaultdict(_UniqueList))
|
||||||
for _, hook in self.hooks:
|
for _, hook in self.hooks:
|
||||||
dep_dict[hook['language']][hook['language_version']].update(
|
dep_dict[hook['language']][hook['language_version']].update(
|
||||||
hook.get('additional_dependencies', []),
|
hook.get('additional_dependencies', []),
|
||||||
|
|
@ -222,3 +222,14 @@ class LocalRepository(Repository):
|
||||||
@cached_property
|
@cached_property
|
||||||
def manifest(self):
|
def manifest(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
class _UniqueList(list):
|
||||||
|
def __init__(self):
|
||||||
|
self._set = set()
|
||||||
|
|
||||||
|
def update(self, obj):
|
||||||
|
for item in obj:
|
||||||
|
if item not in self._set:
|
||||||
|
self._set.add(item)
|
||||||
|
self.append(item)
|
||||||
|
|
|
||||||
|
|
@ -477,7 +477,20 @@ 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)
|
||||||
assert repo.additional_dependencies['python']['default'] == {'pep8'}
|
assert repo.additional_dependencies['python']['default'] == ['pep8']
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.integration
|
||||||
|
def test_additional_dependencies_duplicated(
|
||||||
|
tempdir_factory, store, log_warning_mock,
|
||||||
|
):
|
||||||
|
path = make_repo(tempdir_factory, 'ruby_hooks_repo')
|
||||||
|
config = make_config_from_repo(path)
|
||||||
|
config['hooks'][0]['additional_dependencies'] = [
|
||||||
|
'thread_safe', 'tins', 'thread_safe']
|
||||||
|
repo = Repository.create(config, store)
|
||||||
|
assert repo.additional_dependencies['ruby']['default'] == [
|
||||||
|
'thread_safe', 'tins']
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
|
|
@ -517,12 +530,13 @@ def test_additional_ruby_dependencies_installed(
|
||||||
): # pragma: no cover (non-windows)
|
): # pragma: no cover (non-windows)
|
||||||
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'] = ['thread_safe']
|
config['hooks'][0]['additional_dependencies'] = ['thread_safe', 'tins']
|
||||||
repo = Repository.create(config, store)
|
repo = Repository.create(config, store)
|
||||||
repo.require_installed()
|
repo.require_installed()
|
||||||
with ruby.in_env(repo.cmd_runner, 'default'):
|
with ruby.in_env(repo.cmd_runner, 'default'):
|
||||||
output = cmd_output('gem', 'list', '--local')[1]
|
output = cmd_output('gem', 'list', '--local')[1]
|
||||||
assert 'thread_safe' in output
|
assert 'thread_safe' in output
|
||||||
|
assert 'tins' in output
|
||||||
|
|
||||||
|
|
||||||
@skipif_slowtests_false
|
@skipif_slowtests_false
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue