Skip to content

Commit

Permalink
[Issue-14] fix venv incorrect file search
Browse files Browse the repository at this point in the history
  • Loading branch information
VoIlAlex committed Feb 20, 2024
1 parent f691583 commit 33a24f0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 16 deletions.
37 changes: 29 additions & 8 deletions scripts/requirements-txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,44 @@ fi

# Activating virtual environment function

contains() {
[[ $list =~ (^| )$x($| ) ]] && echo '0' || echo '1'
search_in_path() {
local search_string=$1

# Flag to indicate if the string was found
local found=0
# Loop through the array and search for the string
for item in $(ls $2); do
if [ "$item" = "$search_string" ]; then
found=1
break
fi
done

# Check if the string was found
if [ $found -eq 1 ]; then
echo "0"
else
echo "1"
fi
}

activate_virtual_env() {
for file in $(ls)
do
if [[ -d "./$file" ]]
then
files_in_folder=$(ls "./$file")
pyvenv_exists=$(contains files_in_folder "pyvenv.cfg")
bin_exists=$(contains files_in_folder "bin")

if [ "$pyvenv_exists" = "0" ] && [ "$bin_exists" = "0" ]
pyvenv_exists=$(search_in_path "pyvenv.cfg" "./$file")
bin_exists=$(search_in_path "bin" "./$file" )
lib_exists=$(search_in_path "lib" "./$file" )
if [ "$pyvenv_exists" = "0" ] && [ "$bin_exists" = "0" ] && [ "$lib_exists" = "0" ]
then
activate_exists=$(search_in_path "activate" "./$file/bin")

if [ "$activate_exists" = "0" ]
then
source "./$file/bin/activate"
break 2
break 3
fi
fi
fi
done
Expand Down
37 changes: 29 additions & 8 deletions scripts/rt
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,44 @@ fi

# Activating virtual environment function

contains() {
[[ $list =~ (^| )$x($| ) ]] && echo '0' || echo '1'
search_in_path() {
local search_string=$1

# Flag to indicate if the string was found
local found=0
# Loop through the array and search for the string
for item in $(ls $2); do
if [ "$item" = "$search_string" ]; then
found=1
break
fi
done

# Check if the string was found
if [ $found -eq 1 ]; then
echo "0"
else
echo "1"
fi
}

activate_virtual_env() {
for file in $(ls)
do
if [[ -d "./$file" ]]
then
files_in_folder=$(ls "./$file")
pyvenv_exists=$(contains files_in_folder "pyvenv.cfg")
bin_exists=$(contains files_in_folder "bin")

if [ "$pyvenv_exists" = "0" ] && [ "$bin_exists" = "0" ]
pyvenv_exists=$(search_in_path "pyvenv.cfg" "./$file")
bin_exists=$(search_in_path "bin" "./$file" )
lib_exists=$(search_in_path "lib" "./$file" )
if [ "$pyvenv_exists" = "0" ] && [ "$bin_exists" = "0" ] && [ "$lib_exists" = "0" ]
then
activate_exists=$(search_in_path "activate" "./$file/bin")

if [ "$activate_exists" = "0" ]
then
source "./$file/bin/activate"
break 2
break 3
fi
fi
fi
done
Expand Down

0 comments on commit 33a24f0

Please sign in to comment.