about summary refs log tree commit diff
path: root/pkgs/development/interpreters
diff options
context:
space:
mode:
authorPeter Simons <simons@cryp.to>2013-11-07 15:13:02 +0100
committerPeter Simons <simons@cryp.to>2013-11-07 15:13:02 +0100
commit29588edfe1896d291257bf35e734ff197cd7971b (patch)
tree6e7274ce0b469b15c226cf12d30e983bacc118df /pkgs/development/interpreters
parentb53f71e7155a903e698c99a9fea9c191751d9bd7 (diff)
downloadnixlib-29588edfe1896d291257bf35e734ff197cd7971b.tar
nixlib-29588edfe1896d291257bf35e734ff197cd7971b.tar.gz
nixlib-29588edfe1896d291257bf35e734ff197cd7971b.tar.bz2
nixlib-29588edfe1896d291257bf35e734ff197cd7971b.tar.lz
nixlib-29588edfe1896d291257bf35e734ff197cd7971b.tar.xz
nixlib-29588edfe1896d291257bf35e734ff197cd7971b.tar.zst
nixlib-29588edfe1896d291257bf35e734ff197cd7971b.zip
python-wrapper: split 'extraLibs' into 'stdLibs' and 'extraLibs', and add 'postBuild' step
The default setting for extraLibs used to be the set of modules that come with
python by default but aren't usually enabled in our standard python derivation
because they require additional libraries. This meant that users who want to
*add* libraries to that set had to use a fairly complicated override, to add
more entries without loosing the ones set by default.

After this patch, the "standard libraries" such as "curses' are listed in
stdLibs while the extraLibs argument remains empty by default. This allows
users to override extraLibs without overriding the standard libraries.

Furthermore, the wrapper environment can be messed around with in an
additional 'postBuild' step. One nice application of this build step is
to patch scripts and binaries to use the wrapped python interpreter
instead of the pristine one, thereby enabling them to pick up all
modules that have been configured. The following example shows how this
is done for the 'pylint' utility:

  pkgs.python27Full.override {
    extraLibs = [pkgs.pylint];
    postBuild = ''
      cd ${pkgs.pylint}/bin
      for i in *; do
        rm $out/bin/$i
        sed -r -e "s|^exec |exec $out/bin/python -- |" <$i >$out/bin/$i
        chmod +x $out/bin/$i
      done;
    '';
  };
Diffstat (limited to 'pkgs/development/interpreters')
-rw-r--r--pkgs/development/interpreters/python/wrapper.nix9
1 files changed, 5 insertions, 4 deletions
diff --git a/pkgs/development/interpreters/python/wrapper.nix b/pkgs/development/interpreters/python/wrapper.nix
index a749a82fc8ae..34af23740d5d 100644
--- a/pkgs/development/interpreters/python/wrapper.nix
+++ b/pkgs/development/interpreters/python/wrapper.nix
@@ -1,10 +1,12 @@
-{ stdenv, python, buildEnv, makeWrapper, recursivePthLoader, extraLibs ? [] }:
+{ stdenv, python, buildEnv, makeWrapper, recursivePthLoader, extraLibs ? [], postBuild ? ""
+, stdLibs ? stdenv.lib.attrValues python.modules
+}:
 
 # Create a python executable that knows about additional packages.
 
 (buildEnv {
   name = "python-${python.version}-wrapper";
-  paths = stdenv.lib.filter (x : x ? pythonPath) (stdenv.lib.closePropagation extraLibs) ++ [ python recursivePthLoader ];
+  paths = stdenv.lib.filter (x : x ? pythonPath) (stdenv.lib.closePropagation extraLibs) ++ stdLibs ++ [ python recursivePthLoader ];
   ignoreCollisions = false;
 
   postBuild = ''
@@ -17,11 +19,10 @@
 
     cd "${python}/bin"
     for prg in *; do
-      echo "$prg --> $out/bin/$prg"
       rm -f "$out/bin/$prg"
       makeWrapper "${python}/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out"
     done
-  '';
+  '' + postBuild;
 }) // {
   inherit python;
   inherit (python) meta;