diff --git a/pre_commit_hooks/requirements_txt_fixer.py b/pre_commit_hooks/requirements_txt_fixer.py index 7849767..2c67d51 100644 --- a/pre_commit_hooks/requirements_txt_fixer.py +++ b/pre_commit_hooks/requirements_txt_fixer.py @@ -34,6 +34,10 @@ class Requirement: assert m is not None name = m.group() + if name == b'-i' or name.startswith(b'--index-url='): + return b'--index-url' + elif name.startswith(b'--extra-index-url='): + return b'--extra-index-url' m = self.UNTIL_COMPARISON.search(name) if not m: return name diff --git a/tests/requirements_txt_fixer_test.py b/tests/requirements_txt_fixer_test.py index bb75daa..6991bcd 100644 --- a/tests/requirements_txt_fixer_test.py +++ b/tests/requirements_txt_fixer_test.py @@ -116,6 +116,24 @@ from pre_commit_hooks.requirements_txt_fixer import Requirement b'--extra-index-url https://example.com/simple\n' b'requests\n', ), + ( + b'--extra-index-url https://example.com/simple\n' + b'-i https://pypi.org/simple\n' + b'requests\n', + FAIL, + b'-i https://pypi.org/simple\n' + b'--extra-index-url https://example.com/simple\n' + b'requests\n', + ), + ( + b'--extra-index-url=https://example.com/simple\n' + b'--index-url=https://pypi.org/simple\n' + b'requests\n', + FAIL, + b'--index-url=https://pypi.org/simple\n' + b'--extra-index-url=https://example.com/simple\n' + b'requests\n', + ), ), ) def test_integration(input_s, expected_retval, output, tmpdir):