Skip to content

Commit

Permalink
Fix for requirements.txt using both --index-url and --find-links (#2959)
Browse files Browse the repository at this point in the history
Without the fix, installation would fail with:

    AttributeError: 'Namespace' object has no attribute 'find_links'
  • Loading branch information
sk1p committed Mar 26, 2023
1 parent 10c58ff commit 0e3776e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog/2959.bugfix.rst
@@ -0,0 +1 @@
Fix ``--index-url`` and ``--find-links`` being used together in ``requirements.txt`` files.
4 changes: 2 additions & 2 deletions src/tox/tox_env/python/pip/req/file.py
Expand Up @@ -323,14 +323,14 @@ def _merge_option_line(self, base_opt: Namespace, opt: Namespace, filename: str)
if opt.find_links:
# FIXME: it would be nice to keep track of the source of the find_links: support a find-links local path
# relative to a requirements file.
if not hasattr(base_opt, "index_url"): # pragma: no branch
if not hasattr(base_opt, "find_links"):
base_opt.find_links = []
value = opt.find_links[0]
req_dir = os.path.dirname(os.path.abspath(filename))
relative_to_reqs_file = os.path.join(req_dir, value)
if os.path.exists(relative_to_reqs_file):
value = relative_to_reqs_file # pragma: no cover
if value not in base_opt.find_links: # pragma: no branch
if value not in base_opt.find_links:
base_opt.find_links.append(value)
if opt.pre:
base_opt.pre = True
Expand Down
10 changes: 10 additions & 0 deletions tests/tox_env/python/pip/req/test_file.py
Expand Up @@ -59,6 +59,16 @@
["-f", "http://some.archives.com/archives"],
id="find-links url",
),
pytest.param(
"--index-url a --find-links http://some.archives.com/archives",
{
"index_url": ["a"],
"find_links": ["http://some.archives.com/archives"],
},
[],
["-i", "a", "-f", "http://some.archives.com/archives"],
id="index and find",
),
pytest.param("-i a", {"index_url": ["a"]}, [], ["-i", "a"], id="index url short"),
pytest.param("--index-url a", {"index_url": ["a"]}, [], ["-i", "a"], id="index url long"),
pytest.param("-i a -i b\n-i c", {"index_url": ["c"]}, [], ["-i", "c"], id="index url multiple"),
Expand Down

0 comments on commit 0e3776e

Please sign in to comment.