summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorFrederik Rietdijk <fridh@fridh.nl>2022-09-09 13:36:31 +0200
committerFrederik Rietdijk <freddyrietdijk@fridh.nl>2022-09-12 22:15:39 +0200
commitadbc59c9d3b6be2cdb1c29b84afa8b30d9cc7593 (patch)
tree64f233070247a37c6e5f254f92c74a4577211480 /pkgs
parent2a452a4cbebdd41d3399b64f442f282d819c6d4f (diff)
downloadnixpkgs-adbc59c9d3b6be2cdb1c29b84afa8b30d9cc7593.tar
nixpkgs-adbc59c9d3b6be2cdb1c29b84afa8b30d9cc7593.tar.gz
nixpkgs-adbc59c9d3b6be2cdb1c29b84afa8b30d9cc7593.tar.bz2
nixpkgs-adbc59c9d3b6be2cdb1c29b84afa8b30d9cc7593.tar.lz
nixpkgs-adbc59c9d3b6be2cdb1c29b84afa8b30d9cc7593.tar.xz
nixpkgs-adbc59c9d3b6be2cdb1c29b84afa8b30d9cc7593.tar.zst
nixpkgs-adbc59c9d3b6be2cdb1c29b84afa8b30d9cc7593.zip
buildPython*: store dist (wheel/sdist) in dist output
Store the intermediate artifacts. In time, we should build, install and
test in separate derivations as that reduces circular dependencies,
avoids rebuilds when fixing tests, and makes it possible to use the
wheels for creating say virtualenv's.
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/development/interpreters/python/hooks/default.nix5
-rw-r--r--pkgs/development/interpreters/python/hooks/python-output-dist-hook.sh10
-rw-r--r--pkgs/development/interpreters/python/mk-python-derivation.nix11
-rw-r--r--pkgs/top-level/python-packages.nix1
4 files changed, 26 insertions, 1 deletions
diff --git a/pkgs/development/interpreters/python/hooks/default.nix b/pkgs/development/interpreters/python/hooks/default.nix
index 5d605b240ad..9d4b61c1a0f 100644
--- a/pkgs/development/interpreters/python/hooks/default.nix
+++ b/pkgs/development/interpreters/python/hooks/default.nix
@@ -115,6 +115,11 @@ in rec {
       };
     } ./python-namespaces-hook.sh) {};
 
+  pythonOutputDistHook = callPackage ({ }:
+    makeSetupHook {
+      name = "python-output-dist-hook";
+  } ./python-output-dist-hook.sh ) {};
+
   pythonRecompileBytecodeHook = callPackage ({ }:
     makeSetupHook {
       name = "python-recompile-bytecode-hook";
diff --git a/pkgs/development/interpreters/python/hooks/python-output-dist-hook.sh b/pkgs/development/interpreters/python/hooks/python-output-dist-hook.sh
new file mode 100644
index 00000000000..e73e45cd597
--- /dev/null
+++ b/pkgs/development/interpreters/python/hooks/python-output-dist-hook.sh
@@ -0,0 +1,10 @@
+# Setup hook for storing dist folder (wheels/sdists) in a separate output
+echo "Sourcing python-catch-conflicts-hook.sh"
+
+pythonOutputDistPhase() {
+    echo "Executing pythonOutputDistPhase"
+    mv "dist" "$dist"
+    echo "Finished executing pythonOutputDistPhase"
+}
+
+preFixupPhases+=" pythonOutputDistPhase"
diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix
index f37ad592cb4..f82611554a2 100644
--- a/pkgs/development/interpreters/python/mk-python-derivation.nix
+++ b/pkgs/development/interpreters/python/mk-python-derivation.nix
@@ -17,6 +17,7 @@
 , pythonCatchConflictsHook
 , pythonImportsCheckHook
 , pythonNamespacesHook
+, pythonOutputDistHook
 , pythonRemoveBinBytecodeHook
 , pythonRemoveTestsDirHook
 , setuptoolsBuildHook
@@ -49,6 +50,8 @@
 # Enabled to detect some (native)BuildInputs mistakes
 , strictDeps ? true
 
+, outputs ? [ "out" ]
+
 # used to disable derivation, useful for specific python versions
 , disabled ? false
 
@@ -106,11 +109,13 @@ else
 let
   inherit (python) stdenv;
 
+  withDistOutput = lib.elem format ["pyproject" "setuptools" "flit"];
+
   name_ = name;
 
   self = toPythonModule (stdenv.mkDerivation ((builtins.removeAttrs attrs [
     "disabled" "checkPhase" "checkInputs" "doCheck" "doInstallCheck" "dontWrapPythonPrograms" "catchConflicts" "format"
-    "disabledTestPaths"
+    "disabledTestPaths" "outputs"
   ]) // {
 
     name = namePrefix + name_;
@@ -144,6 +149,8 @@ let
     ] ++ lib.optionals (python.pythonAtLeast "3.3") [
       # Optionally enforce PEP420 for python3
       pythonNamespacesHook
+    ] ++ lib.optionals withDistOutput [
+      pythonOutputDistHook
     ] ++ nativeBuildInputs;
 
     buildInputs = buildInputs ++ pythonPath;
@@ -177,6 +184,8 @@ let
     # Python packages built through cross-compilation are always for the host platform.
     disallowedReferences = lib.optionals (python.stdenv.hostPlatform != python.stdenv.buildPlatform) [ python.pythonForBuild ];
 
+    outputs = outputs ++ lib.optional withDistOutput "dist";
+
     meta = {
       # default to python's platforms
       platforms = python.meta.platforms;
diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index 9e8e4aec942..fd9a0c583da 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -119,6 +119,7 @@ in {
     pythonCatchConflictsHook
     pythonImportsCheckHook
     pythonNamespacesHook
+    pythonOutputDistHook
     pythonRecompileBytecodeHook
     pythonRelaxDepsHook
     pythonRemoveBinBytecodeHook