Merge pull request #254136 from figsoda/python

python310Packages.buildPythonPackage: introduce pyproject option

Changed files
+103 -31
doc
languages-frameworks
pkgs
applications
networking
seahub
development
interpreters
tools
language-servers
ruff-lsp
tools
package-management
nix-update
+68 -18
doc/languages-frameworks/python.section.md
···
buildPythonPackage rec {
pname = "pytest";
version = "3.3.1";
-
format = "setuptools";
+
pyproject = true;
src = fetchPypi {
inherit pname version;
···
* `dontWrapPythonPrograms ? false`: Skip wrapping of Python programs.
* `permitUserSite ? false`: Skip setting the `PYTHONNOUSERSITE` environment
variable in wrapped programs.
-
* `format ? "setuptools"`: Format of the source. Valid options are
-
`"setuptools"`, `"pyproject"`, `"flit"`, `"wheel"`, and `"other"`.
-
`"setuptools"` is for when the source has a `setup.py` and `setuptools` is
-
used to build a wheel, `flit`, in case `flit` should be used to build a wheel,
-
and `wheel` in case a wheel is provided. Use `other` when a custom
-
`buildPhase` and/or `installPhase` is needed.
+
* `pyproject`: Whether the pyproject format should be used. When set to `true`,
+
`pypaBuildHook` will be used, and you can add the required build dependencies
+
from `build-system.requires` to `nativeBuildInputs`. Note that the pyproject
+
format falls back to using `setuptools`, so you can use `pyproject = true`
+
even if the package only has a `setup.py`. When set to `false`, you can
+
use the existing [hooks](#setup-hooks0 or provide your own logic to build the
+
package. This can be useful for packages that don't support the pyproject
+
format. When unset, the legacy `setuptools` hooks are used for backwards
+
compatibility.
* `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
···
python3.pkgs.buildPythonApplication rec {
pname = "luigi";
version = "2.7.9";
-
format = "setuptools";
+
pyproject = true;
src = fetchPypi {
inherit pname version;
hash = "sha256-Pe229rT0aHwA98s+nTHQMEFKZPo/yw6sot8MivFDvAw=";
};
+
nativeBuildInputs = [
+
python3.pkgs.setuptools
+
python3.pkgs.wheel
+
];
+
propagatedBuildInputs = with python3.pkgs; [
tornado
python-daemon
];
meta = with lib; {
-
...
+
# ...
};
}
```
···
{ lib
, buildPythonPackage
, fetchPypi
+
, setuptools
+
, wheel
}:
buildPythonPackage rec {
pname = "toolz";
version = "0.10.0";
-
format = "setuptools";
+
pyproject = true;
src = fetchPypi {
inherit pname version;
hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA=";
};
+
+
nativeBuildInputs = [
+
setuptools
+
wheel
+
];
# has no tests
doCheck = false;
···
my_toolz = python311.pkgs.buildPythonPackage rec {
pname = "toolz";
version = "0.10.0";
-
format = "setuptools";
+
pyproject = true;
src = fetchPypi {
inherit pname version;
hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA=";
};
+
+
nativeBuildInputs = [
+
python311.pkgs.setuptools
+
python311.pkgs.wheel
+
];
# has no tests
doCheck = false;
···
, buildPythonPackage
, fetchPypi
+
# build dependencies
+
, setuptools, wheel
+
# dependencies
, numpy, multipledispatch, python-dateutil
···
buildPythonPackage rec {
pname = "datashape";
version = "0.4.7";
-
format = "setuptools";
+
pyproject = true;
src = fetchPypi {
inherit pname version;
hash = "sha256-FLLvdm1MllKrgTGC6Gb0k0deZeVYvtCCLji/B7uhong=";
};
+
+
nativeBuildInputs = [
+
setuptools
+
wheel
+
];
propagatedBuildInputs = [
multipledispatch
···
{ lib
, buildPythonPackage
, fetchPypi
+
, setuptools
+
, wheel
, libxml2
, libxslt
}:
···
buildPythonPackage rec {
pname = "lxml";
version = "3.4.4";
-
format = "setuptools";
+
pyproject = true;
src = fetchPypi {
inherit pname version;
hash = "sha256-s9NiusRxFydHzaNRMjjxFcvWxfi45jGb9ql6eJJyQJk=";
};
+
+
nativeBuildInputs = [
+
setuptools
+
wheel
+
];
buildInputs = [
libxml2
···
{ lib
, buildPythonPackage
, fetchPypi
+
+
# build dependencies
+
, setuptools
+
, wheel
# dependencies
, fftw
···
buildPythonPackage rec {
pname = "pyFFTW";
version = "0.9.2";
-
format = "setuptools";
+
pyproject = true;
src = fetchPypi {
inherit pname version;
hash = "sha256-9ru2r6kwhUCaskiFoaPNuJCfCVoUL01J40byvRt4kHQ=";
};
+
+
nativeBuildInputs = [
+
setuptools
+
wheel
+
];
buildInputs = [
fftw
···
Keep in mind that while the examples above are done with `requirements.txt`,
`pythonRelaxDepsHook` works by modifying the resulting wheel file, so it should
-
work in any of the formats supported by `buildPythonPackage` currently,
-
with the exception of `other` (see `format` in
-
[`buildPythonPackage` parameters](#buildpythonpackage-parameters) for more details).
+
work with any of the existing [hooks](#setup-hooks).
#### Using unittestCheckHook {#using-unittestcheckhook}
···
```nix
{ lib
, buildPythonPackage
+
, fetchPypi
+
, setuptools
+
, wheel
}:
buildPythonPackage rec {
pname = "toolz";
version = "0.10.0";
-
format = "setuptools";
+
pyproject = true;
src = fetchPypi {
inherit pname version;
hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA=";
};
+
+
nativeBuildInputs = [
+
setuptools
+
wheel
+
];
meta = with lib; {
changelog = "https://github.com/pytoolz/toolz/releases/tag/${version}";
+1 -1
pkgs/applications/networking/seahub/default.nix
···
python.pkgs.buildPythonApplication rec {
pname = "seahub";
version = "9.0.10";
-
format = "other";
+
pyproject = false;
src = fetchFromGitHub {
owner = "haiwen";
+28 -10
pkgs/development/interpreters/python/mk-python-derivation.nix
···
# 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.
···
# "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 ? {}
···
, ... } @ 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;
···
# 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"
]) // {
···
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;
···
}
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;
···
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.
+1 -1
pkgs/development/tools/language-servers/ruff-lsp/default.nix
···
buildPythonPackage rec {
pname = "ruff-lsp";
version = "0.0.39";
-
format = "pyproject";
+
pyproject = true;
disabled = pythonOlder "3.7";
src = fetchFromGitHub {
+5 -1
pkgs/tools/package-management/nix-update/default.nix
···
python3.pkgs.buildPythonApplication rec {
pname = "nix-update";
version = "0.19.3";
-
format = "setuptools";
+
pyproject = true;
src = fetchFromGitHub {
owner = "Mic92";
···
rev = version;
hash = "sha256-+WD+SV/L3TvksWBIg6jk+T0dUTNdp4VKONzdzVT+pac=";
};
+
+
nativeBuildInputs = [
+
python3.pkgs.setuptools
+
];
makeWrapperArgs = [
"--prefix" "PATH" ":" (lib.makeBinPath [ nix nix-prefetch-git nixpkgs-fmt nixpkgs-review ])