@@ -7,22 +7,10 @@ venv_name=$(grep -m 1 venv pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" |
7
7
# Check if pyrightconfig already exists.
8
8
if [[ ! -f pyrightconfig.json ]]; then
9
9
10
- if [[ -z ${venv_name} ]]; then
11
- echo " Using Poetry"
12
- poetry_env_info=$( poetry env info --path) > /dev/null 2>&1
13
- venv_path=${poetry_env_info%/* } # ABCDE
14
- venv_name=${poetry_env_info#*/ } # 12345
15
-
16
- # Generate the pyrightconfig.json file.
17
- json_string=$( jq -n \
18
- --arg v " ${venv_name} " \
19
- --arg vp " ${venv_path} " \
20
- ' {venv: $v, venvPath: $vp} ' )
21
-
22
- echo " ${json_string} " > pyrightconfig.json
23
- else
24
- echo " Using Pyenv"
25
- # Check if pyenv-pyright plugin is installed
10
+ # Capture poetry environment path and check if it's empty.
11
+ poetry_env_info=$( poetry env info --path 2> /dev/null || true)
12
+ if [[ -z ${poetry_env_info} ]]; then
13
+ # Check if pyenv is installed
26
14
if ! command -v pyenv & > /dev/null; then
27
15
echo " pyenv not installed. Please install pyenv..."
28
16
exit 1
@@ -32,14 +20,26 @@ if [[ ! -f pyrightconfig.json ]]; then
32
20
dir_path=" ${pyenv_root} " /plugins/pyenv-pyright
33
21
if [[ ! -d ${dir_path} ]]; then
34
22
# trunk-ignore(shellcheck/SC2312)
35
- if [[ -n $( ls -A " ${dir_path} " ) ]]; then
23
+ if [[ -z $( ls -A " ${dir_path} " ) ]]; then
36
24
git clone https://github.com/alefpereira/pyenv-pyright.git " ${dir_path} "
37
25
fi
38
26
fi
39
27
40
28
# Generate the pyrightconfig.json file.
41
29
pyenv pyright " ${venv_name} "
42
30
pyenv local " ${venv_name} "
31
+ else
32
+ poetry_env_info=$( poetry env info --path 2> /dev/null || true)
33
+ venv_path=$( dirname " ${poetry_env_info} " ) # Get directory path
34
+ venv_name=$( basename " ${poetry_env_info} " ) # Get base name
35
+
36
+ # Generate the pyrightconfig.json file.
37
+ json_string=$( jq -n \
38
+ --arg v " ${venv_name} " \
39
+ --arg vp " ${venv_path} " \
40
+ ' {venv: $v, venvPath: $vp} ' )
41
+
42
+ echo " ${json_string} " > pyrightconfig.json
43
43
fi
44
44
fi
45
45
@@ -48,5 +48,4 @@ if ! jq -r --arg venv_name "${venv_name}" '. | select((.venv != $venv_name or .v
48
48
echo " Failed to configure pyright to use environment '${venv_name} ' as interpreter. Please check pyrightconfig.json..."
49
49
exit 1
50
50
fi
51
- echo " All done!"
52
51
exit 0
0 commit comments