From 50a9d90c04eb672d35d516b32c802760a0736a23 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Tue, 13 May 2025 20:36:35 -0400 Subject: [PATCH 1/2] _bootstrap_python: Fix execution on windows disabling site import This workaround the lack of `sys.winver` attribute addressing the following error: ``` Generating C:/path/to/Python-3.11.12/Python/deepfreeze/deepfreeze.c CUSTOMBUILD : Fatal Python error : init_import_site: Failed to import the site module [C:\path\to\pycbs-3.11-build\CMakeBuild\libpython\libpython-shared.vcxproj] Python runtime state: initialized Traceback (most recent call last): File "C:\path\to\pycbs-3.11-build\Lib\site.py", line 626, in main() File "C:\path\to\pycbs-3.11-build\Lib\site.py", line 612, in main known_paths = addusersitepackages(known_paths) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\path\to\pycbs-3.11-build\Lib\site.py", line 350, in addusersitepackages user_site = getusersitepackages() ^^^^^^^^^^^^^^^^^^^^^ File "C:\path\to\pycbs-3.11-build\Lib\site.py", line 337, in getusersitepackages USER_SITE = _get_path(userbase) ^^^^^^^^^^^^^^^^^^^ File "C:\path\to\pycbs-3.11-build\Lib\site.py", line 302, in _get_path ver_nodot = sys.winver.replace('.', '') ^^^^^^^^^^ AttributeError: module 'sys' has no attribute 'winver' ``` --- Programs/_bootstrap_python.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Programs/_bootstrap_python.c b/Programs/_bootstrap_python.c index 6ecbf0c72b5ff4..136c187758d1bc 100644 --- a/Programs/_bootstrap_python.c +++ b/Programs/_bootstrap_python.c @@ -72,6 +72,9 @@ main(int argc, char **argv) // add current script dir to sys.path config.isolated = 0; config.safe_path = 0; +#ifdef MS_WINDOWS + config.site_import = 0; +#endif #ifdef MS_WINDOWS status = PyConfig_SetArgv(&config, argc, argv); From 646608c7fd9f8ff0c97bb587b6273b1791604e2a Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Fri, 30 May 2025 14:54:08 -0400 Subject: [PATCH 2/2] getpath: Update build directory assumptions based on python-cmake-buildsystem This ensures the following tests pass: - `test_sys` (`SysModuleTest.test_stdlib_dir`) - `test_frozen` (`TestFrozen.test_unfrozen_submodule_in_frozen_package`) --- Lib/test/test_getpath.py | 12 ++++++------ Modules/getpath.py | 10 +++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_getpath.py b/Lib/test/test_getpath.py index 5208374e20013c..3a3168a6dbbac9 100644 --- a/Lib/test/test_getpath.py +++ b/Lib/test/test_getpath.py @@ -278,7 +278,7 @@ def test_buildpath_posix(self): ns.add_known_xfile("/home/cpython/python") ns.add_known_xfile("/usr/local/bin/python") ns.add_known_file("/home/cpython/pybuilddir.txt", ["build/lib.linux-x86_64-9.8"]) - ns.add_known_file("/home/cpython/Lib/os.py") + ns.add_known_file("/home/cpython/lib/python9.8/os.py") ns.add_known_dir("/home/cpython/lib-dynload") expected = dict( executable="/home/cpython/python", @@ -290,7 +290,7 @@ def test_buildpath_posix(self): module_search_paths_set=1, module_search_paths=[ "/usr/local/lib/python98.zip", - "/home/cpython/Lib", + "/home/cpython/lib/python9.8", "/home/cpython/build/lib.linux-x86_64-9.8", ], ) @@ -402,7 +402,7 @@ def test_symlink_buildpath_posix(self): ns.add_known_link("/linkfrom/python", "/home/cpython/python") ns.add_known_xfile("/usr/local/bin/python") ns.add_known_file("/home/cpython/pybuilddir.txt", ["build/lib.linux-x86_64-9.8"]) - ns.add_known_file("/home/cpython/Lib/os.py") + ns.add_known_file("/home/cpython/lib/python9.8/os.py") ns.add_known_dir("/home/cpython/lib-dynload") expected = dict( executable="/linkfrom/python", @@ -414,7 +414,7 @@ def test_symlink_buildpath_posix(self): module_search_paths_set=1, module_search_paths=[ "/usr/local/lib/python98.zip", - "/home/cpython/Lib", + "/home/cpython/lib/python9.8", "/home/cpython/build/lib.linux-x86_64-9.8", ], ) @@ -709,7 +709,7 @@ def test_symlink_buildpath_macos(self): ns.add_known_link("/linkfrom/python", "/home/cpython/python") ns.add_known_xfile("/usr/local/bin/python") ns.add_known_file("/home/cpython/pybuilddir.txt", ["build/lib.macos-9.8"]) - ns.add_known_file("/home/cpython/Lib/os.py") + ns.add_known_file("/home/cpython/lib/python9.8/os.py") ns.add_known_dir("/home/cpython/lib-dynload") expected = dict( executable="/linkfrom/python", @@ -721,7 +721,7 @@ def test_symlink_buildpath_macos(self): module_search_paths_set=1, module_search_paths=[ "/usr/local/lib/python98.zip", - "/home/cpython/Lib", + "/home/cpython/lib/python9.8", "/home/cpython/build/lib.macos-9.8", ], ) diff --git a/Modules/getpath.py b/Modules/getpath.py index dceeed7702c0be..775614f531d868 100644 --- a/Modules/getpath.py +++ b/Modules/getpath.py @@ -180,7 +180,7 @@ STDLIB_SUBDIR = f'{platlibdir}/python{VERSION_MAJOR}.{VERSION_MINOR}' STDLIB_LANDMARKS = [f'{STDLIB_SUBDIR}/os.py', f'{STDLIB_SUBDIR}/os.pyc'] PLATSTDLIB_LANDMARK = f'{platlibdir}/python{VERSION_MAJOR}.{VERSION_MINOR}/lib-dynload' - BUILDSTDLIB_LANDMARKS = ['Lib/os.py'] + BUILDSTDLIB_LANDMARKS = [f'lib/python{VERSION_MAJOR}.{VERSION_MINOR}/os.py'] VENV_LANDMARK = 'pyvenv.cfg' ZIP_LANDMARK = f'{platlibdir}/python{VERSION_MAJOR}{VERSION_MINOR}.zip' DELIM = ':' @@ -491,10 +491,14 @@ def search_up(prefix, *landmarks, test=isfile): else: build_stdlib_prefix = search_up(build_prefix, *BUILDSTDLIB_LANDMARKS) # Always use the build prefix for stdlib + if os_name == 'nt': + lib = 'Lib' + else: + lib = f'lib/python{VERSION_MAJOR}.{VERSION_MINOR}' if build_stdlib_prefix: - stdlib_dir = joinpath(build_stdlib_prefix, 'Lib') + stdlib_dir = joinpath(build_stdlib_prefix, lib) else: - stdlib_dir = joinpath(build_prefix, 'Lib') + stdlib_dir = joinpath(build_prefix, lib) # Only use the build prefix for prefix if it hasn't already been set if not prefix: prefix = build_stdlib_prefix