From d670c0e45cf411823b6a13ef012eea28786dc9d5 Mon Sep 17 00:00:00 2001 From: Florian Friesdorf Date: Sun, 26 Feb 2012 17:23:38 +0000 Subject: [PATCH] include site in pythonpath of wrapped scripts, if python-site is installed svn path=/nixpkgs/branches/stdenv-updates/; revision=32592 --- pkgs/development/python-modules/generic/wrap.sh | 10 +++++++++- pkgs/development/python-modules/site/default.nix | 10 ++++++++++ pkgs/development/python-modules/site/pysite | 13 +++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/python-modules/site/pysite diff --git a/pkgs/development/python-modules/generic/wrap.sh b/pkgs/development/python-modules/generic/wrap.sh index 65f3229ca7c..9f3803f791b 100644 --- a/pkgs/development/python-modules/generic/wrap.sh +++ b/pkgs/development/python-modules/generic/wrap.sh @@ -15,6 +15,14 @@ wrapPythonProgramsIn() { _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". @@ -25,7 +33,7 @@ wrapPythonProgramsIn() { if head -n1 "$i" | grep -q /python; then echo "wrapping \`$i'..." wrapProgram "$i" \ - --prefix PYTHONPATH ":" $program_PYTHONPATH \ + --prefix PYTHONPATH ":" "$program_PYTHONPATH" \ --prefix PATH ":" $program_PATH fi done diff --git a/pkgs/development/python-modules/site/default.nix b/pkgs/development/python-modules/site/default.nix index 98a14850dbe..c2dc99d5a43 100644 --- a/pkgs/development/python-modules/site/default.nix +++ b/pkgs/development/python-modules/site/default.nix @@ -12,6 +12,16 @@ stdenv.mkDerivation rec { dst=$out/lib/${python.libPrefix}/site-packages mkdir -p $dst cat ${./site.py} >> $dst/site.py + + # by providing content for bin/ we make sure, that python or + # some other script is linked instead of the bin/ directory + # itself. This is needed for the wrappers to make all site + # packages available if site is installed. + mkdir $out/bin + cat ${./pysite} >> $out/bin/pysite + substituteInPlace $out/bin/pysite \ + --replace PYTHON_LIB_PREFIX ${python.libPrefix} + chmod +x $out/bin/pysite ''; meta = { diff --git a/pkgs/development/python-modules/site/pysite b/pkgs/development/python-modules/site/pysite new file mode 100644 index 00000000000..b10a24014ce --- /dev/null +++ b/pkgs/development/python-modules/site/pysite @@ -0,0 +1,13 @@ +#!/bin/bash + +python=PYTHON_LIB_PREFIX + +case "$1" in + path) + echo $(dirname $0)/../lib/$python/site-packages + ;; + *) + echo Usage: + echo " $(basename $0) path" + exit 1 +esac