Skip to content

Commit

Permalink
Sort format controls when writing them to output
Browse files Browse the repository at this point in the history
to ensure consistent results
  • Loading branch information
richafrank committed Mar 31, 2020
1 parent 692f6be commit 96d2281
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions piptools/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def write_trusted_hosts(self):
yield "--trusted-host {}".format(trusted_host)

def write_format_controls(self):
for nb in dedup(self.format_control.no_binary):
for nb in dedup(sorted(self.format_control.no_binary)):
yield "--no-binary {}".format(nb)
for ob in dedup(self.format_control.only_binary):
for ob in dedup(sorted(self.format_control.only_binary)):
yield "--only-binary {}".format(ob)

def write_find_links(self):
Expand Down
14 changes: 9 additions & 5 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,20 @@ def test_write_format_controls(writer):
Tests --no-binary/--only-binary options.
"""

# FormatControl actually expects sets, but we give it lists here to
# ensure that we are sorting them when writing.
writer.format_control = FormatControl(
no_binary=["psycopg2", "click"], only_binary=["pytz", "django"]
)
lines = list(writer.write_format_controls())

assert "--no-binary psycopg2" in lines
assert "--no-binary click" in lines

assert "--only-binary pytz" in lines
assert "--only-binary django" in lines
expected_lines = [
"--no-binary click",
"--no-binary psycopg2",
"--only-binary django",
"--only-binary pytz",
]
assert lines == expected_lines


@mark.parametrize(
Expand Down

0 comments on commit 96d2281

Please sign in to comment.