From f78f4440df86358575dea65e748a39fdad41eb85 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Tue, 31 May 2022 16:20:33 -0700 Subject: [PATCH] [python3] Do not ensurepip. Provide venv instructions. (#24906) * [python3] Bootstrap pip with ${CURRENT_INSTALLED_DIR} * [python3] Disable ensurepip -- add venv usage instructions Co-authored-by: Max Khon --- ports/python3/0010-ensurepip.patch | 11 +++++++++++ ports/python3/portfile.cmake | 27 ++++++++++++++------------- ports/python3/usage.unix | 9 +++++++++ ports/python3/usage.win | 8 ++++++++ ports/python3/vcpkg.json | 2 +- versions/baseline.json | 2 +- versions/p-/python3.json | 5 +++++ 7 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 ports/python3/0010-ensurepip.patch create mode 100644 ports/python3/usage.unix create mode 100644 ports/python3/usage.win diff --git a/ports/python3/0010-ensurepip.patch b/ports/python3/0010-ensurepip.patch new file mode 100644 index 0000000000..ce5b65a3db --- /dev/null +++ b/ports/python3/0010-ensurepip.patch @@ -0,0 +1,11 @@ +--- a/Lib/ensurepip/__init__.py 2021-10-05 00:40:46.000000000 +0700 ++++ b/Lib/ensurepip/__init__.py 2022-01-11 15:22:54.001498300 +0700 +@@ -86,6 +86,8 @@ + code = f""" + import runpy + import sys ++import os ++sys.executable = os.path.dirname(os.path.realpath(__file__)) + sys.path = {additional_paths or []} + sys.path + sys.argv[1:] = {args} + runpy.run_module("pip", run_name="__main__", alter_sys=True) diff --git a/ports/python3/portfile.cmake b/ports/python3/portfile.cmake index d99a0fd673..144fd4b002 100644 --- a/ports/python3/portfile.cmake +++ b/ports/python3/portfile.cmake @@ -29,8 +29,9 @@ elseif(VCPKG_TARGET_IS_WINDOWS AND CMAKE_SYSTEM_VERSION EQUAL 6.1) message(FATAL_ERROR "python3 requires the feature deprecated-win7-support when building on Windows 7.") endif() -# The Windows 11 SDK has a problem that causes it to error on the resource files, so we patch that. if(VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_UWP) + string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" PYTHON_ALLOW_EXTENSIONS) + # The Windows 11 SDK has a problem that causes it to error on the resource files, so we patch that. vcpkg_get_windows_sdk(WINSDK_VERSION) if("${WINSDK_VERSION}" VERSION_GREATER_EQUAL "10.0.22000") list(APPEND PATCHES "0007-workaround-windows-11-sdk-rc-compiler-error.patch") @@ -70,7 +71,6 @@ endfunction() if(VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_UWP) # Due to the way Python handles C extension modules on Windows, a static python core cannot # load extension modules. - string(COMPARE EQUAL ${VCPKG_LIBRARY_LINKAGE} "dynamic" PYTHON_ALLOW_EXTENSIONS) if(PYTHON_ALLOW_EXTENSIONS) find_library(BZ2_RELEASE NAMES bz2 PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH) find_library(BZ2_DEBUG NAMES bz2d PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH) @@ -171,15 +171,6 @@ if(VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_UWP) file(GLOB PYTHON_INSTALLERS "${CURRENT_PACKAGES_DIR}/tools/${PORT}/wininst-*.exe") file(REMOVE ${PYTHON_LIBS} ${PYTHON_INSTALLERS}) - # The generated python executable must match the host arch - if(PYTHON_ALLOW_EXTENSIONS AND NOT VCPKG_CROSSCOMPILING) - message(STATUS "Bootstrapping pip") - vcpkg_execute_required_process(COMMAND python -m ensurepip - WORKING_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/${PORT}" - LOGNAME "ensurepip-${TARGET_TRIPLET}" - ) - endif() - # pkg-config files if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") make_python_pkgconfig(FILE python.pc INSTALL_ROOT ${CURRENT_PACKAGES_DIR} @@ -215,7 +206,7 @@ if(VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_UWP) else() set(OPTIONS "--with-openssl=${CURRENT_INSTALLED_DIR}" - "--with-ensurepip" + "--without-ensurepip" "--with-suffix=" "--with-system-expat" "--without-readline" @@ -255,7 +246,17 @@ else() vcpkg_fixup_pkgconfig() endif() -file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") +file(READ "${CMAKE_CURRENT_LIST_DIR}/usage" usage) +if(VCPKG_TARGET_IS_WINDOWS) + if(PYTHON_ALLOW_EXTENSIONS) + file(READ "${CMAKE_CURRENT_LIST_DIR}/usage.win" usage_extra) + else() + set(usage_extra "") + endif() +else() + file(READ "${CMAKE_CURRENT_LIST_DIR}/usage.unix" usage_extra) +endif() +file(WRITE "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage" "${usage}\n${usage_extra}") function(_generate_finder) cmake_parse_arguments(PythonFinder "NO_OVERRIDE" "DIRECTORY;PREFIX" "" ${ARGN}) diff --git a/ports/python3/usage.unix b/ports/python3/usage.unix new file mode 100644 index 0000000000..614292c2ff --- /dev/null +++ b/ports/python3/usage.unix @@ -0,0 +1,9 @@ +The package python3 provides a python interpreter that supports virtual environments: + + $ tools/python3/python3.10 -m venv /path/to/venv + $ export VIRTUAL_ENV=/path/to/venv + $ export PATH=/path/to/venv/bin:$PATH + $ export -n PYTHONHOME + $ unset PYTHONHOME + + See https://docs.python.org/3/library/venv.html for more details. diff --git a/ports/python3/usage.win b/ports/python3/usage.win new file mode 100644 index 0000000000..3fcc343ed8 --- /dev/null +++ b/ports/python3/usage.win @@ -0,0 +1,8 @@ +The package python3 provides a python interpreter that supports virtual environments: + + >tools\python3\python3.10 -m venv c:\path\to\venv + >set VIRTUAL_ENV=c:\path\to\venv + >set PATH=c:\path\to\venv\bin;%PATH% + >set PYTHONHOME= + + See https://docs.python.org/3/library/venv.html for more details. diff --git a/ports/python3/vcpkg.json b/ports/python3/vcpkg.json index 1a2ec91100..21ee84f93d 100644 --- a/ports/python3/vcpkg.json +++ b/ports/python3/vcpkg.json @@ -1,7 +1,7 @@ { "name": "python3", "version": "3.10.2", - "port-version": 1, + "port-version": 2, "description": "The Python programming language", "homepage": "https://github.com/python/cpython", "license": "Python-2.0", diff --git a/versions/baseline.json b/versions/baseline.json index fda507443e..17f604404b 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -5658,7 +5658,7 @@ }, "python3": { "baseline": "3.10.2", - "port-version": 1 + "port-version": 2 }, "qca": { "baseline": "2.3.4", diff --git a/versions/p-/python3.json b/versions/p-/python3.json index a89a02eb10..36df2f98ae 100644 --- a/versions/p-/python3.json +++ b/versions/p-/python3.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "30321893b72abb4b682e3b66f75c54c1df3051c9", + "version": "3.10.2", + "port-version": 2 + }, { "git-tree": "4e348bd50d8c4252bda83903ce22f1e60d34be88", "version": "3.10.2",