Skip to content

Commit

Permalink
nix_expr: Make list ordering deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Mar 27, 2020
1 parent 628b560 commit 1badb89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion nixops/nix_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,13 @@ def _merge(e1, e2):
if isinstance(e1, dict) and isinstance(e2, dict):
return _merge_dicts(e1, e2)
elif isinstance(e1, list) and isinstance(e2, list):
return list(set(e1).union(e2))
l = []
seen = set()
for x in e1 + e2:
if x not in seen:
seen.add(x)
l.append(x)
return l
else:
err = "unable to merge {0} with {1}".format(type(e1), type(e2))
raise ValueError(err)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_nix_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def assert_merge(self, sources, expect):
def test_merge_list(self):
self.assert_merge(
[[1, 2, 3], [4, 5, 6], [7, 6, 5], ["abc", "def"], ["ghi", "abc"],],
[1, 2, 3, 4, 5, 6, 7, "ghi", "def", "abc"],
[1, 2, 3, 4, 5, 6, 7, "abc", "def", "ghi"],
)

def test_merge_dict(self):
Expand Down

0 comments on commit 1badb89

Please sign in to comment.