mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
gh-99370: Calculate zip path from prefix when in a venv (GH-99371)
Before python3.11, when in a venv the zip path is calculated
from prefix on POSIX platforms. In python3.11 the behavior is
accidentally changed to calculating from default prefix. This
change will break venv created from a non-installed python
with a stdlib zip file. This commit restores the behavior back
to before python3.11.
(cherry picked from commit e3d4fed074
)
Co-authored-by: Kai Zhang <kylerzhang11@gmail.com>
This commit is contained in:
parent
3b8bcfc789
commit
5971a65d07
4 changed files with 99 additions and 2 deletions
|
@ -383,6 +383,39 @@ class MockGetPathTests(unittest.TestCase):
|
|||
actual = getpath(ns, expected)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_venv_non_installed_zip_path_posix(self):
|
||||
"Test a venv created from non-installed python has correct zip path."""
|
||||
ns = MockPosixNamespace(
|
||||
argv0="/venv/bin/python",
|
||||
PREFIX="/usr",
|
||||
ENV_PATH="/venv/bin:/usr/bin",
|
||||
)
|
||||
ns.add_known_xfile("/path/to/non-installed/bin/python")
|
||||
ns.add_known_xfile("/venv/bin/python")
|
||||
ns.add_known_link("/venv/bin/python",
|
||||
"/path/to/non-installed/bin/python")
|
||||
ns.add_known_file("/path/to/non-installed/lib/python9.8/os.py")
|
||||
ns.add_known_dir("/path/to/non-installed/lib/python9.8/lib-dynload")
|
||||
ns.add_known_file("/venv/pyvenv.cfg", [
|
||||
r"home = /path/to/non-installed"
|
||||
])
|
||||
expected = dict(
|
||||
executable="/venv/bin/python",
|
||||
prefix="/path/to/non-installed",
|
||||
exec_prefix="/path/to/non-installed",
|
||||
base_executable="/path/to/non-installed/bin/python",
|
||||
base_prefix="/path/to/non-installed",
|
||||
base_exec_prefix="/path/to/non-installed",
|
||||
module_search_paths_set=1,
|
||||
module_search_paths=[
|
||||
"/path/to/non-installed/lib/python98.zip",
|
||||
"/path/to/non-installed/lib/python9.8",
|
||||
"/path/to/non-installed/lib/python9.8/lib-dynload",
|
||||
],
|
||||
)
|
||||
actual = getpath(ns, expected)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_venv_changed_name_copy_posix(self):
|
||||
"Test a venv --copies layout on *nix that lacks a distributed 'python'"
|
||||
ns = MockPosixNamespace(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue