Merge pull request #254136 from figsoda/python

python310Packages.buildPythonPackage: introduce pyproject option

authored by

Frederik Rietdijk and committed by
GitHub
53dd1a6e a8cba393

+103 -31
+68 -18
doc/languages-frameworks/python.section.md
··· 101 buildPythonPackage rec { 102 pname = "pytest"; 103 version = "3.3.1"; 104 - format = "setuptools"; 105 106 src = fetchPypi { 107 inherit pname version; ··· 167 * `dontWrapPythonPrograms ? false`: Skip wrapping of Python programs. 168 * `permitUserSite ? false`: Skip setting the `PYTHONNOUSERSITE` environment 169 variable in wrapped programs. 170 - * `format ? "setuptools"`: Format of the source. Valid options are 171 - `"setuptools"`, `"pyproject"`, `"flit"`, `"wheel"`, and `"other"`. 172 - `"setuptools"` is for when the source has a `setup.py` and `setuptools` is 173 - used to build a wheel, `flit`, in case `flit` should be used to build a wheel, 174 - and `wheel` in case a wheel is provided. Use `other` when a custom 175 - `buildPhase` and/or `installPhase` is needed. 176 * `makeWrapperArgs ? []`: A list of strings. Arguments to be passed to 177 `makeWrapper`, which wraps generated binaries. By default, the arguments to 178 `makeWrapper` set `PATH` and `PYTHONPATH` environment variables before calling ··· 286 python3.pkgs.buildPythonApplication rec { 287 pname = "luigi"; 288 version = "2.7.9"; 289 - format = "setuptools"; 290 291 src = fetchPypi { 292 inherit pname version; 293 hash = "sha256-Pe229rT0aHwA98s+nTHQMEFKZPo/yw6sot8MivFDvAw="; 294 }; 295 296 propagatedBuildInputs = with python3.pkgs; [ 297 tornado 298 python-daemon 299 ]; 300 301 meta = with lib; { 302 - ... 303 }; 304 } 305 ``` ··· 858 { lib 859 , buildPythonPackage 860 , fetchPypi 861 }: 862 863 buildPythonPackage rec { 864 pname = "toolz"; 865 version = "0.10.0"; 866 - format = "setuptools"; 867 868 src = fetchPypi { 869 inherit pname version; 870 hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA="; 871 }; 872 873 # has no tests 874 doCheck = false; ··· 918 my_toolz = python311.pkgs.buildPythonPackage rec { 919 pname = "toolz"; 920 version = "0.10.0"; 921 - format = "setuptools"; 922 923 src = fetchPypi { 924 inherit pname version; 925 hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA="; 926 }; 927 928 # has no tests 929 doCheck = false; ··· 972 , buildPythonPackage 973 , fetchPypi 974 975 # dependencies 976 , numpy, multipledispatch, python-dateutil 977 ··· 982 buildPythonPackage rec { 983 pname = "datashape"; 984 version = "0.4.7"; 985 - format = "setuptools"; 986 987 src = fetchPypi { 988 inherit pname version; 989 hash = "sha256-FLLvdm1MllKrgTGC6Gb0k0deZeVYvtCCLji/B7uhong="; 990 }; 991 992 propagatedBuildInputs = [ 993 multipledispatch ··· 1023 { lib 1024 , buildPythonPackage 1025 , fetchPypi 1026 , libxml2 1027 , libxslt 1028 }: ··· 1030 buildPythonPackage rec { 1031 pname = "lxml"; 1032 version = "3.4.4"; 1033 - format = "setuptools"; 1034 1035 src = fetchPypi { 1036 inherit pname version; 1037 hash = "sha256-s9NiusRxFydHzaNRMjjxFcvWxfi45jGb9ql6eJJyQJk="; 1038 }; 1039 1040 buildInputs = [ 1041 libxml2 ··· 1066 { lib 1067 , buildPythonPackage 1068 , fetchPypi 1069 1070 # dependencies 1071 , fftw ··· 1078 buildPythonPackage rec { 1079 pname = "pyFFTW"; 1080 version = "0.9.2"; 1081 - format = "setuptools"; 1082 1083 src = fetchPypi { 1084 inherit pname version; 1085 hash = "sha256-9ru2r6kwhUCaskiFoaPNuJCfCVoUL01J40byvRt4kHQ="; 1086 }; 1087 1088 buildInputs = [ 1089 fftw ··· 1334 1335 Keep in mind that while the examples above are done with `requirements.txt`, 1336 `pythonRelaxDepsHook` works by modifying the resulting wheel file, so it should 1337 - work in any of the formats supported by `buildPythonPackage` currently, 1338 - with the exception of `other` (see `format` in 1339 - [`buildPythonPackage` parameters](#buildpythonpackage-parameters) for more details). 1340 1341 #### Using unittestCheckHook {#using-unittestcheckhook} 1342 ··· 1461 ```nix 1462 { lib 1463 , buildPythonPackage 1464 }: 1465 1466 buildPythonPackage rec { 1467 pname = "toolz"; 1468 version = "0.10.0"; 1469 - format = "setuptools"; 1470 1471 src = fetchPypi { 1472 inherit pname version; 1473 hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA="; 1474 }; 1475 1476 meta = with lib; { 1477 changelog = "https://github.com/pytoolz/toolz/releases/tag/${version}";
··· 101 buildPythonPackage rec { 102 pname = "pytest"; 103 version = "3.3.1"; 104 + pyproject = true; 105 106 src = fetchPypi { 107 inherit pname version; ··· 167 * `dontWrapPythonPrograms ? false`: Skip wrapping of Python programs. 168 * `permitUserSite ? false`: Skip setting the `PYTHONNOUSERSITE` environment 169 variable in wrapped programs. 170 + * `pyproject`: Whether the pyproject format should be used. When set to `true`, 171 + `pypaBuildHook` will be used, and you can add the required build dependencies 172 + from `build-system.requires` to `nativeBuildInputs`. Note that the pyproject 173 + format falls back to using `setuptools`, so you can use `pyproject = true` 174 + even if the package only has a `setup.py`. When set to `false`, you can 175 + use the existing [hooks](#setup-hooks0 or provide your own logic to build the 176 + package. This can be useful for packages that don't support the pyproject 177 + format. When unset, the legacy `setuptools` hooks are used for backwards 178 + compatibility. 179 * `makeWrapperArgs ? []`: A list of strings. Arguments to be passed to 180 `makeWrapper`, which wraps generated binaries. By default, the arguments to 181 `makeWrapper` set `PATH` and `PYTHONPATH` environment variables before calling ··· 289 python3.pkgs.buildPythonApplication rec { 290 pname = "luigi"; 291 version = "2.7.9"; 292 + pyproject = true; 293 294 src = fetchPypi { 295 inherit pname version; 296 hash = "sha256-Pe229rT0aHwA98s+nTHQMEFKZPo/yw6sot8MivFDvAw="; 297 }; 298 299 + nativeBuildInputs = [ 300 + python3.pkgs.setuptools 301 + python3.pkgs.wheel 302 + ]; 303 + 304 propagatedBuildInputs = with python3.pkgs; [ 305 tornado 306 python-daemon 307 ]; 308 309 meta = with lib; { 310 + # ... 311 }; 312 } 313 ``` ··· 866 { lib 867 , buildPythonPackage 868 , fetchPypi 869 + , setuptools 870 + , wheel 871 }: 872 873 buildPythonPackage rec { 874 pname = "toolz"; 875 version = "0.10.0"; 876 + pyproject = true; 877 878 src = fetchPypi { 879 inherit pname version; 880 hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA="; 881 }; 882 + 883 + nativeBuildInputs = [ 884 + setuptools 885 + wheel 886 + ]; 887 888 # has no tests 889 doCheck = false; ··· 933 my_toolz = python311.pkgs.buildPythonPackage rec { 934 pname = "toolz"; 935 version = "0.10.0"; 936 + pyproject = true; 937 938 src = fetchPypi { 939 inherit pname version; 940 hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA="; 941 }; 942 + 943 + nativeBuildInputs = [ 944 + python311.pkgs.setuptools 945 + python311.pkgs.wheel 946 + ]; 947 948 # has no tests 949 doCheck = false; ··· 992 , buildPythonPackage 993 , fetchPypi 994 995 + # build dependencies 996 + , setuptools, wheel 997 + 998 # dependencies 999 , numpy, multipledispatch, python-dateutil 1000 ··· 1005 buildPythonPackage rec { 1006 pname = "datashape"; 1007 version = "0.4.7"; 1008 + pyproject = true; 1009 1010 src = fetchPypi { 1011 inherit pname version; 1012 hash = "sha256-FLLvdm1MllKrgTGC6Gb0k0deZeVYvtCCLji/B7uhong="; 1013 }; 1014 + 1015 + nativeBuildInputs = [ 1016 + setuptools 1017 + wheel 1018 + ]; 1019 1020 propagatedBuildInputs = [ 1021 multipledispatch ··· 1051 { lib 1052 , buildPythonPackage 1053 , fetchPypi 1054 + , setuptools 1055 + , wheel 1056 , libxml2 1057 , libxslt 1058 }: ··· 1060 buildPythonPackage rec { 1061 pname = "lxml"; 1062 version = "3.4.4"; 1063 + pyproject = true; 1064 1065 src = fetchPypi { 1066 inherit pname version; 1067 hash = "sha256-s9NiusRxFydHzaNRMjjxFcvWxfi45jGb9ql6eJJyQJk="; 1068 }; 1069 + 1070 + nativeBuildInputs = [ 1071 + setuptools 1072 + wheel 1073 + ]; 1074 1075 buildInputs = [ 1076 libxml2 ··· 1101 { lib 1102 , buildPythonPackage 1103 , fetchPypi 1104 + 1105 + # build dependencies 1106 + , setuptools 1107 + , wheel 1108 1109 # dependencies 1110 , fftw ··· 1117 buildPythonPackage rec { 1118 pname = "pyFFTW"; 1119 version = "0.9.2"; 1120 + pyproject = true; 1121 1122 src = fetchPypi { 1123 inherit pname version; 1124 hash = "sha256-9ru2r6kwhUCaskiFoaPNuJCfCVoUL01J40byvRt4kHQ="; 1125 }; 1126 + 1127 + nativeBuildInputs = [ 1128 + setuptools 1129 + wheel 1130 + ]; 1131 1132 buildInputs = [ 1133 fftw ··· 1378 1379 Keep in mind that while the examples above are done with `requirements.txt`, 1380 `pythonRelaxDepsHook` works by modifying the resulting wheel file, so it should 1381 + work with any of the existing [hooks](#setup-hooks). 1382 1383 #### Using unittestCheckHook {#using-unittestcheckhook} 1384 ··· 1503 ```nix 1504 { lib 1505 , buildPythonPackage 1506 + , fetchPypi 1507 + , setuptools 1508 + , wheel 1509 }: 1510 1511 buildPythonPackage rec { 1512 pname = "toolz"; 1513 version = "0.10.0"; 1514 + pyproject = true; 1515 1516 src = fetchPypi { 1517 inherit pname version; 1518 hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA="; 1519 }; 1520 + 1521 + nativeBuildInputs = [ 1522 + setuptools 1523 + wheel 1524 + ]; 1525 1526 meta = with lib; { 1527 changelog = "https://github.com/pytoolz/toolz/releases/tag/${version}";
+1 -1
pkgs/applications/networking/seahub/default.nix
··· 22 python.pkgs.buildPythonApplication rec { 23 pname = "seahub"; 24 version = "9.0.10"; 25 - format = "other"; 26 27 src = fetchFromGitHub { 28 owner = "haiwen";
··· 22 python.pkgs.buildPythonApplication rec { 23 pname = "seahub"; 24 version = "9.0.10"; 25 + pyproject = false; 26 27 src = fetchFromGitHub { 28 owner = "haiwen";
+28 -10
pkgs/development/interpreters/python/mk-python-derivation.nix
··· 82 # However, some packages do provide executables with extensions, and thus bytecode is generated. 83 , removeBinBytecode ? true 84 85 # Several package formats are supported. 86 # "setuptools" : Install a common setuptools/distutils based package. This builds a wheel. 87 # "wheel" : Install from a pre-compiled wheel. ··· 89 # "pyproject": Install a package using a ``pyproject.toml`` file (PEP517). This builds a wheel. 90 # "egg": Install a package from an egg. 91 # "other" : Provide your own buildPhase and installPhase. 92 - , format ? "setuptools" 93 94 , meta ? {} 95 ··· 101 102 , ... } @ attrs: 103 104 let 105 inherit (python) stdenv; 106 107 - withDistOutput = lib.elem format ["pyproject" "setuptools" "flit" "wheel"]; 108 109 name_ = name; 110 ··· 177 178 # Keep extra attributes from `attrs`, e.g., `patchPhase', etc. 179 self = toPythonModule (stdenv.mkDerivation ((builtins.removeAttrs attrs [ 180 - "disabled" "checkPhase" "checkInputs" "nativeCheckInputs" "doCheck" "doInstallCheck" "dontWrapPythonPrograms" "catchConflicts" "format" 181 "disabledTestPaths" "outputs" 182 ]) // { 183 ··· 202 pythonRemoveBinBytecodeHook 203 ] ++ lib.optionals (lib.hasSuffix "zip" (attrs.src.name or "")) [ 204 unzip 205 - ] ++ lib.optionals (format == "setuptools") [ 206 setuptoolsBuildHook 207 - ] ++ lib.optionals (format == "flit") [ 208 flitBuildHook 209 - ] ++ lib.optionals (format == "pyproject") [( 210 if isBootstrapPackage then 211 pypaBuildHook.override { 212 inherit (python.pythonForBuild.pkgs.bootstrap) build; ··· 214 } 215 else 216 pypaBuildHook 217 - )] ++ lib.optionals (format == "wheel") [ 218 wheelUnpackHook 219 - ] ++ lib.optionals (format == "egg") [ 220 eggUnpackHook eggBuildHook eggInstallHook 221 - ] ++ lib.optionals (format != "other") [( 222 if isBootstrapInstallPackage then 223 pypaInstallHook.override { 224 inherit (python.pythonForBuild.pkgs.bootstrap) installer; ··· 252 doCheck = false; 253 doInstallCheck = attrs.doCheck or true; 254 nativeInstallCheckInputs = [ 255 - ] ++ lib.optionals (format == "setuptools") [ 256 # Longer-term we should get rid of this and require 257 # users of this function to set the `installCheckPhase` or 258 # pass in a hook that sets it.
··· 82 # However, some packages do provide executables with extensions, and thus bytecode is generated. 83 , removeBinBytecode ? true 84 85 + # pyproject = true <-> format = "pyproject" 86 + # pyproject = false <-> format = "other" 87 + # https://github.com/NixOS/nixpkgs/issues/253154 88 + , pyproject ? null 89 + 90 # Several package formats are supported. 91 # "setuptools" : Install a common setuptools/distutils based package. This builds a wheel. 92 # "wheel" : Install from a pre-compiled wheel. ··· 94 # "pyproject": Install a package using a ``pyproject.toml`` file (PEP517). This builds a wheel. 95 # "egg": Install a package from an egg. 96 # "other" : Provide your own buildPhase and installPhase. 97 + , format ? null 98 99 , meta ? {} 100 ··· 106 107 , ... } @ attrs: 108 109 + assert (pyproject != null) -> (format == null); 110 + 111 let 112 inherit (python) stdenv; 113 114 + format' = 115 + if pyproject != null then 116 + if pyproject then 117 + "pyproject" 118 + else 119 + "other" 120 + else if format != null then 121 + format 122 + else 123 + "setuptools"; 124 + 125 + withDistOutput = lib.elem format' ["pyproject" "setuptools" "flit" "wheel"]; 126 127 name_ = name; 128 ··· 195 196 # Keep extra attributes from `attrs`, e.g., `patchPhase', etc. 197 self = toPythonModule (stdenv.mkDerivation ((builtins.removeAttrs attrs [ 198 + "disabled" "checkPhase" "checkInputs" "nativeCheckInputs" "doCheck" "doInstallCheck" "dontWrapPythonPrograms" "catchConflicts" "pyproject" "format" 199 "disabledTestPaths" "outputs" 200 ]) // { 201 ··· 220 pythonRemoveBinBytecodeHook 221 ] ++ lib.optionals (lib.hasSuffix "zip" (attrs.src.name or "")) [ 222 unzip 223 + ] ++ lib.optionals (format' == "setuptools") [ 224 setuptoolsBuildHook 225 + ] ++ lib.optionals (format' == "flit") [ 226 flitBuildHook 227 + ] ++ lib.optionals (format' == "pyproject") [( 228 if isBootstrapPackage then 229 pypaBuildHook.override { 230 inherit (python.pythonForBuild.pkgs.bootstrap) build; ··· 232 } 233 else 234 pypaBuildHook 235 + )] ++ lib.optionals (format' == "wheel") [ 236 wheelUnpackHook 237 + ] ++ lib.optionals (format' == "egg") [ 238 eggUnpackHook eggBuildHook eggInstallHook 239 + ] ++ lib.optionals (format' != "other") [( 240 if isBootstrapInstallPackage then 241 pypaInstallHook.override { 242 inherit (python.pythonForBuild.pkgs.bootstrap) installer; ··· 270 doCheck = false; 271 doInstallCheck = attrs.doCheck or true; 272 nativeInstallCheckInputs = [ 273 + ] ++ lib.optionals (format' == "setuptools") [ 274 # Longer-term we should get rid of this and require 275 # users of this function to set the `installCheckPhase` or 276 # pass in a hook that sets it.
+1 -1
pkgs/development/tools/language-servers/ruff-lsp/default.nix
··· 16 buildPythonPackage rec { 17 pname = "ruff-lsp"; 18 version = "0.0.39"; 19 - format = "pyproject"; 20 disabled = pythonOlder "3.7"; 21 22 src = fetchFromGitHub {
··· 16 buildPythonPackage rec { 17 pname = "ruff-lsp"; 18 version = "0.0.39"; 19 + pyproject = true; 20 disabled = pythonOlder "3.7"; 21 22 src = fetchFromGitHub {
+5 -1
pkgs/tools/package-management/nix-update/default.nix
··· 10 python3.pkgs.buildPythonApplication rec { 11 pname = "nix-update"; 12 version = "0.19.3"; 13 - format = "setuptools"; 14 15 src = fetchFromGitHub { 16 owner = "Mic92"; ··· 18 rev = version; 19 hash = "sha256-+WD+SV/L3TvksWBIg6jk+T0dUTNdp4VKONzdzVT+pac="; 20 }; 21 22 makeWrapperArgs = [ 23 "--prefix" "PATH" ":" (lib.makeBinPath [ nix nix-prefetch-git nixpkgs-fmt nixpkgs-review ])
··· 10 python3.pkgs.buildPythonApplication rec { 11 pname = "nix-update"; 12 version = "0.19.3"; 13 + pyproject = true; 14 15 src = fetchFromGitHub { 16 owner = "Mic92"; ··· 18 rev = version; 19 hash = "sha256-+WD+SV/L3TvksWBIg6jk+T0dUTNdp4VKONzdzVT+pac="; 20 }; 21 + 22 + nativeBuildInputs = [ 23 + python3.pkgs.setuptools 24 + ]; 25 26 makeWrapperArgs = [ 27 "--prefix" "PATH" ":" (lib.makeBinPath [ nix nix-prefetch-git nixpkgs-fmt nixpkgs-review ])