2022-09-02 09:49:35 +03:00
|
|
|
@echo off
|
|
|
|
|
2022-09-09 08:37:19 +03:00
|
|
|
if not defined PYTHON (set PYTHON=python)
|
|
|
|
if not defined VENV_DIR (set VENV_DIR=venv)
|
2022-09-08 12:18:50 +03:00
|
|
|
|
2022-09-02 09:49:35 +03:00
|
|
|
mkdir tmp 2>NUL
|
|
|
|
|
|
|
|
%PYTHON% -c "" >tmp/stdout.txt 2>tmp/stderr.txt
|
2022-09-13 16:48:18 +03:00
|
|
|
if %ERRORLEVEL% == 0 goto :start_venv
|
2022-09-02 09:49:35 +03:00
|
|
|
echo Couldn't launch python
|
|
|
|
goto :show_stdout_stderr
|
|
|
|
|
2022-09-13 16:48:18 +03:00
|
|
|
:start_venv
|
2022-09-09 08:37:19 +03:00
|
|
|
if [%VENV_DIR%] == [-] goto :skip_venv
|
2022-09-02 19:26:18 +03:00
|
|
|
|
|
|
|
dir %VENV_DIR%\Scripts\Python.exe >tmp/stdout.txt 2>tmp/stderr.txt
|
|
|
|
if %ERRORLEVEL% == 0 goto :activate_venv
|
|
|
|
|
2022-09-03 01:55:56 +03:00
|
|
|
for /f "delims=" %%i in ('CALL %PYTHON% -c "import sys; print(sys.executable)"') do set PYTHON_FULLNAME="%%i"
|
2022-09-02 19:26:18 +03:00
|
|
|
echo Creating venv in directory %VENV_DIR% using python %PYTHON_FULLNAME%
|
|
|
|
%PYTHON_FULLNAME% -m venv %VENV_DIR% >tmp/stdout.txt 2>tmp/stderr.txt
|
|
|
|
if %ERRORLEVEL% == 0 goto :activate_venv
|
|
|
|
echo Unable to create venv in directory %VENV_DIR%
|
|
|
|
goto :show_stdout_stderr
|
|
|
|
|
|
|
|
:activate_venv
|
2022-09-08 01:31:25 +03:00
|
|
|
set PYTHON="%~dp0%VENV_DIR%\Scripts\Python.exe"
|
2022-09-02 19:26:18 +03:00
|
|
|
echo venv %PYTHON%
|
2022-09-13 16:48:18 +03:00
|
|
|
goto :launch
|
2022-09-02 19:26:18 +03:00
|
|
|
|
|
|
|
:skip_venv
|
2022-09-07 12:32:28 +03:00
|
|
|
|
2022-09-02 09:49:35 +03:00
|
|
|
:launch
|
2022-09-13 16:48:18 +03:00
|
|
|
%PYTHON% launch.py
|
2022-09-02 09:49:35 +03:00
|
|
|
pause
|
|
|
|
exit /b
|
|
|
|
|
|
|
|
:show_stdout_stderr
|
|
|
|
|
|
|
|
echo.
|
|
|
|
echo exit code: %errorlevel%
|
|
|
|
|
|
|
|
for /f %%i in ("tmp\stdout.txt") do set size=%%~zi
|
|
|
|
if %size% equ 0 goto :show_stderr
|
|
|
|
echo.
|
|
|
|
echo stdout:
|
|
|
|
type tmp\stdout.txt
|
|
|
|
|
|
|
|
:show_stderr
|
|
|
|
for /f %%i in ("tmp\stderr.txt") do set size=%%~zi
|
|
|
|
if %size% equ 0 goto :show_stderr
|
|
|
|
echo.
|
|
|
|
echo stderr:
|
|
|
|
type tmp\stderr.txt
|
|
|
|
|
|
|
|
:endofscript
|
|
|
|
|
|
|
|
echo.
|
|
|
|
echo Launch unsuccessful. Exiting.
|
2022-09-02 19:26:18 +03:00
|
|
|
pause
|