Last active
October 27, 2021 10:59
-
-
Save thomasjo/e5bdad47b9c9bd61259ba77b025624ba to your computer and use it in GitHub Desktop.
VS Code + Python + Poetry + direnv + ...
This file contains hidden or 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
# Save this file in the project root. | |
dotenv_if_exists | |
layout poetry |
This file contains hidden or 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
# 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" | |
} |
This file contains hidden or 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
Show hidden characters
// 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