Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkgs/development/interpreters/python/mk-python-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,12 @@ lib.extendMkDerivation {
optional-dependencies
;
updateScript = nix-update-script { };
# __stdenvPythonCompat[Pos] attributes are here for overrideStdenvCompat in `python-packages-base.nix` to work.
# They are internal and subject to changes.
# TODO(@ShamrockLee): Remove when overrideStdenvCompat gets removed.
${if attrs ? stdenv then "__stdenvPythonCompat" else null} = attrs.stdenv;
${if attrs ? stdenv then "__stdenvPythonCompatPos" else null} =
builtins.unsafeGetAttrPos "stdenv" attrs;
}
// attrs.passthru or { };

Expand Down
27 changes: 16 additions & 11 deletions pkgs/development/interpreters/python/python-packages-base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,29 @@ let
args:
let
result = f args;
getName = x: x.pname or (lib.getName (x.name or "<unnamed>"));
applyMsgStdenvArg =
name:
lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511) ''
${name}: Passing `stdenv` directly to `buildPythonPackage` or `buildPythonApplication` is deprecated. You should use their `.override` function instead, e.g:
buildPythonPackage.override { stdenv = customStdenv; } { }
'';
handleStdenvArg =
attrs: attrName:
let
name = attrs.pname or (lib.getName (attrs.name or "<unnamed>"));
pos = attrs.__stdenvPythonCompatPos or (builtins.unsafeGetAttrPos attrName attrs);
msg = [
"${name}: Passing `stdenv` directly to `buildPythonPackage` or `buildPythonApplication` is deprecated. You should use their `.override` function instead, e.g:"
" buildPythonPackage.override { stdenv = customStdenv; } { }"
]
++ lib.optionals (pos != null) [
"`stdenv` argument found at ${pos.file}:${toString pos.line}"
];
in
lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511) (lib.concatLines msg) attrs.${attrName};
in
if lib.isFunction args && result ? __stdenvPythonCompat then
# Less reliable, as constructing with the wrong `stdenv` might lead to evaluation errors in the package definition.
f'.override { stdenv = applyMsgStdenvArg (getName result) result.__stdenvPythonCompat; } (
f'.override { stdenv = handleStdenvArg result "__stdenvPythonCompat"; } (
finalAttrs: removeAttrs (args finalAttrs) [ "stdenv" ]
)
else if (!lib.isFunction args) && (args ? stdenv) then
# More reliable, but only works when args is not `(finalAttrs: { })`
f'.override { stdenv = applyMsgStdenvArg (getName args) args.stdenv; } (
removeAttrs args [ "stdenv" ]
)
f'.override { stdenv = handleStdenvArg args "stdenv"; } (removeAttrs args [ "stdenv" ])
else
result
)
Expand Down
Loading