Created
November 23, 2023 13:00
-
-
Save 270ajay/492188387094689a5f5d7c25faa580ec to your computer and use it in GitHub Desktop.
Batch file to format python files
This file contains hidden or 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 | |
:: 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