Created
May 14, 2020 22:29
-
-
Save sam-writer/5591051b775f7bd58e8f0dd77248534f to your computer and use it in GitHub Desktop.
Make Poetry and VSCode play nicely
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
mkpoetryproj () | |
{ | |
if [ $# -eq 1 ]; then | |
poetry new "$1" | |
cd "$1" || exit | |
# get gitignore | |
curl https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore -o .gitignore | |
{ | |
echo "" | |
echo ".vscode/" | |
} >> .gitignore | |
mkdir -p .vscode | |
touch .vscode/settings.json | |
{ | |
echo "{" | |
echo " \"python.pythonPath\": \"$(poetry env info -p)/bin/python\"," | |
echo " \"terminal.integrated.shellArgs.linux\": [\"poetry shell\"]," | |
echo " \"files.exclude\": {" | |
echo " \"**/.git\": true," | |
echo " \"**/.DS_Store\": true," | |
echo " \"**/*.pyc\": true," | |
echo " \"**/__pycache__\": true," | |
echo " \"**/.mypy_cache\": true" | |
echo " }," | |
echo " \"python.linting.enabled\": true," | |
echo " \"python.linting.mypyEnabled\": true," | |
echo " \"python.formatting.provider\": \"black\"" | |
echo "}" | |
} >> .vscode/settings.json | |
poetry add -D black mypy | |
git init && git add . && git commit -m "ready to start" | |
# shellcheck source=/dev/null | |
source "$(poetry env info -p)/bin/activate" --prompt "poetry env" | |
code . | |
else | |
echo "usage: mkpoetryproj FOLDER_TO_MAKE" | |
echo "" | |
echo "This inits a new project folder with poetry" | |
echo "It adds the GitHub recommended .gitignore, connects VSCode to the poetry venv," | |
echo "and adds black and mypy, and makes sure VSCode knows about them" | |
echo "it then inits a git repo, adds everything and commits it, then opens VSCode" | |
fi | |
} |
This is awesome, thanks for sharing!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A small wrapper for
poetry new
that makes it play nicely with VSCode.I have this in my
.bash_profile
, so when I make a new poetry project, I canmkpoetryproj project_name
and it makes sure that the VS Code Python interpreter, and integrated terminal, are using Poetry's venv.