makeOverridablePythonPackage: take care of overrideAttrs
Make it possible to mix overridePythonAttrs and overrideAttrs, i.e.
((<pkg>.overrideAttrs (_: { foo = "a"; })).overridePythonAttrs (_: { })).foo now works
Co-authored-by: Matt Sturgeon <matt@sturgeon.me.uk>
This commit is contained in:
co-authored by
Matt Sturgeon
parent
e8302431ef
commit
ca6c090082
@@ -14,6 +14,9 @@ let
|
||||
|
||||
# Derivations built with `buildPythonPackage` can already be overridden with `override`, `overrideAttrs`, and `overrideDerivation`.
|
||||
# This function introduces `overridePythonAttrs` and it overrides the call to `buildPythonPackage`.
|
||||
#
|
||||
# Overridings specified through `overridePythonAttrs` will always be applied
|
||||
# before those specified by `overrideAttrs`, even if invoked after them.
|
||||
makeOverridablePythonPackage =
|
||||
f:
|
||||
lib.mirrorFunctionArgs f (
|
||||
@@ -26,6 +29,8 @@ let
|
||||
result
|
||||
// {
|
||||
overridePythonAttrs = newArgs: makeOverridablePythonPackage f (overrideWith newArgs);
|
||||
overrideAttrs =
|
||||
newArgs: makeOverridablePythonPackage (args: (f args).overrideAttrs newArgs) origArgs;
|
||||
}
|
||||
else
|
||||
result
|
||||
|
||||
@@ -407,6 +407,14 @@ let
|
||||
p.overridePythonAttrs (previousAttrs: {
|
||||
overridePythonAttrsFlag = previousAttrs.overridePythonAttrsFlag or 0 + 1;
|
||||
});
|
||||
overrideAttrsFooBar =
|
||||
drv:
|
||||
drv.overrideAttrs (
|
||||
finalAttrs: previousAttrs: {
|
||||
FOO = "a";
|
||||
BAR = finalAttrs.FOO;
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
overridePythonAttrs = {
|
||||
@@ -418,6 +426,37 @@ let
|
||||
(applyOverridePythonAttrs (applyOverridePythonAttrs python-package-stub)).overridePythonAttrsFlag;
|
||||
expected = 2;
|
||||
};
|
||||
overrideAttrs-overridePythonAttrs-test-overrideAttrs = {
|
||||
expr = {
|
||||
inherit (applyOverridePythonAttrs (overrideAttrsFooBar python-package-stub))
|
||||
FOO
|
||||
BAR
|
||||
;
|
||||
};
|
||||
expected = {
|
||||
FOO = "a";
|
||||
BAR = "a";
|
||||
};
|
||||
};
|
||||
overrideAttrs-overridePythonAttrs-test-overridePythonAttrs = {
|
||||
expr =
|
||||
(applyOverridePythonAttrs (overrideAttrsFooBar python-package-stub)) ? overridePythonAttrsFlag;
|
||||
expected = true;
|
||||
};
|
||||
overrideAttrs-overridePythonAttrs-test-commutation = {
|
||||
expr = overrideAttrsFooBar (applyOverridePythonAttrs python-package-stub);
|
||||
expected = applyOverridePythonAttrs (overrideAttrsFooBar python-package-stub);
|
||||
};
|
||||
chain-of-overrides = rec {
|
||||
expr = lib.pipe python-package-stub [
|
||||
(p: p.overrideAttrs { inherit (expected) a; })
|
||||
(p: p.overridePythonAttrs { inherit (expected) b; })
|
||||
(p: p.overrideAttrs { inherit (expected) c; })
|
||||
(p: p.overridePythonAttrs { inherit (expected) d; })
|
||||
(builtins.intersectAttrs expected)
|
||||
];
|
||||
expected = lib.genAttrs [ "a" "b" "c" "d" ] lib.id;
|
||||
};
|
||||
};
|
||||
|
||||
in
|
||||
|
||||
Reference in New Issue
Block a user