Skip to content

Commit

Permalink
[python3] Do not ensurepip. Provide venv instructions. (#24906)
Browse files Browse the repository at this point in the history
* [python3] Bootstrap pip with ${CURRENT_INSTALLED_DIR}

* [python3] Disable ensurepip -- add venv usage instructions

Co-authored-by: Max Khon <fjoe@samodelkin.net>
  • Loading branch information
ras0219-msft and mkhon committed May 31, 2022
1 parent 145848f commit f78f444
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 15 deletions.
11 changes: 11 additions & 0 deletions ports/python3/0010-ensurepip.patch
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 14 additions & 13 deletions ports/python3/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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})
Expand Down
9 changes: 9 additions & 0 deletions ports/python3/usage.unix
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions ports/python3/usage.win
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion ports/python3/vcpkg.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -5658,7 +5658,7 @@
},
"python3": {
"baseline": "3.10.2",
"port-version": 1
"port-version": 2
},
"qca": {
"baseline": "2.3.4",
Expand Down
5 changes: 5 additions & 0 deletions versions/p-/python3.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "30321893b72abb4b682e3b66f75c54c1df3051c9",
"version": "3.10.2",
"port-version": 2
},
{
"git-tree": "4e348bd50d8c4252bda83903ce22f1e60d34be88",
"version": "3.10.2",
Expand Down

0 comments on commit f78f444

Please sign in to comment.