mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #482 from tdeo/keep_dependencies_order
Keep dependency in order
This commit is contained in:
commit
63f65a419c
2 changed files with 28 additions and 3 deletions
|
|
@ -64,7 +64,7 @@ class Repository(object):
|
|||
|
||||
@cached_property
|
||||
def additional_dependencies(self):
|
||||
dep_dict = defaultdict(lambda: defaultdict(set))
|
||||
dep_dict = defaultdict(lambda: defaultdict(_UniqueList))
|
||||
for _, hook in self.hooks:
|
||||
dep_dict[hook['language']][hook['language_version']].update(
|
||||
hook.get('additional_dependencies', []),
|
||||
|
|
@ -222,3 +222,14 @@ class LocalRepository(Repository):
|
|||
@cached_property
|
||||
def manifest(self):
|
||||
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['hooks'][0]['additional_dependencies'] = ['pep8']
|
||||
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
|
||||
|
|
@ -517,12 +530,13 @@ def test_additional_ruby_dependencies_installed(
|
|||
): # pragma: no cover (non-windows)
|
||||
path = make_repo(tempdir_factory, 'ruby_hooks_repo')
|
||||
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.require_installed()
|
||||
with ruby.in_env(repo.cmd_runner, 'default'):
|
||||
output = cmd_output('gem', 'list', '--local')[1]
|
||||
assert 'thread_safe' in output
|
||||
assert 'tins' in output
|
||||
|
||||
|
||||
@skipif_slowtests_false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue