2011-03-28 18:33:33 +02:00
|
|
|
wrapPythonPrograms() {
|
|
|
|
wrapPythonProgramsIn $out "$out $pythonPath"
|
|
|
|
}
|
|
|
|
|
|
|
|
wrapPythonProgramsIn() {
|
|
|
|
local dir="$1"
|
|
|
|
local pythonPath="$2"
|
2014-03-07 14:33:59 +01:00
|
|
|
local python="@executable@"
|
2011-03-28 18:33:33 +02:00
|
|
|
local i
|
|
|
|
|
|
|
|
declare -A pythonPathsSeen=()
|
|
|
|
program_PYTHONPATH=
|
|
|
|
program_PATH=
|
|
|
|
for i in $pythonPath; do
|
|
|
|
_addToPythonPath $i
|
|
|
|
done
|
|
|
|
|
|
|
|
for i in $(find "$dir" -type f -perm +0100); do
|
2011-03-28 19:19:27 +02:00
|
|
|
|
|
|
|
# Rewrite "#! .../env python" to "#! /nix/store/.../python".
|
2014-03-07 16:50:40 +01:00
|
|
|
if head -n1 "$i" | grep -q '#!.*/env.*\(python\|pypy\)'; then
|
|
|
|
sed -i "$i" -e "1 s^.*/env[ ]*\(python\|pypy\)^#! $python^"
|
2011-03-28 19:19:27 +02:00
|
|
|
fi
|
|
|
|
|
2014-03-07 16:50:40 +01:00
|
|
|
if head -n1 "$i" | grep -q '/python\|/pypy'; then
|
2013-07-29 19:31:58 +02:00
|
|
|
# dont wrap EGG-INFO scripts since they are called from python
|
|
|
|
if echo "$i" | grep -v EGG-INFO/scripts; then
|
|
|
|
echo "wrapping \`$i'..."
|
|
|
|
wrapProgram "$i" \
|
|
|
|
--prefix PYTHONPATH ":" $program_PYTHONPATH \
|
|
|
|
--prefix PATH ":" $program_PATH
|
|
|
|
fi
|
2011-03-28 18:33:33 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
_addToPythonPath() {
|
|
|
|
local dir="$1"
|
|
|
|
if [ -n "${pythonPathsSeen[$dir]}" ]; then return; fi
|
|
|
|
pythonPathsSeen[$dir]=1
|
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
|
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
|
|
|
|
local i
|
|
|
|
for i in $(cat $prop); do
|
|
|
|
_addToPythonPath $i
|
|
|
|
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
|
|
|
|
}
|