wrapPythonProgram: split into several functions

This commit is contained in:
Nikolay Amiantov 2016-08-17 02:51:55 +03:00
parent 01624e1ac2
commit 4ad459e3e0

View File

@ -4,16 +4,12 @@ wrapPythonPrograms() {
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() {
local dir="$1"
local pythonPath="$2"
# Builds environment variables like PYTHONPATH and PATH walking through closure
# of dependencies.
buildPythonPath() {
local pythonPath="$1"
local python="@executable@"
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
@ -24,6 +20,30 @@ wrapPythonProgramsIn() {
for path in $pythonPath; do
_addToPythonPath $path
done
}
# Patches a Python script so that it has correct libraries path and executable
# name.
patchPythonScript() {
local f="$1"
# The magicalSedExpression will invoke a "$(basename "$f")", so
# if you change $f to something else, be sure to also change it
# in pkgs/top-level/python-packages.nix!
# It also uses $program_PYTHONPATH.
sed -i "$f" -re '@magicalSedExpression@'
}
# 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() {
local dir="$1"
local pythonPath="$2"
local f
buildPythonPath "$pythonPath"
# Find all regular files in the output directory that are executable.
for f in $(find "$dir" -type f -perm -0100); do
@ -39,16 +59,12 @@ wrapPythonProgramsIn() {
# dont wrap EGG-INFO scripts since they are called from python
if echo "$f" | grep -qv EGG-INFO/scripts; then
echo "wrapping \`$f'..."
# The magicalSedExpression will invoke a "$(basename "$f")", so
# if you change $f to something else, be sure to also change it
# in pkgs/top-level/python-packages.nix!
# It also uses $program_PYTHONPATH.
sed -i "$f" -re '@magicalSedExpression@'
patchPythonScript "$f"
# 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)
local -a wrap_args=("$f"
--prefix PATH ':' "$program_PATH:$dir/bin")
--prefix PATH ':' "$program_PATH")
# Add any additional arguments provided by makeWrapperArgs
# argument to buildPythonPackage.