-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathactivate-venv.bat
More file actions
46 lines (41 loc) · 1.25 KB
/
activate-venv.bat
File metadata and controls
46 lines (41 loc) · 1.25 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
@echo off
REM Workspace root = pasta deste .bat
set "ROOT=%~dp0"
set "VENV=%ROOT%.venv"
set "ACT_CMD=%VENV%\Scripts\activate.bat"
set "ACT_PS=%VENV%\Scripts\Activate.ps1"
if not exist "%VENV%" (
echo ERRO: Nao encontrei "%VENV%".
exit /b 1
)
REM Detecta se este cmd foi iniciado como "cmd /c ..." (tipico quando vc executa .bat a partir do pwsh)
set "CMDLINE=%CMDCMDLINE%"
set "CMDLINE_NO_C=%CMDLINE:/c=%"
if /i not "%CMDLINE%"=="%CMDLINE_NO_C%" goto LaunchedByOther
REM Modo 1: voce ja esta em um CMD interativo -> ativa na propria janela
if exist "%ACT_CMD%" (
call "%ACT_CMD%"
goto :eof
) else (
echo ERRO: Nao encontrei "%ACT_CMD%".
exit /b 1
)
:LaunchedByOther
REM Modo 2: script foi disparado por outro host (ex.: pwsh). Abrimos um PowerShell com o venv ativo.
if exist "%ACT_PS%" (
where pwsh >nul 2>nul
if %errorlevel%==0 (
pwsh -NoLogo -NoProfile -ExecutionPolicy Bypass -NoExit -File "%ACT_PS%"
goto :eof
)
powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -NoExit -File "%ACT_PS%"
goto :eof
)
REM Fallback: sem Activate.ps1? Entao abrimos um CMD com o venv ativo.
if exist "%ACT_CMD%" (
start "" cmd /K "call ""%ACT_CMD%"""
goto :eof
) else (
echo ERRO: Nao encontrei nenhum ativador: "%ACT_PS%" nem "%ACT_CMD%".
exit /b 1
)