git.iko.soy/typeable/nixpkgs
on master help sign in
Python: allow installing wheels

By passing `format="wheel"` it is now possible to install a wheel. It's not recommended, but it can be useful.

commit303e9762451cb347e125197759bd7604a8e319a3 authorFrederik Rietdijk <fridh@fridh.nl> dateTue 26 Apr 2016, 17:57 (11 years ago) parent5a0cde6
2 files changed+51−27
doc/languages-frameworks/python.md+1 pkgs/development/python-modules/generic/default.nix+50−27
doc/languages-frameworks/python.md+1
@@ -534,6 +534,7 @@ All parameters from `mkDerivation` function are still supported.
534534* `postShellHook`: Hook to execute commands after `shellHook`.
535535* `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"]`.
536536* `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'"].
537+* `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`.
537538
538539#### `buildPythonApplication` function
539540
pkgs/development/python-modules/generic/default.nix+50−27
@@ -21,9 +21,6 @@
2121# https://github.com/pypa/pip/issues/881
2222, setupPyBuildFlags ? []
2323
24−# enable tests by default
25−, doCheck ? true
26−
2724# DEPRECATED: use propagatedBuildInputs
2825, pythonPath ? []
2926
@@ -45,6 +42,8 @@
4542# Additional flags to pass to "pip install".
4643, installFlags ? []
4744
45+, format ? "setup"
46+
4847, ... } @ attrs:
4948
5049
@@ -57,8 +56,51 @@ let
5756 # use setuptools shim (so that setuptools is imported before distutils)
5857 # pip does the same thing: https://github.com/pypa/pip/pull/3265
5958 setuppy = ./run_setup.py;
60− # For backwards compatibility, let's use an alias
61− doInstallCheck = doCheck;
59+
60+ formatspecific =
61+ if format == "wheel" then
62+ {
63+ unpackPhase = ''
64+ mkdir dist
65+ cp $src dist/"''${src#*-}"
66+ '';
67+
68+ # Wheels are pre-compiled
69+ buildPhase = attrs.buildPhase or ":";
70+ installCheckPhase = attrs.checkPhase or ":";
71+
72+ # Wheels don't have any checks to run
73+ doInstallCheck = attrs.doCheck or false;
74+ }
75+ else if format == "setup" then
76+ {
77+ # propagate python/setuptools to active setup-hook in nix-shell
78+ propagatedBuildInputs =
79+ propagatedBuildInputs ++ [ python setuptools ];
80+
81+ # we copy nix_run_setup.py over so it's executed relative to the root of the source
82+ # many project make that assumption
83+ buildPhase = attrs.buildPhase or ''
84+ runHook preBuild
85+ cp ${setuppy} nix_run_setup.py
86+ ${python.interpreter} nix_run_setup.py ${lib.optionalString (setupPyBuildFlags != []) ("build_ext " + (lib.concatStringsSep " " setupPyBuildFlags))} bdist_wheel
87+ runHook postBuild
88+ '';
89+
90+ installCheckPhase = attrs.checkPhase or ''
91+ runHook preCheck
92+ ${python.interpreter} nix_run_setup.py test
93+ runHook postCheck
94+ '';
95+
96+ # We run all tests after software has been installed since that is
97+ # a common idiom in Python
98+ #
99+ # For backwards compatibility, let's use an alias
100+ doInstallCheck = attrs.doCheck or false;
101+ }
102+ else
103+ throw "Unsupported format ${format}";
62104in
63105python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] // {
64106 name = namePrefix + name;
@@ -67,9 +109,6 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] //
67109 ++ [ (ensureNewerSourcesHook { year = "1980"; }) ]
68110 ++ (lib.optional (lib.hasSuffix "zip" attrs.src.name or "") unzip);
69111
70− # propagate python/setuptools to active setup-hook in nix-shell
71− propagatedBuildInputs = propagatedBuildInputs ++ [ python setuptools ];
72−
73112 pythonPath = pythonPath;
74113
75114 configurePhase = attrs.configurePhase or ''
@@ -82,14 +121,8 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] //
82121 runHook postConfigure
83122 '';
84123
85− # we copy nix_run_setup.py over so it's executed relative to the root of the source
86− # many project make that assumption
87− buildPhase = attrs.buildPhase or ''
88− runHook preBuild
89− cp ${setuppy} nix_run_setup.py
90− ${python.interpreter} nix_run_setup.py ${lib.optionalString (setupPyBuildFlags != []) ("build_ext " + (lib.concatStringsSep " " setupPyBuildFlags))} bdist_wheel
91− runHook postBuild
92− '';
124+ # Python packages don't have a checkPhase, only a installCheckPhase
125+ doCheck = false;
93126
94127 installPhase = attrs.installPhase or ''
95128 runHook preInstall
@@ -104,16 +137,6 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] //
104137 runHook postInstall
105138 '';
106139
107− # We run all tests after software has been installed since that is
108− # a common idiom in Python
109− doInstallCheck = doInstallCheck;
110−
111− installCheckPhase = attrs.checkPhase or ''
112− runHook preCheck
113− ${python.interpreter} nix_run_setup.py test
114− runHook postCheck
115− '';
116−
117140 postFixup = attrs.postFixup or ''
118141 wrapPythonPrograms
119142
@@ -143,4 +166,4 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] //
143166 # a marker for release utilities to discover python packages
144167 isBuildPythonPackage = python.meta.platforms;
145168 };
146−})
169+} // formatspecific)