summary refs log tree commit diff
diff options
context:
space:
mode:
authorfigsoda <figsoda@pm.me>2023-09-08 20:38:54 -0400
committerfigsoda <figsoda@pm.me>2023-09-12 19:54:03 -0400
commit6893201945af31336ce2e3ec886de773a1e48b6f (patch)
tree845a61c254d20b7a6793572da8febfd0598c255d
parentaa17cca984a209175d977ae8bb814ae37dfb5400 (diff)
downloadnixpkgs-6893201945af31336ce2e3ec886de773a1e48b6f.tar
nixpkgs-6893201945af31336ce2e3ec886de773a1e48b6f.tar.gz
nixpkgs-6893201945af31336ce2e3ec886de773a1e48b6f.tar.bz2
nixpkgs-6893201945af31336ce2e3ec886de773a1e48b6f.tar.lz
nixpkgs-6893201945af31336ce2e3ec886de773a1e48b6f.tar.xz
nixpkgs-6893201945af31336ce2e3ec886de773a1e48b6f.tar.zst
nixpkgs-6893201945af31336ce2e3ec886de773a1e48b6f.zip
python310Packages.buildPythonPackage: introduce pyproject option
-rw-r--r--pkgs/development/interpreters/python/mk-python-derivation.nix38
1 files changed, 28 insertions, 10 deletions
diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix
index 8a75dbf43a7..e9c783116b6 100644
--- a/pkgs/development/interpreters/python/mk-python-derivation.nix
+++ b/pkgs/development/interpreters/python/mk-python-derivation.nix
@@ -82,6 +82,11 @@
 # However, some packages do provide executables with extensions, and thus bytecode is generated.
 , removeBinBytecode ? true
 
+# pyproject = true <-> format = "pyproject"
+# pyproject = false <-> format = "other"
+# https://github.com/NixOS/nixpkgs/issues/253154
+, pyproject ? null
+
 # Several package formats are supported.
 # "setuptools" : Install a common setuptools/distutils based package. This builds a wheel.
 # "wheel" : Install from a pre-compiled wheel.
@@ -89,7 +94,7 @@
 # "pyproject": Install a package using a ``pyproject.toml`` file (PEP517). This builds a wheel.
 # "egg": Install a package from an egg.
 # "other" : Provide your own buildPhase and installPhase.
-, format ? "setuptools"
+, format ? null
 
 , meta ? {}
 
@@ -101,10 +106,23 @@
 
 , ... } @ attrs:
 
+assert (pyproject != null) -> (format == null);
+
 let
   inherit (python) stdenv;
 
-  withDistOutput = lib.elem format ["pyproject" "setuptools" "flit" "wheel"];
+  format' =
+    if pyproject != null then
+      if pyproject then
+        "pyproject"
+      else
+        "other"
+    else if format != null then
+      format
+    else
+      "setuptools";
+
+  withDistOutput = lib.elem format' ["pyproject" "setuptools" "flit" "wheel"];
 
   name_ = name;
 
@@ -177,7 +195,7 @@ let
 
   # Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
   self = toPythonModule (stdenv.mkDerivation ((builtins.removeAttrs attrs [
-    "disabled" "checkPhase" "checkInputs" "nativeCheckInputs" "doCheck" "doInstallCheck" "dontWrapPythonPrograms" "catchConflicts" "format"
+    "disabled" "checkPhase" "checkInputs" "nativeCheckInputs" "doCheck" "doInstallCheck" "dontWrapPythonPrograms" "catchConflicts" "pyproject" "format"
     "disabledTestPaths" "outputs"
   ]) // {
 
@@ -202,11 +220,11 @@ let
       pythonRemoveBinBytecodeHook
     ] ++ lib.optionals (lib.hasSuffix "zip" (attrs.src.name or "")) [
       unzip
-    ] ++ lib.optionals (format == "setuptools") [
+    ] ++ lib.optionals (format' == "setuptools") [
       setuptoolsBuildHook
-    ] ++ lib.optionals (format == "flit") [
+    ] ++ lib.optionals (format' == "flit") [
       flitBuildHook
-    ] ++ lib.optionals (format == "pyproject") [(
+    ] ++ lib.optionals (format' == "pyproject") [(
       if isBootstrapPackage then
         pypaBuildHook.override {
           inherit (python.pythonForBuild.pkgs.bootstrap) build;
@@ -214,11 +232,11 @@ let
         }
       else
         pypaBuildHook
-    )] ++ lib.optionals (format == "wheel") [
+    )] ++ lib.optionals (format' == "wheel") [
       wheelUnpackHook
-    ] ++ lib.optionals (format == "egg") [
+    ] ++ lib.optionals (format' == "egg") [
       eggUnpackHook eggBuildHook eggInstallHook
-    ] ++ lib.optionals (format != "other") [(
+    ] ++ lib.optionals (format' != "other") [(
       if isBootstrapInstallPackage then
         pypaInstallHook.override {
           inherit (python.pythonForBuild.pkgs.bootstrap) installer;
@@ -252,7 +270,7 @@ let
     doCheck = false;
     doInstallCheck = attrs.doCheck or true;
     nativeInstallCheckInputs = [
-    ] ++ lib.optionals (format == "setuptools") [
+    ] ++ lib.optionals (format' == "setuptools") [
       # Longer-term we should get rid of this and require
       # users of this function to set the `installCheckPhase` or
       # pass in a hook that sets it.