Fix amalgamation script to work with python3-only environments (#444)

- Use sys.executable in Python scripts (amalgamate.py, cmake_build.py) instead of hardcoded 'python'
- Update shell scripts to prefer python3 over python with fallback
- Fix scripts/run_tests.py to detect python3 for CPython benchmarking

This fixes the issue where the amalgamation script fails on Linux systems
that only have python3 available and no 'python' symlink.
This commit is contained in:
Kanika Kapoor 2025-12-27 00:42:53 +05:30
parent 1e2135e153
commit c7572c76ba
9 changed files with 31 additions and 13 deletions

View File

@ -5,7 +5,7 @@ import sys
import time import time
from typing import List, Dict from typing import List, Dict
assert os.system("python prebuild.py") == 0 assert os.system(f"{sys.executable} prebuild.py") == 0
ROOT = 'include/pocketpy' ROOT = 'include/pocketpy'
PUBLIC_HEADERS = ['config.h', 'export.h', 'vmath.h', 'pocketpy.h'] PUBLIC_HEADERS = ['config.h', 'export.h', 'vmath.h', 'pocketpy.h']

View File

@ -8,7 +8,7 @@ if ! type -P clang >/dev/null 2>&1; then
fi fi
echo "> Running prebuild.py... " echo "> Running prebuild.py... "
python prebuild.py command -v python3 >/dev/null 2>&1 && python3 prebuild.py || python prebuild.py
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "prebuild.py failed." echo "prebuild.py failed."

View File

@ -1,6 +1,9 @@
set -e set -e
python amalgamate.py # Use python3 if available, otherwise fall back to python
PYTHON=$(command -v python3 >/dev/null 2>&1 && echo python3 || echo python)
$PYTHON amalgamate.py
rm -rf build rm -rf build
mkdir build mkdir build
@ -20,4 +23,4 @@ cmake --build . --config Release
cd ../ cd ../
python scripts/merge_built_libraries.py build $PYTHON scripts/merge_built_libraries.py build

View File

@ -1,6 +1,9 @@
set -e set -e
python amalgamate.py # Use python3 if available, otherwise fall back to python
PYTHON=$(command -v python3 >/dev/null 2>&1 && echo python3 || echo python)
$PYTHON amalgamate.py
rm -rf build rm -rf build
mkdir build mkdir build
@ -27,8 +30,8 @@ cd ../
HEADERS="amalgamated/pocketpy.h" HEADERS="amalgamated/pocketpy.h"
python scripts/merge_built_libraries.py build/os64 $PYTHON scripts/merge_built_libraries.py build/os64
python scripts/merge_built_libraries.py build/simulatorarm64 $PYTHON scripts/merge_built_libraries.py build/simulatorarm64
xcodebuild -create-xcframework \ xcodebuild -create-xcframework \
-library build/os64/libpocketpy.a -headers $HEADERS \ -library build/os64/libpocketpy.a -headers $HEADERS \

View File

@ -1,6 +1,9 @@
set -e set -e
python prebuild.py # Use python3 if available, otherwise fall back to python
PYTHON=$(command -v python3 >/dev/null 2>&1 && echo python3 || echo python)
$PYTHON prebuild.py
rm -rf web/lib rm -rf web/lib
mkdir web/lib mkdir web/lib

View File

@ -2,7 +2,7 @@ import os
import sys import sys
import shutil import shutil
assert os.system("python prebuild.py") == 0 assert os.system(f"{sys.executable} prebuild.py") == 0
if not os.path.exists("build"): if not os.path.exists("build"):
os.mkdir("build") os.mkdir("build")

View File

@ -1,6 +1,9 @@
set -e set -e
python prebuild.py # Use python3 if available, otherwise fall back to python
PYTHON=$(command -v python3 >/dev/null 2>&1 && echo python3 || echo python)
$PYTHON prebuild.py
SRC=$(find src/ -name "*.c") SRC=$(find src/ -name "*.c")

View File

@ -1,12 +1,15 @@
set -e set -e
python prebuild.py # Use python3 if available, otherwise fall back to python
PYTHON=$(command -v python3 >/dev/null 2>&1 && echo python3 || echo python)
$PYTHON prebuild.py
SRC=$(find src/ -name "*.c") SRC=$(find src/ -name "*.c")
clang -std=c11 --coverage -O1 -Wfatal-errors -o main src2/main.c $SRC -Iinclude -DPK_ENABLE_OS=1 -lm -ldl -DNDEBUG clang -std=c11 --coverage -O1 -Wfatal-errors -o main src2/main.c $SRC -Iinclude -DPK_ENABLE_OS=1 -lm -ldl -DNDEBUG
python scripts/run_tests.py $PYTHON scripts/run_tests.py
# if prev error exit # if prev error exit
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then

View File

@ -2,11 +2,14 @@ import os
import sys import sys
import time import time
import subprocess import subprocess
import shutil
def test_file(filepath, cpython=False): def test_file(filepath, cpython=False):
if cpython: if cpython:
return os.system("python " + filepath) == 0 # Use python3 if available, otherwise fall back to python
python_cmd = shutil.which("python3") or shutil.which("python") or "python"
return os.system(f"{python_cmd} {filepath}") == 0
if sys.platform == 'win32': if sys.platform == 'win32':
code = os.system("main.exe " + filepath) code = os.system("main.exe " + filepath)
else: else: