Skip to content

Commit 7aaa81e

Browse files
authored
Merge pull request #95 from DavidCEllis/fix-container-pythons
Use the original path instead of sys.executable
2 parents 6d5a2ba + d5431fd commit 7aaa81e

3 files changed

Lines changed: 28 additions & 17 deletions

File tree

src/ducktools/pythonfinder/shared.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ def query_install(
278278
if metadata:
279279
output["metadata"].update(metadata)
280280

281+
if exe_path != output["executable"]:
282+
output["metadata"]["sys_executable"] = output["executable"]
283+
output["executable"] = exe_path
284+
281285
install = PythonInstall.from_json(**output, managed_by=managed_by)
282286

283287
return install

tests/test_cache.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
# ducktools-pythonfinder
22
# MIT License
3-
#
3+
#
44
# Copyright (c) 2025 David C Ellis
5-
#
5+
#
66
# Permission is hereby granted, free of charge, to any person obtaining a copy
77
# of this software and associated documentation files (the "Software"), to deal
88
# in the Software without restriction, including without limitation the rights
99
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1010
# copies of the Software, and to permit persons to whom the Software is
1111
# furnished to do so, subject to the following conditions:
12-
#
12+
#
1313
# The above copyright notice and this permission notice shall be included in all
1414
# copies or substantial portions of the Software.
15-
#
15+
#
1616
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1717
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1818
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1919
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2020
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
# SOFTWARE.
23+
import re
24+
import sys
2325
import os.path
2426
from types import SimpleNamespace
2527
from unittest.mock import patch
@@ -28,15 +30,16 @@
2830

2931
from ducktools.pythonfinder.shared import DetailFinder, PythonInstall
3032

31-
fake_python_path = "/path/to/python"
32-
example_json = """
33-
{
34-
"version": [3, 13, 2, "final", 0],
35-
"executable": "/path/to/python",
36-
"architecture": "64bit",
37-
"implementation": "cpython",
38-
"metadata": {"freethreaded": false}
39-
}
33+
fake_python_path = "/path/to/python" if sys.platform != "win32" else r"X:\path\to\python"
34+
json_python_path = re.escape(fake_python_path)
35+
example_json = f"""
36+
{{
37+
"version": [3, 13, 2, "final", 0],
38+
"executable": "{json_python_path}",
39+
"architecture": "64bit",
40+
"implementation": "cpython",
41+
"metadata": {{"freethreaded": false}}
42+
}}
4043
""".strip()
4144

4245
example_install = PythonInstall(
@@ -160,7 +163,7 @@ def test_clear_invalid_runtimes(run_mock, stat_mock, temp_finder):
160163
with temp_finder, patch("os.path.exists") as exists_patch:
161164
exists_patch.return_value = True
162165
temp_finder.clear_invalid_runtimes()
163-
166+
164167
save_mock.assert_not_called()
165168
assert os.path.abspath(fake_python_path) in temp_finder.raw_cache
166169

@@ -224,4 +227,4 @@ def test_changed_stat_invalidates(run_mock, temp_finder):
224227
details = temp_finder.get_install_details(fake_python_path)
225228

226229
assert temp_finder.raw_cache[fake_abspath]["mtime"] == 1739886572
227-
querymock.assert_called()
230+
querymock.assert_called()

tests/test_pyenv.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def test_pypy_version(fs, temp_finder):
249249

250250
ver_folder = "pypy3.10-7.3.15"
251251
tmpdir = os.path.expanduser("~/.pyenv/versions")
252+
homedir = os.path.expanduser("~")
252253

253254
mock_output = textwrap.dedent(
254255
"""
@@ -282,10 +283,13 @@ def test_pypy_version(fs, temp_finder):
282283

283284
out_version = PythonInstall(
284285
version=(3, 10, 13, "final", 0),
285-
executable="~/.pyenv/versions/pypy3.10-7.3.15/bin/pypy",
286+
executable=f"{homedir}/.pyenv/versions/pypy3.10-7.3.15/bin/python",
286287
architecture="64bit",
287288
implementation="pypy",
288-
metadata={"pypy_version": (7, 3, 15, "final", 0)},
289+
metadata={
290+
"pypy_version": (7, 3, 15, "final", 0),
291+
"sys_executable": "~/.pyenv/versions/pypy3.10-7.3.15/bin/pypy"
292+
},
289293
managed_by="pyenv",
290294
)
291295

0 commit comments

Comments
 (0)