Skip to content

Instantly share code, notes, and snippets.

@thomasjo
Last active October 27, 2021 10:59
Show Gist options
  • Save thomasjo/e5bdad47b9c9bd61259ba77b025624ba to your computer and use it in GitHub Desktop.
Save thomasjo/e5bdad47b9c9bd61259ba77b025624ba to your computer and use it in GitHub Desktop.
VS Code + Python + Poetry + direnv + ...
# Save this file in the project root.
dotenv_if_exists
layout poetry
# Save this file as $HOME/.config/direnv/lib/poetry.sh
layout_poetry() {
if [[ ! -f pyproject.toml ]]; then
log_error 'No pyproject.toml found. Use `poetry new` or `poetry init` to create one first.'
exit 2
fi
local VENV=$(poetry env list --full-path | cut -d' ' -f1)
if [[ -z $VENV || ! -d $VENV/bin ]]; then
log_error 'No poetry virtual environment found. Use `poetry install` to create one first.'
exit 2
fi
export VIRTUAL_ENV=$VENV
export POETRY_ACTIVE=1
PATH_add "$VENV/bin"
}
// Save this file in the project's .vscode directory as settings.json.
{
"python.pythonPath": ".venv/bin/python",
// Format on save using Black.
"python.formatting.provider": "black",
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
},
// Exclude files and folders from explorer.
"files.exclude": {
"**/.ipynb_checkpoints": true,
"**/.venv": true,
},
// Exclude files and folders from watcher.
"files.watcherExclude": {
"**/.venv/**": true,
},
// Exclude files and folders from search.
"search.exclude": {
"**/.venv": true,
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment