Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for requirements.txt using both --index-url and --find-links #2959

Merged
merged 1 commit into from
Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/2959.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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