adding docs to python wrap.sh
This commit is contained in:
parent
efd4fcbebc
commit
5f55788531
@ -1,51 +1,74 @@
|
|||||||
|
# Wrapper around wrapPythonProgramsIn, below. The $pythonPath
|
||||||
|
# variable is passed in from the buildPythonPackage function.
|
||||||
wrapPythonPrograms() {
|
wrapPythonPrograms() {
|
||||||
wrapPythonProgramsIn $out "$out $pythonPath"
|
wrapPythonProgramsIn $out "$out $pythonPath"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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).
|
||||||
wrapPythonProgramsIn() {
|
wrapPythonProgramsIn() {
|
||||||
local dir="$1"
|
local dir="$1"
|
||||||
local pythonPath="$2"
|
local pythonPath="$2"
|
||||||
local python="@executable@"
|
local python="@executable@"
|
||||||
local i
|
local path
|
||||||
|
local f
|
||||||
|
|
||||||
|
# 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.
|
||||||
declare -A pythonPathsSeen=()
|
declare -A pythonPathsSeen=()
|
||||||
program_PYTHONPATH=
|
program_PYTHONPATH=
|
||||||
program_PATH=
|
program_PATH=
|
||||||
for i in $pythonPath; do
|
for path in $pythonPath; do
|
||||||
_addToPythonPath $i
|
_addToPythonPath $path
|
||||||
done
|
done
|
||||||
|
|
||||||
for i in $(find "$dir" -type f -perm +0100); do
|
# Find all regular files in the output directory that are executable.
|
||||||
|
for f in $(find "$dir" -type f -perm +0100); do
|
||||||
# Rewrite "#! .../env python" to "#! /nix/store/.../python".
|
# Rewrite "#! .../env python" to "#! /nix/store/.../python".
|
||||||
if head -n1 "$i" | grep -q '#!.*/env.*\(python\|pypy\)'; then
|
if head -n1 "$f" | grep -q '#!.*/env.*\(python\|pypy\)'; then
|
||||||
sed -i "$i" -e "1 s^.*/env[ ]*\(python\|pypy\)^#! $python^"
|
sed -i "$f" -e "1 s^.*/env[ ]*\(python\|pypy\)^#! $python^"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# catch /python and /.python-wrapped
|
# catch /python and /.python-wrapped
|
||||||
if head -n1 "$i" | grep -q '/\.\?\(python\|pypy\)'; then
|
if head -n1 "$f" | grep -q '/\.\?\(python\|pypy\)'; then
|
||||||
# dont wrap EGG-INFO scripts since they are called from python
|
# dont wrap EGG-INFO scripts since they are called from python
|
||||||
if echo "$i" | grep -v EGG-INFO/scripts; then
|
if echo "$f" | grep -qv EGG-INFO/scripts; then
|
||||||
echo "wrapping \`$i'..."
|
echo "wrapping \`$f'..."
|
||||||
sed -i "$i" -re '@magicalSedExpression@'
|
sed -i "$f" -re '@magicalSedExpression@'
|
||||||
wrapProgram "$i" \
|
# wrapProgram creates the executable shell script described
|
||||||
--prefix PYTHONPATH ":" $program_PYTHONPATH \
|
# above. The script will set PYTHONPATH and PATH variables.!
|
||||||
--prefix PATH ":" $program_PATH
|
# (see pkgs/build-support/setup-hooks/make-wrapper.sh)
|
||||||
|
wrapProgram $f \
|
||||||
|
--prefix PYTHONPATH ':' $program_PYTHONPATH \
|
||||||
|
--prefix PATH ':' $program_PATH
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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`.
|
||||||
_addToPythonPath() {
|
_addToPythonPath() {
|
||||||
local dir="$1"
|
local dir="$1"
|
||||||
|
# Stop if we've already visited here.
|
||||||
if [ -n "${pythonPathsSeen[$dir]}" ]; then return; fi
|
if [ -n "${pythonPathsSeen[$dir]}" ]; then return; fi
|
||||||
pythonPathsSeen[$dir]=1
|
pythonPathsSeen[$dir]=1
|
||||||
|
# addToSearchPath is defined in stdenv/generic/setup.sh. It will have
|
||||||
|
# the effect of calling `export program_X=$dir/...:$program_X`.
|
||||||
addToSearchPath program_PYTHONPATH $dir/lib/@libPrefix@/site-packages
|
addToSearchPath program_PYTHONPATH $dir/lib/@libPrefix@/site-packages
|
||||||
addToSearchPath program_PATH $dir/bin
|
addToSearchPath program_PATH $dir/bin
|
||||||
|
|
||||||
|
# Inspect the propagated inputs (if they exist) and recur on them.
|
||||||
local prop="$dir/nix-support/propagated-native-build-inputs"
|
local prop="$dir/nix-support/propagated-native-build-inputs"
|
||||||
if [ -e $prop ]; then
|
if [ -e $prop ]; then
|
||||||
local i
|
local new_path
|
||||||
for i in $(cat $prop); do
|
for new_path in $(cat $prop); do
|
||||||
_addToPythonPath $i
|
_addToPythonPath $new_path
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user