| 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 |
powershell -Command "(Get-Content 'pyproject.toml' | Select-String '^name = ') -replace '^name = \"', '' -replace '\"$', ''" > _tmp_.txt |
| 22 |
set /p %1=<_tmp_.txt |
| 23 |
del _tmp_.txt |
| 24 |
popd |
| 25 |
goto:eof |
| 26 |
|
| 27 |
:GetModName |
| 28 |
pushd %~dp0.. |
| 29 |
for /D %%I in (*) DO ( |
| 30 |
if exist %%I\__init__.py ( |
| 31 |
set %1=%%I |
| 32 |
goto :found_module |
| 33 |
) |
| 34 |
) |
| 35 |
:found_module |
| 36 |
popd |
| 37 |
goto:eof |
| 38 |
|
| 39 |
:GetVersion |
| 40 |
call:GetModName MODNAME |
| 41 |
call:SetPythonPath |
| 42 |
echo import %MODNAME%;print(%MODNAME%.__version__) | python > _tmp_.txt |
| 43 |
set /p %1=<_tmp_.txt |
| 44 |
del _tmp_.txt |
| 45 |
goto:eof |
| 46 |
|
| 47 |
:GetVersionWithoutAlphaBeta |
| 48 |
call:GetModName MODNAME |
| 49 |
call:SetPythonPath |
| 50 |
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 |
| 51 |
set /p %1=<_tmp_.txt |
| 52 |
del _tmp_.txt |
| 53 |
goto:eof |
| 54 |
|
| 55 |
:GetDLProjectPath |
| 56 |
call:SetPythonPath |
| 57 |
python -c "import datalab, os;print(os.path.abspath(os.path.join(datalab.__path__[0], os.pardir)))" > _tmp_.txt |
| 58 |
set /p %1=<_tmp_.txt |
| 59 |
del _tmp_.txt |
| 60 |
goto:eof |
| 61 |
|
| 62 |
:SetPythonPath |
| 63 |
set ORIGINAL_PYTHONPATH=%PYTHONPATH% |
| 64 |
cd %~dp0.. |
| 65 |
if not defined RELEASE (set RELEASE=0) |
| 66 |
if %RELEASE%==1 ( |
| 67 |
set PYTHONPATH=%CD% |
| 68 |
) else ( |
| 69 |
for /F "tokens=*" %%A in (.env) do ( |
| 70 |
set %%A |
| 71 |
) |
| 72 |
) |
| 73 |
set PYTHONPATH=%PYTHONPATH%;%ORIGINAL_PYTHONPATH% |
| 74 |
goto:eof |
| 75 |
|
| 76 |
:UsePython |
| 77 |
if defined WINPYVER (goto:eof) |
| 78 |
if not defined PYTHON (goto :nopython) |
| 79 |
for %%a in ("%PYTHON%") do set "p_dir=%%~dpa" |
| 80 |
if exist "%p_dir%\activate.bat" (goto :venvpython) |
| 81 |
for %%a in (%p_dir:~0,-1%) do set "WINPYDIRBASE=%%~dpa" |
| 82 |
if exist "%WINPYDIRBASE%\scripts\env.bat" (goto :nopython) |
| 83 |
goto :python |
| 84 |
:venvpython |
| 85 |
call "%p_dir%\activate.bat" |
| 86 |
call :ShowTitle "Using Python Virtual Environment from %p_dir%" |
| 87 |
goto:eof |
| 88 |
:python |
| 89 |
set PATH=%p_dir%;%PATH% |
| 90 |
call :ShowTitle "Using Python from %p_dir%" |
| 91 |
goto:eof |
| 92 |
:nopython |
| 93 |
if defined WINPYDIRBASE ( |
| 94 |
call %WINPYDIRBASE%\scripts\env.bat |
| 95 |
call :ShowTitle "Using WinPython from %WINPYDIRBASE%" |
| 96 |
) else ( |
| 97 |
echo Warning: WINPYDIRBASE environment variable is not defined, switching to system Python |
| 98 |
echo ******** |
| 99 |
echo (if nothing happens, that's probably because Python is not installed either: |
| 100 |
echo please set the WINPYDIRBASE variable to select WinPython directory, or install Python) |
| 101 |
) |
| 102 |
goto:eof |
| 103 |
|
| 104 |
:ShowTitle |
| 105 |
@echo: |
| 106 |
@echo ========= %~1 ========= |
| 107 |
@echo: |
| 108 |
goto:eof |
| 109 |
|
| 110 |
:EndOfScript |
| 111 |
@echo: |
| 112 |
@echo ********************************************************************************** |
| 113 |
@echo: |
| 114 |
if not defined UNATTENDED ( |
| 115 |
@echo End of script |
| 116 |
pause |
| 117 |
) |
| 118 |
goto:eof |
| 119 |
|
| 120 |
:Exit |
| 121 |
exit /b |