##// END OF EJS Templates
Use environment variable to identify conda / mamba (#14515)...
Use environment variable to identify conda / mamba (#14515) Conda and mamba both set an environment variable which refers to the base environment's executable path, use that in preference to less reliable methods, but fall back on the other approaches if unable to locate the executable this way. Additionally, change the search to look for the bare command name rather than the command within the top level of the active environment, I'm dubious this approach works with any current conda / mamba version which usually place their executable links in a `condabin` directory or elsewhere not at the same level as the Python executable. I believe this will also address https://github.com/ipython/ipython/issues/14350, which I'm also seeing in a Windows context where the regex fails to parse and causes a traceback.

File last commit:

r1752:af0aa7a3
r28871:d23bee0c merge
Show More
pkginstall
119 lines | 3.2 KiB | text/plain | TextLexer
#!/bin/bash
#
# Simple installation shell script for Python packages.
#
# Usage:
# pkginstall PAKPREFIX [PYPACKAGE]
#
# PAKPREFIX: prefix of the package as distributed in the tarball.
#
# PYPACKAGE: name of the Python package as it will end up installed. If not
# given, it defaults to PAKPREFIX.
#
#-----------------------------------------------------------------------------
# Process command-line args
#
PAKPREFIX=$1
PYPACKAGE=${2:-$PAKPREFIX}
#-----------------------------------------------------------------------------
# Configure main variables
#
# Defaults for variables that the .cfg file may override.
PYTHON_DEFAULT=python
PREFIX_DEFAULT=$HOME/usr/local
# Read config file which may declare user values for these variables.
source ./pkginstall.cfg
# Set the variables we'll actually use, either from the config file or from our
# defaults.
PYTHON=${PYTHON-${PYTHON_DEFAULT}}
PREFIX=${PREFIX-${PREFIX_DEFAULT}}
#-----------------------------------------------------------------------------
# 'Main' code begins
#
# Find the actual python executable path
PYTHONX=$(which $PYTHON)
if [[ ! -x $PYTHONX ]]; then
echo "ERROR: no python executable found at given path: $PYTHON"
echo "Aborting."
exit 1
fi
# Python version information. PYTHONV holds a versioned string used to build
# the site-packages path for the actual Python version we'll use.
PYVER=$($PYTHONX -ESV 2>&1)
PYVER_MINOR=${PYVER#Python }
PYVER_MAJOR=${PYVER_MINOR:0:3}
PYTHONV=python${PYVER_MAJOR}
# Set prefixes and other variables for the installation path.
SITEPKG=${PREFIX}/lib/${PYTHONV}/site-packages
SITEPKG64=${PREFIX}/lib64/${PYTHONV}/site-packages
# User diagnostics of current config
echo "Configuration:"
echo " PYTHON : $PYTHON"
echo " PYTHONX : $PYTHONX"
echo " PREFIX : $PREFIX"
echo " SITEPKG : $SITEPKG"
echo " SITEPKG64: $SITEPKG64"
# Find tarball
tarball=$(ls *$PAKPREFIX*.tar.*)
if [[ -z $tarball ]]; then
echo "ERROR: tarball not found for $PYPACKAGE"
exit 1
fi
# Figure out the name of the directory and compression format to use to unpack
pakdir=$(echo $tarball | awk -F '.tar.' '{print $1}')
tarfmt=$(echo $tarball | awk -F '.tar.' '{print $2}')
if [[ $tarfmt == "gz" ]]; then
tarflag="z"
else
tarflag="j"
fi
# Unpack the tarball if needed
if [[ ! -d $pakdir ]]; then
echo "Unpacking tarball: $tarball"
tar -x -${tarflag} -f $tarball
if [[ ! -d $pakdir ]]; then
echo "Tarball $tarball unpacked to unexpected path, aborting"
exit 1
fi
fi
# Remove existing ${PYPACKAGE} to make sure the build doesn't pick up spurious
# things. We don't touch the bin/ dir or anything else because it's hard to
# know what goes there in advance. But this should prevent most serious
# problems.
rm -rf $SITEPKG/${PYPACKAGE}
rm -rf $SITEPKG/${PYPACKAGE}*.egg
rm -rf $SITEPKG/${PYPACKAGE}*.egg-info
rm -rf $SITEPKG64/${PYPACKAGE}
rm -rf $SITEPKG64/${PYPACKAGE}*.egg
rm -rf $SITEPKG64/${PYPACKAGE}*.egg-info
# Make/install phase
# Set python search path correctly
export PYTHONPATH=$SITEPKG:$SITEPKG64:$PYTHONPATH
# Ensure install dirs exist
mkdir -p $SITEPKG
mkdir -p $SITEPKG64
cd ${pakdir}
rm -rf build dist
$PYTHONX setup.py clean
time $PYTHONX setup.py install --prefix=$PREFIX