Skip to content

Commit 36a1c0e

Browse files
author
Louis Shawn
committed
fix(requirements-txt-fixer): handle -i and --index-url= forms
1 parent 918dc64 commit 36a1c0e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pre_commit_hooks/requirements_txt_fixer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def name(self) -> bytes:
3434
assert m is not None
3535

3636
name = m.group()
37+
if name == b'-i' or name.startswith(b'--index-url='):
38+
return b'--index-url'
39+
elif name.startswith(b'--extra-index-url='):
40+
return b'--extra-index-url'
3741
m = self.UNTIL_COMPARISON.search(name)
3842
if not m:
3943
return name

tests/requirements_txt_fixer_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@
116116
b'--extra-index-url https://example.com/simple\n'
117117
b'requests\n',
118118
),
119+
(
120+
b'--extra-index-url https://example.com/simple\n'
121+
b'-i https://pypi.org/simple\n'
122+
b'requests\n',
123+
FAIL,
124+
b'-i https://pypi.org/simple\n'
125+
b'--extra-index-url https://example.com/simple\n'
126+
b'requests\n',
127+
),
128+
(
129+
b'--extra-index-url=https://example.com/simple\n'
130+
b'--index-url=https://pypi.org/simple\n'
131+
b'requests\n',
132+
FAIL,
133+
b'--index-url=https://pypi.org/simple\n'
134+
b'--extra-index-url=https://example.com/simple\n'
135+
b'requests\n',
136+
),
119137
),
120138
)
121139
def test_integration(input_s, expected_retval, output, tmpdir):

0 commit comments

Comments
 (0)