Skip to content

Instantly share code, notes, and snippets.

@leoncvlt
Last active March 30, 2020 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoncvlt/10e67d9415e61eff0f5010ef6fec51d8 to your computer and use it in GitHub Desktop.
Save leoncvlt/10e67d9415e61eff0f5010ef6fec51d8 to your computer and use it in GitHub Desktop.
evenvo.bat | a batch file for easy python virtual environment operations
@echo off
echo [ evenvo ] easy virtual environment operations
IF "%~1" == "" GOTO Initialize
IF "%~1" == "init" GOTO Initialize
IF "%~1" == "freeze" GOTO Freeze
IF "%~1" == "build" GOTO Build
IF "%~1" == "gitignore" GOTO GitIgnore
:Usage
echo Usage:
echo evenvo.bat [command]
echo init creates or activates the virtual environment and installs requirements.txt if found
echo freeze freezes local pip requirements into requirements.txt
echo build [scriptname] builds the [scriptname] .py/.spec file to a single .exe file using pyinstaller, if installed
echo gitignore downloads a python and virtual environment-ready .gitignore file
GOTO End
:Initialize
IF EXIST %~dp0env (
echo Python environment found, activating...
GOTO Activate
) ELSE (
echo Python environment not found, creating and activating...
GOTO Create
)
:Create
py -m venv %~dp0env
GOTO Activate
:Activate
call %~dp0env\Scripts\activate.bat
GOTO Install
:Install
IF EXIST %~dp0requirements.txt (
pip install -r %~dp0requirements.txt
)
GOTO End
:Freeze
echo Freezing local pip requirements into requirements.txt...
pip freeze -l > %~dp0requirements.txt
GOTO End
:Build
IF "%~2" == "" GOTO Usage
pyinstaller -h >nul 2>&1 && (
if EXIST %2 (
echo Building %2 to /dist folder...
pyinstaller --onefile %2
) else (
echo %2 was not found
GOTO End
)
) || (
echo Build command was invoked, but pyinstaller was not found. Activate the virtual environment and call pip install pyinstaller
)
:GitIgnore
echo Downloading python .gitignore from gitignore.io...
powershell -Command "Invoke-WebRequest https://www.gitignore.io/api/python -OutFile .gitignore"
echo # Created by evenvo >> .gitignore
echo env/ >> .gitignore
:End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment