nixpkgs/pkgs/development/python-modules/generic/wrap.sh
Florian Friesdorf 2ea5e2b576 Revert "suffix pythonpath"
This reverts commit a9a2b1e0dd8cdbb1dff3253d303b35d41f29b0f9.

svn path=/nixpkgs/branches/stdenv-updates/; revision=32652
2012-02-28 00:07:19 +00:00

56 lines
1.5 KiB
Bash

wrapPythonPrograms() {
wrapPythonProgramsIn $out "$out $pythonPath"
}
wrapPythonProgramsIn() {
local dir="$1"
local pythonPath="$2"
local python="$(type -p python)"
local i
declare -A pythonPathsSeen=()
program_PYTHONPATH=
program_PATH=
for i in $pythonPath; do
_addToPythonPath $i
done
program_PYTHONPATH='$(
# activate site if installed
bindir=$(dirname "$0")
pysite="$bindir/pysite"
relpath=$(test -x "$pysite" && "$pysite" path)
echo -n ${relpath:+"$relpath":}
)'"$program_PYTHONPATH"
for i in $(find "$dir" -type f -perm +0100); do
# Rewrite "#! .../env python" to "#! /nix/store/.../python".
if head -n1 "$i" | grep -q '#!.*/env.*python'; then
sed -i "$i" -e "1 s^.*/env[ ]*python^#! $python^"
fi
if head -n1 "$i" | grep -q /python; then
echo "wrapping \`$i'..."
wrapProgram "$i" \
--prefix PYTHONPATH ":" "$program_PYTHONPATH" \
--prefix PATH ":" $program_PATH
fi
done
}
_addToPythonPath() {
local dir="$1"
if [ -n "${pythonPathsSeen[$dir]}" ]; then return; fi
pythonPathsSeen[$dir]=1
addToSearchPath program_PYTHONPATH $dir/lib/@libPrefix@/site-packages
addToSearchPath program_PATH $dir/bin
local prop="$dir/nix-support/propagated-build-native-inputs"
if [ -e $prop ]; then
local i
for i in $(cat $prop); do
_addToPythonPath $i
done
fi
}