Created
September 20, 2021 20:24
-
-
Save echiesse/020445a68198e4a78b86209f3dc4132e to your computer and use it in GitHub Desktop.
Script para ativar python virtualenvs no windows. Tenta recursivamente até a raiz.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set venvdir=%1 | |
for /f "delims==" %%d in ('cd') do set currentDir=%%d | |
call :reset-el | |
if not "%venvdir%" == "" ( | |
call %venvdir%\Scripts\activate | |
) else ( | |
call :attempt | |
) | |
goto :eof | |
:attempt | |
:loop | |
call :try-activate . | |
for /f "delims==" %%d in ('cd') do set envdir=%%d | |
if "%envdir%" == "C:\" goto :finishNotFound | |
if %errorlevel% equ 0 goto :finish | |
cd .. | |
goto :loop | |
goto :eof | |
:try-activate | |
call :reset-el | |
if exist %1\venv ( | |
call %1\venv\Scripts\activate | |
exit /b 0 | |
) else if exist %1\Scripts\activate ( | |
call %1\Scripts\activate | |
exit /b 0 | |
) | |
exit /b 1 | |
:reset-el | |
exit /b 0 | |
:finishNotFound | |
cd %currentDir% | |
echo activate: virtual env not found | |
exit /b | |
:finish | |
cd %currentDir% | |
echo activate: virtual env found in %envdir% | |
exit /b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment