File: utils.bat

package info (click to toggle)
datalab 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 36,260 kB
  • sloc: python: 29,592; makefile: 3
file content (121 lines) | stat: -rw-r--r-- 3,391 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
@echo off
set FUNC=%0
call:%*
goto Exit

REM ======================================================
REM Utilities for deployment, test and build scripts
REM ======================================================
REM Licensed under the terms of the MIT License
REM Copyright (c) 2020 Pierre Raybaut
REM (see LICENSE file for more details)
REM ======================================================

:GetScriptPath
    set _tmp_=%~dp0
    if %_tmp_:~-1%==\ set %1=%_tmp_:~0,-1%
    EXIT /B 0

:GetLibName
    pushd %~dp0..
    powershell -Command "(Get-Content 'pyproject.toml' | Select-String '^name = ') -replace '^name = \"', '' -replace '\"$', ''" > _tmp_.txt
    set /p %1=<_tmp_.txt
    del _tmp_.txt
    popd
    goto:eof

:GetModName
    pushd %~dp0..
    for /D %%I in (*) DO (
        if exist %%I\__init__.py (
            set %1=%%I
            goto :found_module
        )
    )
    :found_module
    popd
    goto:eof

:GetVersion
    call:GetModName MODNAME
    call:SetPythonPath
    echo import %MODNAME%;print(%MODNAME%.__version__) | python > _tmp_.txt
    set /p %1=<_tmp_.txt
    del _tmp_.txt
    goto:eof

:GetVersionWithoutAlphaBeta
    call:GetModName MODNAME
    call:SetPythonPath
    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
    set /p %1=<_tmp_.txt
    del _tmp_.txt
    goto:eof

:GetDLProjectPath
call:SetPythonPath
python -c "import datalab, os;print(os.path.abspath(os.path.join(datalab.__path__[0], os.pardir)))" > _tmp_.txt
set /p %1=<_tmp_.txt
del _tmp_.txt
goto:eof

:SetPythonPath
    set ORIGINAL_PYTHONPATH=%PYTHONPATH%
    cd %~dp0..
    if not defined RELEASE (set RELEASE=0)
    if %RELEASE%==1 (
        set PYTHONPATH=%CD%
    ) else (
        for /F "tokens=*" %%A in (.env) do (
            set %%A
        )
    )
    set PYTHONPATH=%PYTHONPATH%;%ORIGINAL_PYTHONPATH%
    goto:eof

:UsePython
    if defined WINPYVER (goto:eof)
    if not defined PYTHON (goto :nopython)
    for %%a in ("%PYTHON%") do set "p_dir=%%~dpa"
    if exist "%p_dir%\activate.bat" (goto :venvpython)
    for %%a in (%p_dir:~0,-1%) do set "WINPYDIRBASE=%%~dpa"
    if exist "%WINPYDIRBASE%\scripts\env.bat" (goto :nopython)
    goto :python
    :venvpython
        call "%p_dir%\activate.bat"
        call :ShowTitle "Using Python Virtual Environment from %p_dir%"
        goto:eof
    :python
        set PATH=%p_dir%;%PATH%
        call :ShowTitle "Using Python from %p_dir%"
        goto:eof
    :nopython
        if defined WINPYDIRBASE (
            call %WINPYDIRBASE%\scripts\env.bat
            call :ShowTitle "Using WinPython from %WINPYDIRBASE%"
        ) else (
            echo Warning: WINPYDIRBASE environment variable is not defined, switching to system Python
            echo ********
            echo (if nothing happens, that's probably because Python is not installed either:
            echo please set the WINPYDIRBASE variable to select WinPython directory, or install Python)
            )
        goto:eof

:ShowTitle
    @echo:
    @echo ========= %~1 =========
    @echo:
    goto:eof

:EndOfScript
    @echo:
    @echo **********************************************************************************
    @echo:
    if not defined UNATTENDED (
        @echo End of script
        pause
        )
    goto:eof

:Exit
    exit /b