Skip to content

Commit

Permalink
feat: add direnv configuration for virtual environment management
Browse files Browse the repository at this point in the history
Add a new `.config/direnv/direnvrc` file with functions `layout_uv_venv` and `layout_uv`
to automate virtual environment setup using `uv`. Include the `~/.config/direnv` directory
in `install.conf.yaml` to ensure the configuration is linked during setup. These changes
simplify virtual environment management and improve developer workflow by automating
environment activation and setup.

Signed-off-by: Marcelo Borges <me@marceloborges.dev>
  • Loading branch information
jmarcelomb committed Feb 11, 2025
1 parent 24ef9a8 commit 3547d39
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .config/direnv/direnvrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
layout_uv_venv() {
if [[ -d ".venv" ]]; then
VIRTUAL_ENV="$(pwd)/.venv"
fi

if [[ -z $VIRTUAL_ENV || ! -d $VIRTUAL_ENV ]]; then
log_status "No virtual environment exists. Executing \`uv venv\` to create one."
uv venv
VIRTUAL_ENV="$(pwd)/.venv"
fi

PATH_add "$VIRTUAL_ENV/bin"
export UV_ACTIVE=1 # or VENV_ACTIVE=1
export VIRTUAL_ENV
}

layout_uv() {
if [[ -d ".venv" ]]; then
VIRTUAL_ENV="$(pwd)/.venv"
fi

if [[ -z $VIRTUAL_ENV || ! -d $VIRTUAL_ENV ]]; then
log_status "No uv project exists. Executing \`uv init\` to create one."
uv init --no-readme
rm hello.py
uv venv
VIRTUAL_ENV="$(pwd)/.venv"
fi

PATH_add "$VIRTUAL_ENV/bin"
export UV_ACTIVE=1 # or VENV_ACTIVE=1
export VIRTUAL_ENV
}
1 change: 1 addition & 0 deletions install.conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
~/.config/alacritty: .config/alacritty
~/.config/zellij/: .config/zellij
~/.config/yazi/: .config/yazi
~/.config/direnv: .config/direnv
~/.config/git/: .config/git/
~/.config/starship.toml: .config/starship.toml
~/.config/i3: .config/i3/
Expand Down

0 comments on commit 3547d39

Please sign in to comment.