summary refs log tree commit diff
diff options
context:
space:
mode:
authorzimbatm <zimbatm@zimbatm.com>2016-05-09 14:39:41 +0100
committerzimbatm <zimbatm@zimbatm.com>2016-05-09 14:39:41 +0100
commit428db7857e8fae65c32e87f5d768af141cbb3ad5 (patch)
tree8f624476c5a821607ef2c7e692e871bbd131d9ef
parent9cc724e570ebe6dcb6089e2fcd9c65f79ca85a01 (diff)
parent3c0dc7a7c7d581fc54ad4d87af746db9eefc57e0 (diff)
downloadnixlib-428db7857e8fae65c32e87f5d768af141cbb3ad5.tar
nixlib-428db7857e8fae65c32e87f5d768af141cbb3ad5.tar.gz
nixlib-428db7857e8fae65c32e87f5d768af141cbb3ad5.tar.bz2
nixlib-428db7857e8fae65c32e87f5d768af141cbb3ad5.tar.lz
nixlib-428db7857e8fae65c32e87f5d768af141cbb3ad5.tar.xz
nixlib-428db7857e8fae65c32e87f5d768af141cbb3ad5.tar.zst
nixlib-428db7857e8fae65c32e87f5d768af141cbb3ad5.zip
Merge pull request #15010 from FRidh/format
Python: support installing wheels
-rw-r--r--doc/languages-frameworks/python.md1
-rw-r--r--pkgs/development/python-modules/generic/default.nix77
-rw-r--r--pkgs/top-level/python-packages.nix13
3 files changed, 64 insertions, 27 deletions
diff --git a/doc/languages-frameworks/python.md b/doc/languages-frameworks/python.md
index 81da5c704395..a04ca75a2fbb 100644
--- a/doc/languages-frameworks/python.md
+++ b/doc/languages-frameworks/python.md
@@ -534,6 +534,7 @@ All parameters from `mkDerivation` function are still supported.
 * `postShellHook`: Hook to execute commands after `shellHook`.
 * `makeWrapperArgs`: A list of strings. Arguments to be passed to `makeWrapper`, which wraps generated binaries. By default, the arguments to `makeWrapper` set `PATH` and `PYTHONPATH` environment variables before calling the binary. Additional arguments here can allow a developer to set environment variables which will be available when the binary is run. For example, `makeWrapperArgs = ["--set FOO BAR" "--set BAZ QUX"]`.
 * `installFlags`: A list of strings. Arguments to be passed to `pip install`. To pass options to `python setup.py install`, use `--install-option`. E.g., `installFlags=["--install-option='--cpp_implementation'"].
+* `format`: Format of the source. Options are `setup` for when the source has a `setup.py` and `setuptools` is used to build a wheel, and `wheel` in case the source is already a binary wheel. The default value is `setup`.
 
 #### `buildPythonApplication` function
 
diff --git a/pkgs/development/python-modules/generic/default.nix b/pkgs/development/python-modules/generic/default.nix
index 1fdbd4ffc0bd..b8e1e8cad71b 100644
--- a/pkgs/development/python-modules/generic/default.nix
+++ b/pkgs/development/python-modules/generic/default.nix
@@ -21,9 +21,6 @@
 # https://github.com/pypa/pip/issues/881
 , setupPyBuildFlags ? []
 
-# enable tests by default
-, doCheck ? true
-
 # DEPRECATED: use propagatedBuildInputs
 , pythonPath ? []
 
@@ -45,6 +42,8 @@
 # Additional flags to pass to "pip install".
 , installFlags ? []
 
+, format ? "setup"
+
 , ... } @ attrs:
 
 
@@ -57,8 +56,51 @@ let
   # use setuptools shim (so that setuptools is imported before distutils)
   # pip does the same thing: https://github.com/pypa/pip/pull/3265
   setuppy = ./run_setup.py;
-  # For backwards compatibility, let's use an alias
-  doInstallCheck = doCheck;
+
+  formatspecific =
+    if format == "wheel" then
+      {
+        unpackPhase = ''
+          mkdir dist
+          cp $src dist/"''${src#*-}"
+        '';
+
+        # Wheels are pre-compiled
+        buildPhase = attrs.buildPhase or ":";
+        installCheckPhase = attrs.checkPhase or ":";
+
+        # Wheels don't have any checks to run
+        doInstallCheck = attrs.doCheck or false;
+      }
+    else if format == "setup" then
+      {
+        # propagate python/setuptools to active setup-hook in nix-shell
+        propagatedBuildInputs =
+          propagatedBuildInputs ++ [ python setuptools ];
+
+        # we copy nix_run_setup.py over so it's executed relative to the root of the source
+        # many project make that assumption
+        buildPhase = attrs.buildPhase or ''
+          runHook preBuild
+          cp ${setuppy} nix_run_setup.py
+          ${python.interpreter} nix_run_setup.py ${lib.optionalString (setupPyBuildFlags != []) ("build_ext " + (lib.concatStringsSep " " setupPyBuildFlags))} bdist_wheel
+          runHook postBuild
+        '';
+
+        installCheckPhase = attrs.checkPhase or ''
+          runHook preCheck
+          ${python.interpreter} nix_run_setup.py test
+          runHook postCheck
+        '';
+
+        # We run all tests after software has been installed since that is
+        # a common idiom in Python
+        #
+        # For backwards compatibility, let's use an alias
+        doInstallCheck = attrs.doCheck or false;
+      }
+    else
+      throw "Unsupported format ${format}";
 in
 python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] // {
   name = namePrefix + name;
@@ -67,9 +109,6 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] //
     ++ [ (ensureNewerSourcesHook { year = "1980"; }) ]
     ++ (lib.optional (lib.hasSuffix "zip" attrs.src.name or "") unzip);
 
-  # propagate python/setuptools to active setup-hook in nix-shell
-  propagatedBuildInputs = propagatedBuildInputs ++ [ python setuptools ];
-
   pythonPath = pythonPath;
 
   configurePhase = attrs.configurePhase or ''
@@ -82,14 +121,8 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] //
     runHook postConfigure
   '';
 
-  # we copy nix_run_setup.py over so it's executed relative to the root of the source
-  # many project make that assumption
-  buildPhase = attrs.buildPhase or ''
-    runHook preBuild
-    cp ${setuppy} nix_run_setup.py
-    ${python.interpreter} nix_run_setup.py ${lib.optionalString (setupPyBuildFlags != []) ("build_ext " + (lib.concatStringsSep " " setupPyBuildFlags))} bdist_wheel
-    runHook postBuild
-  '';
+  # Python packages don't have a checkPhase, only a installCheckPhase
+  doCheck = false;
 
   installPhase = attrs.installPhase or ''
     runHook preInstall
@@ -104,16 +137,6 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] //
     runHook postInstall
   '';
 
-  # We run all tests after software has been installed since that is
-  # a common idiom in Python
-  doInstallCheck = doInstallCheck;
-
-  installCheckPhase = attrs.checkPhase or ''
-    runHook preCheck
-    ${python.interpreter} nix_run_setup.py test
-    runHook postCheck
-  '';
-
   postFixup = attrs.postFixup or ''
     wrapPythonPrograms
 
@@ -143,4 +166,4 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] //
     # a marker for release utilities to discover python packages
     isBuildPythonPackage = python.meta.platforms;
   };
-})
+} // formatspecific)
diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index cad802e6729c..f28d9270a195 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -5477,6 +5477,19 @@ in modules // {
     };
   });
 
+  entrypoints = buildPythonPackage rec {
+    name = "entrypoints";
+    version = "0.2.1";
+    format = "wheel";
+
+    src = pkgs.fetchurl {
+      url = "https://pypi.python.org/packages/a5/2d/26548d66d58f7775cb332fcf3f864987c05f5e3f800b0b22b9919dacf653/entrypoints-0.2.1-py2.py3-none-any.whl";
+      sha256 = "112n36dllmls19j5k6bwcnsm6y2789lxzkjl1n9yir7gkm0dmzzw";
+    };
+
+    propagatedBuildInputs = with self; [ configparser ];
+  };
+
 
   evdev = buildPythonPackage rec {
     version = "0.4.7";