Automatically fix package=version in requirements.txt

This commit is contained in:
Paul Hooijenga 2018-10-23 21:26:37 +02:00
parent 86bfe8c475
commit f8b8997c07
2 changed files with 4 additions and 0 deletions

View file

@ -61,6 +61,9 @@ def fix_requirements(f):
elif line.startswith(b'#') or line.strip() == b'':
requirement.comments.append(line)
else:
# Automatically fix 'package=version' to 'package==version'
if b'=' in line and b'==' not in line and b'egg=' not in line:
line = line.replace(b'=', b'==')
requirement.value = line
# if a file ends in a comment, preserve it at the end

View file

@ -30,6 +30,7 @@ from pre_commit_hooks.requirements_txt_fixer import Requirement
),
(b'bar\npkg-resources==0.0.0\nfoo\n', FAIL, b'bar\nfoo\n'),
(b'foo\npkg-resources==0.0.0\nbar\n', FAIL, b'bar\nfoo\n'),
(b'foo=1\n', FAIL, b'foo==1\n'),
),
)
def test_integration(input_s, expected_retval, output, tmpdir):