Prefer venv module over virtualenv

if it's installed as part of the Python standard library.
This commit is contained in:
Nicola Soranzo
2022-06-17 00:33:14 +01:00
parent 7887f5dc5e
commit 2e2403e1e2
+28 -21
View File
@@ -116,12 +116,12 @@ if [ $SET_VENV -eq 1 ] && [ $CREATE_VENV -eq 1 ]; then
echo "Creating Conda environment for Galaxy: $GALAXY_CONDA_ENV"
echo "To avoid this, use the --no-create-venv flag or set \$GALAXY_CONDA_ENV to an"
echo "existing environment before starting Galaxy."
$CONDA_EXE create --yes --override-channels --channel conda-forge --channel defaults --name "$GALAXY_CONDA_ENV" 'python=3.7' 'pip>=19.3' 'virtualenv>=16'
$CONDA_EXE create --yes --override-channels --channel conda-forge --channel defaults --name "$GALAXY_CONDA_ENV" 'python=3.7' 'pip>=19.3'
unset __CONDA_INFO
fi
conda_activate
fi
virtualenv "$GALAXY_VIRTUAL_ENV"
python3 -m venv "$GALAXY_VIRTUAL_ENV"
else
# If $GALAXY_VIRTUAL_ENV does not exist, and there is no conda available, attempt to create it.
if [ -z "$GALAXY_PYTHON" ]; then
@@ -137,27 +137,34 @@ if [ $SET_VENV -eq 1 ] && [ $CREATE_VENV -eq 1 ]; then
echo "using Python: $GALAXY_PYTHON"
echo "To avoid this, use the --no-create-venv flag or set \$GALAXY_VIRTUAL_ENV to an"
echo "existing environment before starting Galaxy."
if command -v virtualenv >/dev/null; then
virtualenv -p "$GALAXY_PYTHON" "$GALAXY_VIRTUAL_ENV"
else
min_python_version=3.7
vurl="https://bootstrap.pypa.io/virtualenv/${min_python_version}/virtualenv.pyz"
vtmp=$(mktemp -d -t galaxy-virtualenv-XXXXXX)
vsrc="$vtmp/$(basename $vurl)"
echo "Fetching $vurl"
if command -v curl >/dev/null; then
curl -L -o "$vsrc" "$vurl"
elif command -v wget >/dev/null; then
wget -O "$vsrc" "$vurl"
# First try to use the venv standard library module, although it is
# not always installed by default on Linux distributions.
if ! "$GALAXY_PYTHON" -m venv "$GALAXY_VIRTUAL_ENV"; then
echo "Creating the Python virtual environment using the venv standard library module failed."
echo "Trying with virtualenv now."
if command -v virtualenv >/dev/null; then
virtualenv -p "$GALAXY_PYTHON" "$GALAXY_VIRTUAL_ENV"
else
"$GALAXY_PYTHON" -c "try:
from urllib import urlretrieve
except:
from urllib.request import urlretrieve
urlretrieve('$vurl', '$vsrc')"
# Download virtualenv zipapp
min_python_version=3.7
vurl="https://bootstrap.pypa.io/virtualenv/${min_python_version}/virtualenv.pyz"
vtmp=$(mktemp -d -t galaxy-virtualenv-XXXXXX)
vsrc="$vtmp/$(basename $vurl)"
echo "Fetching $vurl"
if command -v curl >/dev/null; then
curl -L -o "$vsrc" "$vurl"
elif command -v wget >/dev/null; then
wget -O "$vsrc" "$vurl"
else
"$GALAXY_PYTHON" -c "try:
from urllib import urlretrieve
except:
from urllib.request import urlretrieve
urlretrieve('$vurl', '$vsrc')"
fi
"$GALAXY_PYTHON" "$vsrc" "$GALAXY_VIRTUAL_ENV"
rm -rf "$vtmp"
fi
"$GALAXY_PYTHON" "$vsrc" "$GALAXY_VIRTUAL_ENV"
rm -rf "$vtmp"
fi
fi
fi