Skip to content

Commit 2ad764e

Browse files
authored
fix run_python_test_script.py usage in external projects (#4448)
* fix run_python_test_script.py usage in external projects * fix run_python_test_script.py usage in external projects * fix run_python_test_script.py usage in external projects * fix run_python_test_script.py usage in external projects * fix run_python_test_script.py usage in external projects
1 parent 4551d78 commit 2ad764e

File tree

3 files changed

+53
-44
lines changed

3 files changed

+53
-44
lines changed

scripts/run_python_test_script.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1+
import argparse
12
import os
3+
import re
24
import sys
35
import platform
4-
import argparse
6+
import subprocess
57
import shutil
6-
7-
# Add current script directory to sys.path
8-
sys.path.insert(0, os.path.dirname(os.path.abspath("__file__")))
9-
10-
from utils import get_vcpkg_root_from_where, detect_vcpkg_python_version
8+
from pathlib import Path
9+
10+
def get_vcpkg_root_from_where():
11+
try:
12+
output = subprocess.check_output(["where", "vcpkg"], universal_newlines=True)
13+
first_line = output.strip().splitlines()[0]
14+
return Path(first_line).resolve().parent
15+
except Exception as e:
16+
print(e)
17+
return None
18+
19+
def detect_vcpkg_python_version(vcpkg_root, triplet="x64-windows-meshlib"):
20+
include_dir = vcpkg_root / "installed" / triplet / "include"
21+
if include_dir.exists():
22+
for entry in include_dir.iterdir():
23+
match = re.match(r"python3\.(\d+)", entry.name)
24+
if match:
25+
minor_version = match.group(1)
26+
return f"3.{minor_version}"
27+
return None
1128

1229
parser = argparse.ArgumentParser(description="Python Test Script")
1330

scripts/setup_win_python_reqs.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
11
import platform
2+
import re
3+
import os
24
import subprocess
5+
from pathlib import Path
36

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
615

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.")
935

1036
def run_python_setup(py_version: str):
1137
py_cmd = f"py -{py_version}"

scripts/utils.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)