Skip to content

Instantly share code, notes, and snippets.

@sayef
Last active August 28, 2021 13:59
Show Gist options
  • Save sayef/6f807bcece8f0b76f1b793096c111741 to your computer and use it in GitHub Desktop.
Save sayef/6f807bcece8f0b76f1b793096c111741 to your computer and use it in GitHub Desktop.
Clean Python Code with autoflake, autopep8 and isort
# 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
# add this keybinding in keybindings.json
[
{
"key": "alt+s",
"command": "workbench.action.tasks.runTask"
}
]
# 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