Last active
August 28, 2021 13:59
-
-
Save sayef/6f807bcece8f0b76f1b793096c111741 to your computer and use it in GitHub Desktop.
Clean Python Code with autoflake, autopep8 and isort
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
# add this file in .vscode folder as compile.sh | |
# edit ~/.local/bin/ if it's different in your machine | |
FILE=$(wslpath $1) | |
EXT=$(rev <<< "$FILE" | cut -d"." -f1 | rev) | |
if [ "$EXT" == "py" ]; then | |
echo "Running autopep8 and autoflake on $FILE $EXT" | |
~/.local/bin/autopep8 -i -a -a $FILE | |
~/.local/bin/autoflake -i --remove-all-unused-imports --remove-unused-variables $FILE | |
~/.local/bin/isort $FILE | |
fi |
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
# add this keybinding in keybindings.json | |
[ | |
{ | |
"key": "alt+s", | |
"command": "workbench.action.tasks.runTask" | |
} | |
] |
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
# add this file in .vscode folder as tasks.json | |
{ | |
"version": "2.0.0", | |
"tasks": [ | |
{ | |
"label": "Clean Code", | |
"type": "shell", | |
"command": "bash .vscode/compile.sh ${file}", | |
"isBackground": false, | |
"presentation": { | |
"reveal": "never", | |
"echo": false, | |
"clear": true | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment