Repository navigation
Expand file tree
/
Copy pathpython-embeded.bat
More file actions
79 lines (68 loc) · 2.06 KB
/
Copy pathpython-embeded.bat
File metadata and controls
79 lines (68 loc) · 2.06 KB
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
@echo off
title Python Embedded
set inst_dir=%CD%
cd /d "%inst_dir%"
if not defined PYTHON (set PYTHON=python)
if not defined PY_EMBEDDED (set "PY_EMBEDDED=%inst_dir%\python-embedded")
set ERROR_REPORTING=FALSE
mkdir tmp 2>NUL
if not exist "%PY_EMBEDDED%\python.exe" (
curl -o python-3.10.0-embed-amd64.zip https://www.python.org/ftp/python/3.10.0/python-3.10.0-embed-amd64.zip
mkdir python-embedded
powershell -command "Expand-Archive -Path %inst_dir%\python-3.10.0-embed-amd64.zip -DestinationPath %inst_dir%\python-embedded"
del python-3.10.0-embed-amd64.zip
)
set PYTHON="%PY_EMBEDDED%\python.exe"
echo venv %PYTHON%
goto:check_pip
:check_pip
if exist "%PY_EMBEDDED%\scripts\pip.exe" (
echo pip set
set PIP="%PY_EMBEDDED%\scripts\pip.exe"
goto :launch
)
goto:pip_install
:pip_install
echo install pip
if not exist "%PY_EMBEDDED%\get-pip.py" (
curl -sSL https://bootstrap.pypa.io/get-pip.py -o "%PY_EMBEDDED%\get-pip.py"
rem Edit python310._pth to uncomment import site
powershell -command "(Get-Content %PY_EMBEDDED%\python310._pth) -replace '#import site', 'import site' | Set-Content %PY_EMBEDDED%\python310._pth"
)
%PYTHON% "%PY_EMBEDDED%\get-pip.py"
if %ERRORLEVEL% == 0 goto:check_pip
echo Couldn't install pip
goto :show_stdout_stderr
:install_requirements
echo Installing requirements
%PIP% install -r requirements.txt >tmp\stdout.txt 2>tmp\stderr.txt
del /F "%PY_EMBEDDED%\get-pip.py"
if %ERRORLEVEL% == 1 (
echo Couldn't install requirements
goto :show_stdout_stderr
)
:launch
if exist "%PY_EMBEDDED%\get-pip.py" (
goto :install_requirements
)
%PYTHON% main.py %*
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 :endofscript
echo.
echo stderr:
type tmp\stderr.txt
:endofscript
echo.
echo Launch unsuccessful. Exiting.
pause