Skip to content

Instantly share code, notes, and snippets.

@270ajay
Created November 23, 2023 13:00
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 270ajay/492188387094689a5f5d7c25faa580ec to your computer and use it in GitHub Desktop.
Save 270ajay/492188387094689a5f5d7c25faa580ec to your computer and use it in GitHub Desktop.
Batch file to format python files
@ECHO OFF
:: This batch file helps in automating tasks on cmd.
:: First, we sort inports using isort package.
:: Then, we remove unused imports using autoflake package.
:: Finally, we format using black package.
TITLE Python Files Formatter
ECHO /!\ Please make sure you have the following packages installed:
ECHO -- isort (pip install isort)
ECHO -- autoflake (pip install autoflake)
ECHO -- black (pip install black)
:: Ask user for the path.
SET /p "directory=Please enter the path to the python project: "
ECHO.
:: Go to the directory.
cd %directory%
CALL:repeat
:: --------------------
:: Function definitions
:: --------------------
:repeat
CALL:format
ECHO.
ECHO *** Run Again? (if no, close this window) ***
PAUSE
GOTO:repeat
:format
ECHO.
ECHO =====================================
ECHO Running isort to sort imports...
CALL python -m isort .
ECHO.
ECHO =====================================
ECHO Running autoflake to remove unused imports...
CALL python -m autoflake -i -r .
ECHO.
ECHO =====================================
ECHO Running black to format python files...
CALL python -m black .
ECHO.
ECHO =====================================
ECHO.
ECHO Formatting done.
ECHO.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment