Skip to content

Commit 9411c3d

Browse files
committed
Improve Script
1 parent 359ce58 commit 9411c3d

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

plugins/pip/venvShellHook.sh

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
STATE_FILE="$DEVBOX_PROJECT_ROOT/.devbox/venv_check_completed"
2+
echo $STATE_FILE
23

34
is_valid_venv() {
45
[ -f "$1/bin/activate" ] && [ -f "$1/bin/python" ]
@@ -10,10 +11,31 @@ is_devbox_python() {
1011
echo "DEVBOX_PACKAGES_DIR is not set. Unable to check for Devbox Python."
1112
return 1
1213
fi
13-
local python_path=$(readlink "$1/bin/python")
14-
echo $python_path
15-
echo $DEVBOX_PACKAGES_DIR
16-
[[ $python_path == $DEVBOX_PACKAGES_DIR/bin/python* ]]
14+
local python_path="$1/bin/python"
15+
local link_target
16+
17+
while true; do
18+
if [ ! -L "$python_path" ]; then
19+
echo $python_path
20+
# Not a symlink, we're done
21+
break
22+
fi
23+
24+
link_target=$(readlink "$python_path")
25+
echo "Checking symlink: $link_target"
26+
27+
if [[ "$link_target" == /* ]]; then
28+
# Absolute path, we're done
29+
python_path="$link_target"
30+
break
31+
elif [[ "$link_target" == python* ]] || [[ "$link_target" == ./* ]] || [[ "$link_target" == ../* ]]; then
32+
# Relative path or python symlink, continue resolving
33+
python_path=$(dirname "$python_path")/"$link_target"
34+
else
35+
# Unexpected format, stop here
36+
break
37+
fi
38+
done
1739
}
1840

1941
# Function to check Python version

0 commit comments

Comments
 (0)