Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python3] add vcpkg_get_vcpkg_installed_python #38929

Merged
merged 11 commits into from
Jun 17, 2024
8 changes: 7 additions & 1 deletion ports/python3/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
1 change: 1 addition & 0 deletions ports/python3/vcpkg-port-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
6 changes: 5 additions & 1 deletion ports/python3/vcpkg.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -44,6 +44,10 @@
"name": "sqlite3",
"platform": "!(windows & static)"
},
{
"name": "vcpkg-get-python",
"host": true
},
{
"name": "vcpkg-msbuild",
"host": true,
Expand Down
7 changes: 7 additions & 0 deletions ports/vcpkg-get-python/portfile.cmake
Original file line number Diff line number Diff line change
@@ -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)
46 changes: 46 additions & 0 deletions ports/vcpkg-get-python/vcpkg-port-config.cmake
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 6 additions & 0 deletions ports/vcpkg-get-python/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "vcpkg-get-python",
"version-date": "2024-06-08",
"license": "MIT",
"supports": "native"
}
6 changes: 5 additions & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -7098,7 +7098,7 @@
},
"python3": {
"baseline": "3.11.8",
"port-version": 2
"port-version": 3
},
"qca": {
"baseline": "2.3.7",
Expand Down Expand Up @@ -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
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": "bd79c290d4768a376a9bb0de77cefb2e608e9bc7",
"version": "3.11.8",
"port-version": 3
},
{
"git-tree": "24bb8d2b3db0a12a7ca7f04061f632f0e94abcc2",
"version": "3.11.8",
Expand Down
9 changes: 9 additions & 0 deletions versions/v-/vcpkg-get-python.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "829be9eea1ad30190a8bb66e4c8a46c9c6d5b0f5",
"version-date": "2024-06-08",
"port-version": 0
}
]
}