From 38064e056f3b457348b2da289a1eecc7a1380f10 Mon Sep 17 00:00:00 2001 From: drmext <71258889+drmext@users.noreply.github.com> Date: Thu, 25 Dec 2025 04:04:43 +0000 Subject: [PATCH] Fix --- make_venv_portable.bat | 46 ++++++++++++++++++++++++++++ start.bat | 68 ++++++++++-------------------------------- 2 files changed, 61 insertions(+), 53 deletions(-) create mode 100644 make_venv_portable.bat diff --git a/make_venv_portable.bat b/make_venv_portable.bat new file mode 100644 index 0000000..9610796 --- /dev/null +++ b/make_venv_portable.bat @@ -0,0 +1,46 @@ +@echo off + +cd /d %~dp0 + +REM breaks if special characters are in path +:make_venv_portable +set pyvenv="%~dp0.venv\pyvenv.cfg" +set pyvenvtemp="%~dp0.venv\pyvenv.tmp" +for /f "tokens=*" %%i in ('python -V') do set pyver=%%i +for /f %%i in ('where python') do set pypath=%%i +set v=home version executable command +for %%a in (%v%) do for /f "tokens=*" %%i in ('findstr /b %%a %pyvenv%') do set %%a=%%i +if exist %pyvenvtemp% del %pyvenvtemp% +setlocal enabledelayedexpansion +( + for /f "tokens=1* delims=:" %%a in ('findstr /n "^" %pyvenv%') do ( + set "line=%%b" + if "!line!"=="%home%" (set line=home = %pypath:~0,-11%) + if "!line!"=="%version%" (set line=version = %pyver:~7%) + if "!line!"=="%executable%" (set line=executable = %pypath%) + if "!line!"=="%command%" (set line=command = %pypath% -m venv %~dp0.venv) + echo(!line! + ) +) > %pyvenvtemp% +endlocal +del %pyvenv% +rename %pyvenvtemp% pyvenv.cfg + +set activate="%~dp0.venv\Scripts\activate.bat" +set activatetemp="%~dp0.venv\Scripts\activate.tmp" +for /f "tokens=*" %%i in ('findstr "VIRTUAL_ENV=" %activate%') do set virtual=%%i +if exist %activatetemp% del %activatetemp% +setlocal enabledelayedexpansion +( + for /f "tokens=1* delims=:" %%a in ('findstr /n "^" %activate%') do ( + set "line=%%b" + if "!line!"=="%virtual%" (set line=set "VIRTUAL_ENV=%~dp0.venv") + if "!line!"=="END" (set line=:END) + echo(!line! + ) +) > %activatetemp% +endlocal +del %activate% +rename "%activatetemp%" activate.bat + +pause diff --git a/start.bat b/start.bat index 3a12f39..e0c69ae 100644 --- a/start.bat +++ b/start.bat @@ -4,66 +4,28 @@ TITLE MB cd /d %~dp0 -REM goto :make_venv_portable +py --version 3 >nul 2>&1 +if errorlevel 1 goto install if not exist .venv\Scripts\activate.bat ( - python -m venv .venv -) - -( + py -m venv .venv .venv\Scripts\activate.bat - python -m pip install -r requirements.txt - python pyeamu.py + py -m pip install -r requirements.txt + py pyeamu.py +) else ( + .venv\Scripts\activate.bat + py pyeamu.py ) -echo: -echo Install python with "Add python.exe to PATH" checked +goto :EOF + +:install echo https://www.python.org/downloads/ +echo Install Python with "Add python.exe to PATH" checked echo: -echo Note: Choose the previous version if latest is 3.xx.0 +echo Install the previous version if latest is 3.xx.0 +echo - libraries may be broken on 3.xx.0 +echo - don't install pre-release version echo: pause - -goto :eof - -REM breaks when special characters are in path -:make_venv_portable -set pyvenv="%~dp0.venv\pyvenv.cfg" -set pyvenvtemp="%~dp0.venv\pyvenv.tmp" -for /f "tokens=*" %%i in ('python -V') do set pyver=%%i -for /f %%i in ('where python') do set pypath=%%i -set v=home version executable command -for %%a in (%v%) do for /f "tokens=*" %%i in ('findstr /b %%a %pyvenv%') do set %%a=%%i -if exist %pyvenvtemp% del %pyvenvtemp% -setlocal enabledelayedexpansion -( - for /f "tokens=1* delims=:" %%a in ('findstr /n "^" %pyvenv%') do ( - set "line=%%b" - if "!line!"=="%home%" (set line=home = %pypath:~0,-11%) - if "!line!"=="%version%" (set line=version = %pyver:~7%) - if "!line!"=="%executable%" (set line=executable = %pypath%) - if "!line!"=="%command%" (set line=command = %pypath% -m venv %~dp0.venv) - echo(!line! - ) -) > %pyvenvtemp% -endlocal -del %pyvenv% -rename %pyvenvtemp% pyvenv.cfg - -set activate="%~dp0.venv\Scripts\activate.bat" -set activatetemp="%~dp0.venv\Scripts\activate.tmp" -for /f "tokens=*" %%i in ('findstr "VIRTUAL_ENV=" %activate%') do set virtual=%%i -if exist %activatetemp% del %activatetemp% -setlocal enabledelayedexpansion -( - for /f "tokens=1* delims=:" %%a in ('findstr /n "^" %activate%') do ( - set "line=%%b" - if "!line!"=="%virtual%" (set line=set VIRTUAL_ENV=%~dp0.venv) - if "!line!"=="END" (set line=:END) - echo(!line! - ) -) > %activatetemp% -endlocal -del %activate% -rename "%activatetemp%" activate.bat