| 1 |
@echo off |
| 2 |
set FUNC=%0 |
| 3 |
call:%* |
| 4 |
goto Exit |
| 5 |
|
| 6 |
REM ====================================================== |
| 7 |
REM Utilities for deployment, test and build scripts |
| 8 |
REM ====================================================== |
| 9 |
REM Licensed under the terms of the MIT License |
| 10 |
REM Copyright (c) 2020 Pierre Raybaut |
| 11 |
REM (see LICENSE file for more details) |
| 12 |
REM ====================================================== |
| 13 |
|
| 14 |
:GetScriptPath |
| 15 |
set _tmp_=%~dp0 |
| 16 |
if %_tmp_:~-1%==\ set %1=%_tmp_:~0,-1% |
| 17 |
EXIT /B 0 |
| 18 |
|
| 19 |
:GetLibName |
| 20 |
pushd %~dp0.. |
| 21 |
for %%I in (.) do set %1=%%~nxI |
| 22 |
popd |
| 23 |
goto:eof |
| 24 |
|
| 25 |
:GetModName |
| 26 |
pushd %~dp0.. |
| 27 |
for /D %%I in (*) DO ( |
| 28 |
if exist %%I\__init__.py ( |
| 29 |
set %1=%%I |
| 30 |
goto :found_module |
| 31 |
) |
| 32 |
) |
| 33 |
:found_module |
| 34 |
popd |
| 35 |
goto:eof |
| 36 |
|
| 37 |
:GetVersion |
| 38 |
call:GetModName MODNAME |
| 39 |
call:SetPythonPath |
| 40 |
echo import %MODNAME%;print(%MODNAME%.__version__) | python > _tmp_.txt |
| 41 |
set /p %1=<_tmp_.txt |
| 42 |
del _tmp_.txt |
| 43 |
goto:eof |
| 44 |
|
| 45 |
:GetVersionWithoutAlphaBeta |
| 46 |
call:GetModName MODNAME |
| 47 |
call:SetPythonPath |
| 48 |
echo import %MODNAME%;ver=%MODNAME%.__version__;print(ver.split("b")[0] if "b" in ver else ver.split("a")[0] if "a" in ver else ver) | python > _tmp_.txt |
| 49 |
set /p %1=<_tmp_.txt |
| 50 |
del _tmp_.txt |
| 51 |
goto:eof |
| 52 |
|
| 53 |
:SetPythonPath |
| 54 |
set ORIGINAL_PYTHONPATH=%PYTHONPATH% |
| 55 |
cd %~dp0.. |
| 56 |
for /F "tokens=*" %%A in (.env) do ( |
| 57 |
set %%A |
| 58 |
) |
| 59 |
set PYTHONPATH=%PYTHONPATH%;%ORIGINAL_PYTHONPATH% |
| 60 |
goto:eof |
| 61 |
|
| 62 |
:UsePython |
| 63 |
if defined WINPYVER (goto:eof) |
| 64 |
if not defined PYTHON (goto :nopython) |
| 65 |
for %%a in ("%PYTHON%") do set "p_dir=%%~dpa" |
| 66 |
if exist "%p_dir%\activate.bat" (goto :venvpython) |
| 67 |
for %%a in (%p_dir:~0,-1%) do set "WINPYDIRBASE=%%~dpa" |
| 68 |
if exist "%WINPYDIRBASE%\scripts\env.bat" (goto :nopython) |
| 69 |
goto :python |
| 70 |
:venvpython |
| 71 |
call "%p_dir%\activate.bat" |
| 72 |
call :ShowTitle "Using Python Virtual Environment from %p_dir%" |
| 73 |
goto:eof |
| 74 |
:python |
| 75 |
set PATH=%p_dir%;%PATH% |
| 76 |
call :ShowTitle "Using Python from %p_dir%" |
| 77 |
goto:eof |
| 78 |
:nopython |
| 79 |
if defined WINPYDIRBASE ( |
| 80 |
call %WINPYDIRBASE%\scripts\env.bat |
| 81 |
call :ShowTitle "Using WinPython from %WINPYDIRBASE%" |
| 82 |
) else ( |
| 83 |
echo Warning: WINPYDIRBASE environment variable is not defined, switching to system Python |
| 84 |
echo ******** |
| 85 |
echo (if nothing happens, that's probably because Python is not installed either: |
| 86 |
echo please set the WINPYDIRBASE variable to select WinPython directory, or install Python) |
| 87 |
) |
| 88 |
goto:eof |
| 89 |
|
| 90 |
:ShowTitle |
| 91 |
@echo: |
| 92 |
@echo ========= %~1 ========= |
| 93 |
@echo: |
| 94 |
goto:eof |
| 95 |
|
| 96 |
:EndOfScript |
| 97 |
@echo: |
| 98 |
@echo ********************************************************************************** |
| 99 |
@echo: |
| 100 |
if not defined UNATTENDED ( |
| 101 |
@echo End of script |
| 102 |
pause |
| 103 |
) |
| 104 |
goto:eof |
| 105 |
|
| 106 |
:Exit |
| 107 |
exit /b |