-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adds global `.direnvrc` which defines `layout poetry` that initialized poetry environment in a directory with `pyproject.toml` - Adds utility script `poetry-here` that creates local `.envrc` and sets up direnv - Makes appropriate symlinks of these files into `$HOME`
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Define `layout poetry` for local `.envrc` | ||
# - https://github.com/direnv/direnv/wiki/Python#poetry | ||
# - https://medium.com/analytics-vidhya/best-practice-for-using-poetry-608ab6feaaf | ||
layout_poetry() { | ||
|
||
if [[ ! -f pyproject.toml ]]; then | ||
log_status 'No pyproject.toml found. Will initialize poetry in no-interactive mode' | ||
|
||
# Initialize poetry in no-interactive mode | ||
poetry init -n -q | ||
fi | ||
|
||
# Create venv if it doesn't exist | ||
poetry run true | ||
|
||
# Setup VIRTUAL_ENV and add it to PATH | ||
export VIRTUAL_ENV=$(poetry env info --path) | ||
export POETRY_ACTIVE=1 | ||
PATH_add "$VIRTUAL_ENV/bin" | ||
|
||
# Make symlink to `.venv` for easy IDE environment setup | ||
if [ ! -L .venv ]; then | ||
ln -ns $VIRTUAL_ENV .venv | ||
fi | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Allows to run `poetry-here` anywhere one wants to have poetry setup. | ||
# - Works even if new project with poetry has not yet been set up | ||
# - https://medium.com/analytics-vidhya/best-practice-for-using-poetry-608ab6feaaf | ||
|
||
echo "layout poetry" > .envrc | ||
|
||
direnv allow . | ||
direnv exec . true |
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