|
1 | 1 | import platform |
| 2 | +import re |
| 3 | +import os |
2 | 4 | import subprocess |
| 5 | +from pathlib import Path |
3 | 6 |
|
4 | | -# Add current script directory to sys.path |
5 | | -sys.path.insert(0, os.path.dirname(os.path.abspath("__file__"))) |
| 7 | +def get_vcpkg_root_from_where(): |
| 8 | + try: |
| 9 | + output = subprocess.check_output(["where", "vcpkg"], universal_newlines=True) |
| 10 | + first_line = output.strip().splitlines()[0] |
| 11 | + return Path(first_line).resolve().parent |
| 12 | + except Exception as e: |
| 13 | + print(e) |
| 14 | + return None |
6 | 15 |
|
7 | | -from utils import get_vcpkg_root_from_where, detect_vcpkg_python_version, choco_install_python |
8 | | -from pathlib import Path |
| 16 | +def detect_vcpkg_python_version(vcpkg_root, triplet="x64-windows-meshlib"): |
| 17 | + include_dir = vcpkg_root / "installed" / triplet / "include" |
| 18 | + if include_dir.exists(): |
| 19 | + for entry in include_dir.iterdir(): |
| 20 | + match = re.match(r"python3\.(\d+)", entry.name) |
| 21 | + if match: |
| 22 | + minor_version = match.group(1) |
| 23 | + return f"3.{minor_version}" |
| 24 | + return None |
| 25 | + |
| 26 | +def choco_install_python(version: str): |
| 27 | + version_nodot = version.replace('.', '') # "3.11" -> "311" |
| 28 | + choco_package = f"python{version_nodot}" |
| 29 | + try: |
| 30 | + print(f"Installing {choco_package} via Chocolatey...") |
| 31 | + subprocess.run(["choco", "install", choco_package, "-y"], check=True) |
| 32 | + print(f"Successfully installed {choco_package}") |
| 33 | + except subprocess.CalledProcessError: |
| 34 | + print(f"Failed to install {choco_package}. Check Chocolatey setup and try again.") |
9 | 35 |
|
10 | 36 | def run_python_setup(py_version: str): |
11 | 37 | py_cmd = f"py -{py_version}" |
|
0 commit comments