Skip to content

Commit 0e3776e

Browse files
authored
Fix for requirements.txt using both --index-url and --find-links (#2959)
Without the fix, installation would fail with: AttributeError: 'Namespace' object has no attribute 'find_links'
1 parent 10c58ff commit 0e3776e

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

docs/changelog/2959.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix ``--index-url`` and ``--find-links`` being used together in ``requirements.txt`` files.

src/tox/tox_env/python/pip/req/file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,14 @@ def _merge_option_line(self, base_opt: Namespace, opt: Namespace, filename: str)
323323
if opt.find_links:
324324
# FIXME: it would be nice to keep track of the source of the find_links: support a find-links local path
325325
# relative to a requirements file.
326-
if not hasattr(base_opt, "index_url"): # pragma: no branch
326+
if not hasattr(base_opt, "find_links"):
327327
base_opt.find_links = []
328328
value = opt.find_links[0]
329329
req_dir = os.path.dirname(os.path.abspath(filename))
330330
relative_to_reqs_file = os.path.join(req_dir, value)
331331
if os.path.exists(relative_to_reqs_file):
332332
value = relative_to_reqs_file # pragma: no cover
333-
if value not in base_opt.find_links: # pragma: no branch
333+
if value not in base_opt.find_links:
334334
base_opt.find_links.append(value)
335335
if opt.pre:
336336
base_opt.pre = True

tests/tox_env/python/pip/req/test_file.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@
5959
["-f", "http://some.archives.com/archives"],
6060
id="find-links url",
6161
),
62+
pytest.param(
63+
"--index-url a --find-links http://some.archives.com/archives",
64+
{
65+
"index_url": ["a"],
66+
"find_links": ["http://some.archives.com/archives"],
67+
},
68+
[],
69+
["-i", "a", "-f", "http://some.archives.com/archives"],
70+
id="index and find",
71+
),
6272
pytest.param("-i a", {"index_url": ["a"]}, [], ["-i", "a"], id="index url short"),
6373
pytest.param("--index-url a", {"index_url": ["a"]}, [], ["-i", "a"], id="index url long"),
6474
pytest.param("-i a -i b\n-i c", {"index_url": ["c"]}, [], ["-i", "c"], id="index url multiple"),

0 commit comments

Comments
 (0)