@@ -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)