buildPython*: simplify overrideStdenvCompat and add nested-override support (#455764)

This commit is contained in:
Yueh-Shun Li
2025-12-12 08:09:28 +00:00
committed by GitHub
2 changed files with 27 additions and 15 deletions
@@ -38,25 +38,30 @@ let
// {
# Support overriding `f` itself, e.g. `buildPythonPackage.override { }`.
# Ensure `makeOverridablePythonPackage` is applied to the result.
override = lib.mirrorFunctionArgs f.override (fdrv: makeOverridablePythonPackage (f.override fdrv));
override = lib.mirrorFunctionArgs f.override (
newArgs: makeOverridablePythonPackage (f.override newArgs)
);
};
overrideStdenvCompat =
f:
lib.setFunctionArgs (
args:
if !(lib.isFunction args) && (args ? stdenv) then
lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511) ''
Passing `stdenv` directly to `buildPythonPackage` or `buildPythonApplication` is deprecated. You should use their `.override` function instead, e.g:
buildPythonPackage.override { stdenv = customStdenv; } { }
'' (f.override { stdenv = args.stdenv; } args)
else
f args
) (removeAttrs (lib.functionArgs f) [ "stdenv" ])
// {
# Intentionally drop the effect of overrideStdenvCompat when calling `buildPython*.override`.
inherit (f) override;
};
lib.fix (
f':
lib.mirrorFunctionArgs f (
args:
if !(lib.isFunction args) && (args ? stdenv) then
lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511) ''
Passing `stdenv` directly to `buildPythonPackage` or `buildPythonApplication` is deprecated. You should use their `.override` function instead, e.g:
buildPythonPackage.override { stdenv = customStdenv; } { }
'' (f'.override { inherit (args) stdenv; } (removeAttrs args [ "stdenv" ]))
else
f args
)
// {
# Preserve the effect of overrideStdenvCompat when calling `buildPython*.override`.
override = lib.mirrorFunctionArgs f.override (newArgs: overrideStdenvCompat (f.override newArgs));
}
);
mkPythonDerivation =
if python.isPy3k then ./mk-python-derivation.nix else ./python2/mk-python-derivation.nix;
+7
View File
@@ -453,6 +453,13 @@ let
})).stdenv;
expected = pkgs.clangStdenv;
};
overridePythonAttrs-override-clangStdenv-deprecated-nested = {
expr =
(package-stub-gcc.overridePythonAttrs {
stdenv = pkgs.clangStdenv;
}).stdenv;
expected = pkgs.clangStdenv;
};
overridePythonAttrs = {
expr = (applyOverridePythonAttrs package-stub).overridePythonAttrsFlag;