From 0e3776e00cb9a78771c249cdaed2a57c6f84ea49 Mon Sep 17 00:00:00 2001 From: Alexander Clausen Date: Sun, 26 Mar 2023 16:25:48 +0200 Subject: 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' --- docs/changelog/2959.bugfix.rst | 1 + src/tox/tox_env/python/pip/req/file.py | 4 ++-- tests/tox_env/python/pip/req/test_file.py | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 docs/changelog/2959.bugfix.rst 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"), -- cgit v1.2.1