[python3] add vcpkg_get_vcpkg_installed_python (#38929)

This commit is contained in:
Alexander Neumann 2024-06-17 20:36:07 +02:00 committed by GitHub
parent 79e4347293
commit 2324733d55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 91 additions and 3 deletions

View File

@ -384,4 +384,10 @@ else()
file(COPY_FILE "${CURRENT_PACKAGES_DIR}/tools/python3/python3.${PYTHON_VERSION_MINOR}" "${CURRENT_PACKAGES_DIR}/tools/python3/python3")
endif()
configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-port-config.cmake" "${CURRENT_PACKAGES_DIR}/share/python3/vcpkg-port-config.cmake" @ONLY)
configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-port-config.cmake" "${CURRENT_PACKAGES_DIR}/share/python3/vcpkg-port-config.cmake" @ONLY)
# For testing
block()
set(CURRENT_HOST_INSTALLED_DIR "${CURRENT_PACKAGES_DIR}")
vcpkg_get_vcpkg_installed_python(VCPKG_PYTHON3)
endblocK()

View File

@ -10,3 +10,4 @@ else()
endif()
set(PYTHON3_SITE "${site_base}/site-packages")
include("${CURRENT_HOST_INSTALLED_DIR}/share/vcpkg-get-python/vcpkg-port-config.cmake")

View File

@ -1,7 +1,7 @@
{
"name": "python3",
"version": "3.11.8",
"port-version": 2,
"port-version": 3,
"description": "The Python programming language",
"homepage": "https://github.com/python/cpython",
"license": "Python-2.0",
@ -44,6 +44,10 @@
"name": "sqlite3",
"platform": "!(windows & static)"
},
{
"name": "vcpkg-get-python",
"host": true
},
{
"name": "vcpkg-msbuild",
"host": true,

View File

@ -0,0 +1,7 @@
file(INSTALL
"${CMAKE_CURRENT_LIST_DIR}/vcpkg-port-config.cmake"
DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
vcpkg_install_copyright(FILE_LIST "${VCPKG_ROOT_DIR}/LICENSE.txt")
set(VCPKG_POLICY_CMAKE_HELPER_PORT enabled)

View File

@ -0,0 +1,46 @@
function(vcpkg_get_vcpkg_installed_python out_python)
if(NOT VCPKG_TARGET_IS_WINDOWS)
# vcpkg installed python on !windows works as normal python would work.
set(${out_python} "${CURRENT_HOST_INSTALLED_DIR}/tools/python3/python3" PARENT_SCOPE)
return()
endif()
# On windows python is unable to lookup DLLs, so a manual venv is created
set(python_home "${CURRENT_HOST_INSTALLED_DIR}/tools/python3")
set(python_base "${CURRENT_BUILDTREES_DIR}/python-${TARGET_TRIPLET}")
file(GLOB python_files LIST_DIRECTORIES false "${python_home}/*")
if(EXISTS "${CURRENT_HOST_INSTALLED_DIR}/tools/python3/DLLs")
file(COPY "${CURRENT_HOST_INSTALLED_DIR}/tools/python3/DLLs/" DESTINATION "${python_base}/DLLs")
endif()
file(COPY ${python_files} DESTINATION "${python_base}/Scripts")
file(MAKE_DIRECTORY "${python_base}/Lib/site-packages")
file(WRITE "${python_base}/pyvenv.cfg"
"
home = ${python_home}
include-system-site-packages = false
version = ${PYTHON3_VERSION}
executable = ${python_home}/python.exe
command = ${python_home}/python.exe -m venv ${python_base}
"
)
file(WRITE "${python_base}/Lib/site-packages/sitecustomize.py"
"
import os
import sys
from pathlib import Path
import site
#enable direct lookup of installed site-packages without the need to copy them
site.addsitedir(sys.base_prefix + '/Lib/site-packages')
vcpkg_bin_path = Path(sys.base_prefix + '/../../bin')
if vcpkg_bin_path.is_dir():
os.add_dll_directory(vcpkg_bin_path)
"
)
set(${out_python} "${python_base}/Scripts/python.exe" PARENT_SCOPE)
endfunction()

View File

@ -0,0 +1,6 @@
{
"name": "vcpkg-get-python",
"version-date": "2024-06-08",
"license": "MIT",
"supports": "native"
}

View File

@ -7098,7 +7098,7 @@
},
"python3": {
"baseline": "3.11.8",
"port-version": 2
"port-version": 3
},
"qca": {
"baseline": "2.3.7",
@ -9104,6 +9104,10 @@
"baseline": "2023-12-31",
"port-version": 0
},
"vcpkg-get-python": {
"baseline": "2024-06-08",
"port-version": 0
},
"vcpkg-get-python-packages": {
"baseline": "2024-01-24",
"port-version": 0

View File

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "bd79c290d4768a376a9bb0de77cefb2e608e9bc7",
"version": "3.11.8",
"port-version": 3
},
{
"git-tree": "24bb8d2b3db0a12a7ca7f04061f632f0e94abcc2",
"version": "3.11.8",

View File

@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "829be9eea1ad30190a8bb66e4c8a46c9c6d5b0f5",
"version-date": "2024-06-08",
"port-version": 0
}
]
}