diff --git a/scripts/build.cmd b/scripts/build.cmd index bf420da..a2ac2b0 100644 --- a/scripts/build.cmd +++ b/scripts/build.cmd @@ -8,10 +8,28 @@ cd /d "%~dp0\.." set VENV_DIR=.venv-platformio +REM Prefer the "py" launcher (ships with official Python installer) which +REM reliably picks Python 3, even if "python" on PATH points to an old +REM Python 2.x install. +where py >nul 2>nul +if %errorlevel%==0 ( + set PYTHON_CMD=py -3 +) else ( + set PYTHON_CMD=python +) + if not exist "%VENV_DIR%" ( - echo Creating local virtualenv in %VENV_DIR% ... - python -m venv "%VENV_DIR%" - "%VENV_DIR%\Scripts\pip.exe" install --upgrade pip + echo Creating local virtualenv in %VENV_DIR% using: %PYTHON_CMD% + %PYTHON_CMD% -m venv "%VENV_DIR%" + if not exist "%VENV_DIR%\Scripts\python.exe" ( + echo. + echo ERROR: Could not create a Python 3 virtualenv. + echo Make sure Python 3 is installed from https://www.python.org/downloads/ + echo and that "py -3 --version" or "python --version" reports Python 3.x + echo ^(your "python" currently points to: %PYTHON_CMD%^) + exit /b 1 + ) + "%VENV_DIR%\Scripts\python.exe" -m pip install --upgrade pip "%VENV_DIR%\Scripts\pip.exe" install platformio ) diff --git a/scripts/deploy.cmd b/scripts/deploy.cmd index 958464c..5385751 100644 --- a/scripts/deploy.cmd +++ b/scripts/deploy.cmd @@ -12,10 +12,25 @@ cd /d "%~dp0\.." set VENV_DIR=.venv-platformio +where py >nul 2>nul +if %errorlevel%==0 ( + set PYTHON_CMD=py -3 +) else ( + set PYTHON_CMD=python +) + if not exist "%VENV_DIR%" ( - echo Creating local virtualenv in %VENV_DIR% ... - python -m venv "%VENV_DIR%" - "%VENV_DIR%\Scripts\pip.exe" install --upgrade pip + echo Creating local virtualenv in %VENV_DIR% using: %PYTHON_CMD% + %PYTHON_CMD% -m venv "%VENV_DIR%" + if not exist "%VENV_DIR%\Scripts\python.exe" ( + echo. + echo ERROR: Could not create a Python 3 virtualenv. + echo Make sure Python 3 is installed from https://www.python.org/downloads/ + echo and that "py -3 --version" or "python --version" reports Python 3.x + echo ^(your "python" currently points to: %PYTHON_CMD%^) + exit /b 1 + ) + "%VENV_DIR%\Scripts\python.exe" -m pip install --upgrade pip "%VENV_DIR%\Scripts\pip.exe" install platformio ) diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 0000000..707bfcb --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Build + flash the M5Stack Dashboard project via PlatformIO on Linux/macOS. +# +# Usage: +# ./scripts/deploy.sh # auto-detect USB port +# ./scripts/deploy.sh /dev/ttyUSB0 # force a specific port +# +# This script intentionally does NOT open the serial monitor afterwards. +# Uses the same local virtualenv as build.sh, created automatically if missing. + +cd "$(dirname "$0")/.." + +VENV_DIR=".venv-platformio" + +if [ ! -d "$VENV_DIR" ]; then + echo "Creating local virtualenv in $VENV_DIR ..." + python3 -m venv "$VENV_DIR" + "$VENV_DIR/bin/pip" install --upgrade pip + "$VENV_DIR/bin/pip" install platformio +fi + +PIO="$VENV_DIR/bin/pio" + +if [ "$#" -ge 1 ]; then + PORT="$1" + echo "Using forced upload port: $PORT" + "$PIO" run --target upload --upload-port "$PORT" +else + echo "Auto-detecting upload port..." + "$PIO" run --target upload +fi + +echo "Build + flash complete."