Skip to content

Commit

Permalink
Test: support external virtualenv for finding python3 binary
Browse files Browse the repository at this point in the history
  • Loading branch information
mbideau committed Nov 8, 2020
1 parent 371bbf6 commit 9161038
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion test/run_some_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,24 @@ IFS_BAK="$IFS"
test_dir="$(dirname "$(realpath "$0")")"
cases_dir="$test_dir"/cases
project_dir="$(dirname "$test_dir")"
python_bin="$project_dir"/bin/python3
vcardtools_py="$project_dir"/vcardtools.py

if [ "$VIRTUAL_ENV" != '' ]; then
if [ -x "$VIRTUAL_ENV"/bin/python3 ]; then
python_bin="$VIRTUAL_ENV"/bin/python3
else
echo "Error: failed to find the python3 binary path ('$VIRTUAL_ENV/bin/python3' doesn't exist)." >&2
exit 1
fi
else
if [ -x "$project_dir"/bin/python3 ]; then
python_bin="$project_dir"/bin/python3
else
echo "Error: failed to find the python3 binary path (no VIRTUAL_ENV var, nor '$project_dir/bin/python3' exists)." >&2
exit 1
fi
fi

if [ ! -f "$vcardtools_py" ]; then
echo "Error: failed to find vcardtools python script '$vcardtools_py'" >&2
exit 1
Expand Down

1 comment on commit 9161038

@dev-abir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lines 35 to 39 are redundant.

The second else-if (if [ -x "$project_dir"/bin/python3 ]; then) is not required, the first if checks whether the user uses a virtualenv or not. I can't think of a case where user will store the python binary inside the project directory if it's not a virtual environment.

Now we need to handle two cases:

  1. If the user doesn't use a virtual environment.
  2. The user uses a virtual environment, but not venv

Please sign in to comment.