mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-02 03:43:06 +00:00
wrapPythonProgram: split into several functions
This commit is contained in:
parent
01624e1ac2
commit
4ad459e3e0
@ -4,16 +4,12 @@ wrapPythonPrograms() {
|
|||||||
wrapPythonProgramsIn $out "$out $pythonPath"
|
wrapPythonProgramsIn $out "$out $pythonPath"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Transforms any binaries generated by the setup.py script, replacing them
|
# Builds environment variables like PYTHONPATH and PATH walking through closure
|
||||||
# with an executable shell script which will set some environment variables
|
# of dependencies.
|
||||||
# and then call into the original binary (which has been given a .wrapped
|
buildPythonPath() {
|
||||||
# suffix).
|
local pythonPath="$1"
|
||||||
wrapPythonProgramsIn() {
|
|
||||||
local dir="$1"
|
|
||||||
local pythonPath="$2"
|
|
||||||
local python="@executable@"
|
local python="@executable@"
|
||||||
local path
|
local path
|
||||||
local f
|
|
||||||
|
|
||||||
# Create an empty table of python paths (see doc on _addToPythonPath
|
# Create an empty table of python paths (see doc on _addToPythonPath
|
||||||
# for how this is used). Build up the program_PATH and program_PYTHONPATH
|
# for how this is used). Build up the program_PATH and program_PYTHONPATH
|
||||||
@ -24,6 +20,30 @@ wrapPythonProgramsIn() {
|
|||||||
for path in $pythonPath; do
|
for path in $pythonPath; do
|
||||||
_addToPythonPath $path
|
_addToPythonPath $path
|
||||||
done
|
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.
|
# Find all regular files in the output directory that are executable.
|
||||||
for f in $(find "$dir" -type f -perm -0100); do
|
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
|
# dont wrap EGG-INFO scripts since they are called from python
|
||||||
if echo "$f" | grep -qv EGG-INFO/scripts; then
|
if echo "$f" | grep -qv EGG-INFO/scripts; then
|
||||||
echo "wrapping \`$f'..."
|
echo "wrapping \`$f'..."
|
||||||
# The magicalSedExpression will invoke a "$(basename "$f")", so
|
patchPythonScript "$f"
|
||||||
# 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@'
|
|
||||||
# wrapProgram creates the executable shell script described
|
# wrapProgram creates the executable shell script described
|
||||||
# above. The script will set PYTHONPATH and PATH variables.!
|
# above. The script will set PYTHONPATH and PATH variables.!
|
||||||
# (see pkgs/build-support/setup-hooks/make-wrapper.sh)
|
# (see pkgs/build-support/setup-hooks/make-wrapper.sh)
|
||||||
local -a wrap_args=("$f"
|
local -a wrap_args=("$f"
|
||||||
--prefix PATH ':' "$program_PATH:$dir/bin")
|
--prefix PATH ':' "$program_PATH")
|
||||||
|
|
||||||
# Add any additional arguments provided by makeWrapperArgs
|
# Add any additional arguments provided by makeWrapperArgs
|
||||||
# argument to buildPythonPackage.
|
# argument to buildPythonPackage.
|
||||||
|
Loading…
Reference in New Issue
Block a user