2015-05-24 11:55:24 +02:00
|
|
|
# Wrapper around wrapPythonProgramsIn, below. The $pythonPath
|
|
|
|
# variable is passed in from the buildPythonPackage function.
|
2011-03-28 18:33:33 +02:00
|
|
|
wrapPythonPrograms() {
|
|
|
|
wrapPythonProgramsIn $out "$out $pythonPath"
|
|
|
|
}
|
|
|
|
|
2015-05-24 11:55:24 +02:00
|
|
|
# Transforms any binaries generated by the setup.py script, replacing them
|
|
|
|
# with an executable shell script which will set some environment variables
|
|
|
|
# and then call into the original binary (which has been given a .wrapped
|
|
|
|
# suffix).
|
2011-03-28 18:33:33 +02:00
|
|
|
wrapPythonProgramsIn() {
|
|
|
|
local dir="$1"
|
|
|
|
local pythonPath="$2"
|
2014-03-07 14:33:59 +01:00
|
|
|
local python="@executable@"
|
2015-05-24 11:55:24 +02:00
|
|
|
local path
|
|
|
|
local f
|
2011-03-28 18:33:33 +02:00
|
|
|
|
2015-05-24 11:55:24 +02:00
|
|
|
# Create an empty table of python paths (see doc on _addToPythonPath
|
|
|
|
# for how this is used). Build up the program_PATH and program_PYTHONPATH
|
|
|
|
# variables.
|
2011-03-28 18:33:33 +02:00
|
|
|
declare -A pythonPathsSeen=()
|
|
|
|
program_PYTHONPATH=
|
|
|
|
program_PATH=
|
2015-05-24 11:55:24 +02:00
|
|
|
for path in $pythonPath; do
|
|
|
|
_addToPythonPath $path
|
2011-03-28 18:33:33 +02:00
|
|
|
done
|
|
|
|
|
2015-05-24 11:55:24 +02:00
|
|
|
# Find all regular files in the output directory that are executable.
|
|
|
|
for f in $(find "$dir" -type f -perm +0100); do
|
2011-03-28 19:19:27 +02:00
|
|
|
# Rewrite "#! .../env python" to "#! /nix/store/.../python".
|
2015-05-24 11:55:24 +02:00
|
|
|
if head -n1 "$f" | grep -q '#!.*/env.*\(python\|pypy\)'; then
|
|
|
|
sed -i "$f" -e "1 s^.*/env[ ]*\(python\|pypy\)^#! $python^"
|
2011-03-28 19:19:27 +02:00
|
|
|
fi
|
2015-05-24 11:55:24 +02:00
|
|
|
|
2015-03-07 22:31:40 +01:00
|
|
|
# catch /python and /.python-wrapped
|
2015-05-24 11:55:24 +02:00
|
|
|
if head -n1 "$f" | grep -q '/\.\?\(python\|pypy\)'; then
|
2013-07-29 19:31:58 +02:00
|
|
|
# dont wrap EGG-INFO scripts since they are called from python
|
2015-05-24 11:55:24 +02:00
|
|
|
if echo "$f" | grep -qv EGG-INFO/scripts; then
|
|
|
|
echo "wrapping \`$f'..."
|
|
|
|
sed -i "$f" -re '@magicalSedExpression@'
|
|
|
|
# wrapProgram creates the executable shell script described
|
|
|
|
# above. The script will set PYTHONPATH and PATH variables.!
|
|
|
|
# (see pkgs/build-support/setup-hooks/make-wrapper.sh)
|
|
|
|
wrapProgram $f \
|
|
|
|
--prefix PYTHONPATH ':' $program_PYTHONPATH \
|
|
|
|
--prefix PATH ':' $program_PATH
|
2013-07-29 19:31:58 +02:00
|
|
|
fi
|
2011-03-28 18:33:33 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2015-05-24 11:55:24 +02:00
|
|
|
# Adds the lib and bin directories to the PYTHONPATH and PATH variables,
|
|
|
|
# respectively. Recurses on any paths declared in
|
|
|
|
# `propagated-native-build-inputs`, while avoiding duplicating paths by
|
|
|
|
# flagging the directories it has visited in `pythonPathsSeen`.
|
2011-03-28 18:33:33 +02:00
|
|
|
_addToPythonPath() {
|
|
|
|
local dir="$1"
|
2015-05-24 11:55:24 +02:00
|
|
|
# Stop if we've already visited here.
|
2011-03-28 18:33:33 +02:00
|
|
|
if [ -n "${pythonPathsSeen[$dir]}" ]; then return; fi
|
|
|
|
pythonPathsSeen[$dir]=1
|
2015-05-24 11:55:24 +02:00
|
|
|
# addToSearchPath is defined in stdenv/generic/setup.sh. It will have
|
|
|
|
# the effect of calling `export program_X=$dir/...:$program_X`.
|
2011-03-29 17:19:59 +02:00
|
|
|
addToSearchPath program_PYTHONPATH $dir/lib/@libPrefix@/site-packages
|
2011-03-28 18:33:33 +02:00
|
|
|
addToSearchPath program_PATH $dir/bin
|
2015-05-24 11:55:24 +02:00
|
|
|
|
|
|
|
# Inspect the propagated inputs (if they exist) and recur on them.
|
2012-12-28 19:20:09 +01:00
|
|
|
local prop="$dir/nix-support/propagated-native-build-inputs"
|
2011-03-28 18:33:33 +02:00
|
|
|
if [ -e $prop ]; then
|
2015-05-24 11:55:24 +02:00
|
|
|
local new_path
|
|
|
|
for new_path in $(cat $prop); do
|
|
|
|
_addToPythonPath $new_path
|
2011-03-28 18:33:33 +02:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
2012-07-21 01:55:50 +02:00
|
|
|
|
|
|
|
createBuildInputsPth() {
|
|
|
|
local category="$1"
|
|
|
|
local inputs="$2"
|
|
|
|
if [ foo"$inputs" != foo ]; then
|
|
|
|
for x in $inputs; do
|
2013-01-11 18:03:32 +01:00
|
|
|
if $(echo -n $x |grep -q python-recursive-pth-loader); then
|
|
|
|
continue
|
|
|
|
fi
|
2012-07-21 01:55:50 +02:00
|
|
|
if test -d "$x"/lib/@libPrefix@/site-packages; then
|
2012-07-22 02:07:23 +02:00
|
|
|
echo $x/lib/@libPrefix@/site-packages \
|
|
|
|
>> "$out"/lib/@libPrefix@/site-packages/${name}-nix-python-$category.pth
|
2012-07-21 01:55:50 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|