From 385afa40ba9f778e785a1252bf201a886776e94b Mon Sep 17 00:00:00 2001 From: TJ Date: Fri, 8 Sep 2023 12:54:33 -0700 Subject: [PATCH 1/3] Handle FileNotFoundError --- docs/changelog/3105.bugfix.rst | 1 + src/tox/tox_env/python/virtual_env/api.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/3105.bugfix.rst diff --git a/docs/changelog/3105.bugfix.rst b/docs/changelog/3105.bugfix.rst new file mode 100644 index 000000000..dd87507cd --- /dev/null +++ b/docs/changelog/3105.bugfix.rst @@ -0,0 +1 @@ +Handle ``FileNotFoundError`` when the ``base_python`` interpreter doesn't exist diff --git a/src/tox/tox_env/python/virtual_env/api.py b/src/tox/tox_env/python/virtual_env/api.py index 706f7ea44..c1c507247 100644 --- a/src/tox/tox_env/python/virtual_env/api.py +++ b/src/tox/tox_env/python/virtual_env/api.py @@ -132,7 +132,7 @@ def _get_python(self, base_python: list[str]) -> PythonInfo | None: # noqa: ARG # the base pythons are injected into the virtualenv_env_vars, so we don't need to use it here try: interpreter = self.creator.interpreter - except RuntimeError: # if can't find + except (FileNotFoundError, RuntimeError): # Unable to find the interpreter return None return PythonInfo( implementation=interpreter.implementation, From e5282a6b6ddac8caaa840380c5a6a8a72784ebbc Mon Sep 17 00:00:00 2001 From: TJ Date: Fri, 8 Sep 2023 13:26:42 -0700 Subject: [PATCH 2/3] Add unittest --- tests/tox_env/python/test_python_api.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/tox_env/python/test_python_api.py b/tests/tox_env/python/test_python_api.py index 159d9d772..a514f09f3 100644 --- a/tests/tox_env/python/test_python_api.py +++ b/tests/tox_env/python/test_python_api.py @@ -277,3 +277,13 @@ def test_list_installed_deps_explicit_cli( assert "pip==" in result.out else: assert "pip==" not in result.out + + +def test_usedevelop_with_nonexistent_basepython(tox_project: ToxProjectCreator) -> None: + project = tox_project( + { + "tox.ini": "[testenv]\nusedevelop = true\n[testenv:unused]\nbasepython = /nonexistent/bin/python", + }, + ) + result = project.run() + assert result.code == 0 From 0324acdcd7c29c9825009e27f2ad1bdda3d582f2 Mon Sep 17 00:00:00 2001 From: TJ Date: Fri, 8 Sep 2023 15:12:00 -0700 Subject: [PATCH 3/3] PR feedback --- tests/tox_env/python/test_python_api.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/tox_env/python/test_python_api.py b/tests/tox_env/python/test_python_api.py index a514f09f3..e56d9d698 100644 --- a/tests/tox_env/python/test_python_api.py +++ b/tests/tox_env/python/test_python_api.py @@ -280,10 +280,7 @@ def test_list_installed_deps_explicit_cli( def test_usedevelop_with_nonexistent_basepython(tox_project: ToxProjectCreator) -> None: - project = tox_project( - { - "tox.ini": "[testenv]\nusedevelop = true\n[testenv:unused]\nbasepython = /nonexistent/bin/python", - }, - ) + ini = "[testenv]\nusedevelop = true\n[testenv:unused]\nbasepython = /nonexistent/bin/python" + project = tox_project({"tox.ini": ini}) result = project.run() assert result.code == 0