File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ Patch get_interpreter to handle missing cache and app_data - by :user: `esafak `
Original file line number Diff line number Diff line change @@ -77,6 +77,25 @@ def get_interpreter(
7777 cache = None ,
7878 env : Mapping [str , str ] | None = None ,
7979) -> PythonInfo | None :
80+ """
81+ Find an interpreter that matches a given specification.
82+
83+ :param key: the specification of the interpreter to find
84+ :param try_first_with: a list of interpreters to try first
85+ :param app_data: the application data folder
86+ :param cache: a cache of python information
87+ :param env: the environment to use
88+ :return: the interpreter if found, otherwise None
89+ """
90+ if cache is None :
91+ # Import locally to avoid a circular dependency
92+ from virtualenv .app_data import AppDataDisabled # noqa: PLC0415
93+ from virtualenv .cache import FileCache # noqa: PLC0415
94+
95+ if app_data is None :
96+ app_data = AppDataDisabled ()
97+ cache = FileCache (store_factory = app_data .py_info , clearer = app_data .py_info_clear )
98+
8099 spec = PythonSpec .from_string_spec (key )
81100 LOGGER .info ("find interpreter for spec %r" , spec )
82101 proposed_paths = set ()
Original file line number Diff line number Diff line change @@ -224,6 +224,18 @@ def test_returns_second_python_specified_when_more_than_one_is_specified_and_env
224224 assert result == mocker .sentinel .python_from_cli
225225
226226
227+ def test_get_interpreter_no_cache_no_app_data ():
228+ """Test that get_interpreter can be called without cache and app_data."""
229+ # A call to a valid interpreter should succeed and return a PythonInfo object.
230+ interpreter = get_interpreter (sys .executable , [])
231+ assert interpreter is not None
232+ assert Path (interpreter .executable ).is_file ()
233+
234+ # A call to an invalid interpreter should not fail and should return None.
235+ interpreter = get_interpreter ("a-python-that-does-not-exist" , [])
236+ assert interpreter is None
237+
238+
227239def test_discovery_absolute_path_with_try_first (tmp_path ):
228240 good_env = tmp_path / "good"
229241 bad_env = tmp_path / "bad"
You can’t perform that action at this time.
0 commit comments