Skip to content

Commit

Permalink
Remove duplicated elements
Browse files Browse the repository at this point in the history
  • Loading branch information
HeySlava authored and Vyacheslav Kapitonov committed Sep 27, 2023
1 parent 516a8a2 commit 670f16c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pre_commit_hooks/requirements_txt_fixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def fix_requirements(f: IO[bytes]) -> int:
for requirement in sorted(requirements):
after.extend(requirement.comments)
assert requirement.value, requirement.value
after.append(requirement.value)
if requirement.value not in after:
after.append(requirement.value)
after.extend(rest)

after_string = b''.join(after)
Expand Down
2 changes: 2 additions & 0 deletions tests/requirements_txt_fixer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
PASS,
b'a=2.0.0 \\\n --hash=sha256:abcd\nb==1.0.0\n',
),
(b'\nfoo\nfoo\n', FAIL, b'\nfoo\n'),
(b'\nbar\nfoo\nbar\n', FAIL, b'\nbar\nfoo\n'),
),
)
def test_integration(input_s, expected_retval, output, tmpdir):
Expand Down

0 comments on commit 670f16c

Please sign in to comment.