-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.direnvrc
More file actions
67 lines (53 loc) · 1.38 KB
/
.direnvrc
File metadata and controls
67 lines (53 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use_nvm_from_nvm_rc() {
if [[ ! -f .nvmrc ]]; then
log_error 'No .nvmrc found'
exit 2
fi
local version=$(cat .nvmrc)
use_nvm "$version"
}
use_nvm() {
local node_version=$1
nvm_sh=$(brew --prefix)/opt/nvm/nvm.sh
which nvm || source $nvm_sh
# if [[ -e $nvm_sh ]]; then
# source $nvm_sh
nvm use $node_version
# fi
}
layout_uv() {
local python_version=${1:-}
local venv_dir=".venv"
local python_bin="$venv_dir/bin/python"
# already activated?
if [[ "${VIRTUAL_ENV:-""}" == "$PWD/$venv_dir" && -x "$python_bin" ]]; then
return 0
fi
export VIRTUAL_ENV="$PWD/$venv_dir"
if [[ -x "$python_bin" ]]; then
layout python "$python_bin"
return 0
fi
if [[ ! -f pyproject.toml && \
! -f .python-version && \
-z "$python_version" ]]; then
return 0
fi
echo "direnv: creating virtualenv via uv in $venv_dir"
mkdir -p "$venv_dir"
echo $1
local python_version_arg=""
if [[ -n "${python_version}" ]]; then
local python_version_arg="--python $python_version"
fi
# NOTE: uv can natively read the required python version from
# `.python-version` or `pyproject.toml`.
# it also supports version ranges.
uv venv --clear "$venv_dir" $python_version_arg
if [[ -x "$python_bin" ]]; then
layout python "$python_bin"
fi
export UV_ACTIVE=1
export UV_PROJECT_ENVIRONMENT=$VIRTUAL_ENV
}
# vim: et ts=2 sts=2 sw=2