summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Clausen <alex@gc-web.de>2023-03-26 16:25:48 +0200
committerGitHub <noreply@github.com>2023-03-26 07:25:48 -0700
commit0e3776e00cb9a78771c249cdaed2a57c6f84ea49 (patch)
tree736c38442f641fbbe77fde17f3e4d70b472b5265
parent10c58fface96857f00bb253b2b88c297d5baf5d5 (diff)
downloadtox-git-release-4.4.8.tar.gz
Fix for requirements.txt using both --index-url and --find-links (#2959)release-4.4.8
Without the fix, installation would fail with: AttributeError: 'Namespace' object has no attribute 'find_links'
-rw-r--r--docs/changelog/2959.bugfix.rst1
-rw-r--r--src/tox/tox_env/python/pip/req/file.py4
-rw-r--r--tests/tox_env/python/pip/req/test_file.py10
3 files changed, 13 insertions, 2 deletions
diff --git a/docs/changelog/2959.bugfix.rst b/docs/changelog/2959.bugfix.rst
new file mode 100644
index 00000000..993c334f
--- /dev/null
+++ b/docs/changelog/2959.bugfix.rst
@@ -0,0 +1 @@
+Fix ``--index-url`` and ``--find-links`` being used together in ``requirements.txt`` files.
diff --git a/src/tox/tox_env/python/pip/req/file.py b/src/tox/tox_env/python/pip/req/file.py
index d8b29558..8aad15d0 100644
--- a/src/tox/tox_env/python/pip/req/file.py
+++ b/src/tox/tox_env/python/pip/req/file.py
@@ -323,14 +323,14 @@ class RequirementsFile:
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
diff --git a/tests/tox_env/python/pip/req/test_file.py b/tests/tox_env/python/pip/req/test_file.py
index e387a8ac..a363328e 100644
--- a/tests/tox_env/python/pip/req/test_file.py
+++ b/tests/tox_env/python/pip/req/test_file.py
@@ -59,6 +59,16 @@ _REQ_FILE_TEST_CASES = [
["-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"),