Keep dependency in order - #482
Conversation
There was a problem hiding this comment.
So we do lose set semantics here, can you add a test with multiple hooks that have the same additional dependencies and verify that there are not duplicates?
There was a problem hiding this comment.
Well, the current set implementation is already accepting the same dependency listed at different versions. We could keep the same behaviour by handling duplicates manually:
for dep in hook.get('additional_dependencies', []):
if dep not in dep_dict[hook['language']][hook['language_version']]:
dep_dict[hook['language']][hook['language_version']].append(dep)An other option would be to extract the name and the version for each dependency (needs to be implemented for each language though) and then either:
- keep only the first version of each package
- issue a warning to the user
- raise an exception
and then implement tests accordingly, what would you prefer?
There was a problem hiding this comment.
The former is fine, I don't want to add language-specific parsing of this stuff if avoidable.
Heh, if we could only target python3.6 (or modern pypy), the set would have insertion order
| logger.warning( | ||
| 'Additional dependency {} is listed twice for hook ' | ||
| '{}'.format(dep, hook['name']) | ||
| ) |
There was a problem hiding this comment.
A warning should not be raised here.
This is a perfectly valid configuration:
hooks:
- id: puppet-validate
language_version: '2.1.5'
additional_dependencies: ['puppet:4.5.3']
- id: epp-validate
language_version: '2.1.5'
additional_dependencies: ['puppet:4.5.3']There was a problem hiding this comment.
Maybe we can keep the code change smaller by making something like this:
class _UniqueList(list):
def __init__(self):
self._set = set()
def update(self, obj):
for item in obj:
if item not in self._set:
self.append(item)And then the diff is just
- dep_dict = defaultdict(lambda: defaultdict(set))
+ dep_dict = defaultdict(lambda: defaultdict(_UniqueList))There was a problem hiding this comment.
👍
Let me know if you want me to squash commits
|
I squashed the commit. Everything allright? |
|
Yep! I was waiting for the build and didn't notice it in my 50 tabs 🤣 Thanks for the contribution! |
|
Thanks for reactivity! |

I was investigating pre-commit/pre-commit-mirror-maker#20 and realized running
gem install gem1:version1 gem2:versioncan give different result fromgem install gem2:version2 gem1:version1.This PR keeps the list of additional dependencies of an hook in the order they appeared in the
.pre-commit-config.yaml.