Skip to content

Instantly share code, notes, and snippets.

@sam-writer
Created May 14, 2020 22:29
Show Gist options
  • Save sam-writer/5591051b775f7bd58e8f0dd77248534f to your computer and use it in GitHub Desktop.
Save sam-writer/5591051b775f7bd58e8f0dd77248534f to your computer and use it in GitHub Desktop.
Make Poetry and VSCode play nicely
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
}
@public-daniel
Copy link

This is awesome, thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment