Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function _pytestIncludeExcludeExpr() {

function pytestCheckPhase() {
echo "Executing pytestCheckPhase"
runHook preCheck
runHook preInstallCheck

# Compose arguments
local -a flagsArray=(-m pytest)
Expand Down Expand Up @@ -90,11 +90,11 @@ EOF
echoCmd 'pytest flags' "${flagsArray[@]}"
@pythonCheckInterpreter@ "${flagsArray[@]}"

runHook postCheck
runHook postInstallCheck
echo "Finished executing pytestCheckPhase"
}

if [ -z "${dontUsePytestCheck-}" ] && [ -z "${installCheckPhase-}" ]; then
echo "Using pytestCheckPhase"
appendToVar preDistPhases pytestCheckPhase
installCheckPhase=pytestCheckPhase
fi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ echo "Sourcing unittest-check-hook"

unittestCheckPhase() {
echo "Executing unittestCheckPhase"
runHook preCheck
runHook preInstallCheck

local -a flagsArray=()

Expand All @@ -16,11 +16,11 @@ unittestCheckPhase() {
echoCmd 'unittest flags' "${flagsArray[@]}"
@pythonCheckInterpreter@ -m unittest discover "${flagsArray[@]}"

runHook postCheck
runHook postInstallCheck
echo "Finished executing unittestCheckPhase"
}

if [[ -z "${dontUseUnittestCheck-}" ]] && [[ -z "${installCheckPhase-}" ]]; then
echo "Using unittestCheckPhase"
appendToVar preDistPhases unittestCheckPhase
installCheckPhase=unittestCheckPhase
fi
35 changes: 19 additions & 16 deletions pkgs/development/interpreters/python/mk-python-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ let
cleanAttrs = flip removeAttrs [
"disabled"
"checkPhase"
"preCheck"
"postCheck"
"checkInputs"
"nativeCheckInputs"
"doCheck"
"doInstallCheck"
"pyproject"
"format"
"stdenv"
Expand All @@ -123,10 +124,10 @@ in
# Run-time dependencies for the package
buildInputs ? [ ],

# Dependencies needed for running the checkPhase.
# These are added to buildInputs when doCheck = true.
checkInputs ? [ ],
nativeCheckInputs ? [ ],
# Dependencies needed for running the installCheckPhase.
# These are added to buildInputs when doInstallCheck = true.
installCheckInputs ? [ ],
nativeInstallCheckInputs ? [ ],

# propagate build dependencies so in case we have A -> B -> C,
# C can import package A propagated by B
Expand Down Expand Up @@ -192,7 +193,7 @@ in

meta ? { },

doCheck ? true,
doInstallCheck ? true,

...
}@attrs:
Expand Down Expand Up @@ -358,7 +359,7 @@ let
)
]
++ optionals (stdenv.buildPlatform == stdenv.hostPlatform) [
# This is a test, however, it should be ran independent of the checkPhase and checkInputs
# This is a test, however, it should be ran independent of the installCheckPhase and installCheckInputs
pythonImportsCheckHook
]
++ optionals (python.pythonAtLeast "3.3") [
Expand Down Expand Up @@ -388,11 +389,11 @@ let

LANG = "${if python.stdenv.hostPlatform.isDarwin then "en_US" else "C"}.UTF-8";

# Python packages don't have a checkPhase, only an installCheckPhase
# Python packages don't have a installCheckPhase, only an installCheckPhase
doCheck = false;
doInstallCheck = attrs.doCheck or true;
nativeInstallCheckInputs = nativeCheckInputs ++ attrs.nativeInstallCheckInputs or [ ];
installCheckInputs = checkInputs ++ attrs.installCheckInputs or [ ];
inherit doInstallCheck;
inherit nativeInstallCheckInputs;
inherit installCheckInputs;

inherit dontWrapPythonPrograms;

Expand Down Expand Up @@ -430,11 +431,13 @@ let
}
// meta;
}
// optionalAttrs (attrs ? checkPhase) {
# If given use the specified checkPhase, otherwise use the setup hook.
# Longer-term we should get rid of `checkPhase` and use `installCheckPhase`.
installCheckPhase = attrs.checkPhase;
}
# If given use the specified installCheckPhase, otherwise use the setup hook.
# Longer-term we should get rid of `checkPhase` and use `installCheckPhase`.
// getOptionalAttrs [
"installCheckPhase"
"preInstallCheck"
"postInstallCheck"
] attrs
//
lib.mapAttrs
(
Expand Down
80 changes: 77 additions & 3 deletions pkgs/development/interpreters/python/python-packages-base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,76 @@
python,
}:

let
getOptionalAttrs =
names: attrs: lib.getAttrs (lib.intersectLists names (lib.attrNames attrs)) attrs;

getInstallCheckPhaseArgs =
args:
lib.mapAttrs'
(name: value: {
name = lib.replaceString "Check" "InstallCheck" name;
inherit value;
})
(
getOptionalAttrs [
"doCheck"
"preCheck"
"postCheck"
] args
)
// getOptionalAttrs [
"doInstallCheck"
"preInstallCheck"
"postInstallCheck"
] args
// {
nativeInstallCheckInputs = args.nativeCheckInputs or [ ] ++ args.nativeInstallCheckInputs or [ ];
installCheckInputs = args.checkInputs or [ ] ++ args.installCheckInputs or [ ];
}
// lib.optionalAttrs (args ? installCheckPhase || args ? checkPhase) {
installCheckPhase =
lib.replaceStrings
[ "runHook preCheck\n" "runHook postCheck\n" ]
[ "runHook preInstallCheck\n" "runHook postInstallCheck\n" ]
(args.installCheckPhase or args.checkPhase);
};

getCheckPhaseArgs =
args:
lib.mapAttrs'
(name: value: {
name = lib.replaceString "Install" "" name;
inherit value;
})
(
getOptionalAttrs [
"doInstallCheck"
"nativeInstallCheckInputs"
"preInstallCheck"
"postInstallCheck"
] args
)
// lib.optionalAttrs (args ? installCheckInputs) {
checkInputs = args.installCheckInputs;
}
// lib.optionalAttrs (args ? installCheckPhase) {
checkPhase =
lib.replaceStrings
[ "runHook preInstallCheck\n" "runHook postInstallCheck\n" ]
[ "runHook preCheck\n" "runHook postCheck\n" ]
args.installCheckPhase;
};

getOutArgs =
args:
let
outArgsInstallCheck = getInstallCheckPhaseArgs args;
outArgsCheck = getCheckPhaseArgs outArgsInstallCheck;
in
removeAttrs args (lib.attrNames outArgsCheck) // outArgsInstallCheck;
in

self:

let
Expand All @@ -22,15 +92,19 @@ let
lib.mirrorFunctionArgs f (
origArgs:
let
result = f origArgs;
overrideWith = newArgs: origArgs // lib.toFunction newArgs origArgs;
installCheckPhaseArgsOrig = getInstallCheckPhaseArgs origArgs;
checkPhaseArgsOrig = getCheckPhaseArgs installCheckPhaseArgsOrig;
inArgs = origArgs // checkPhaseArgsOrig // installCheckPhaseArgsOrig;

result = f (getOutArgs origArgs);
overrideWith = newArgs: getOutArgs origArgs // getOutArgs (lib.toFunction newArgs inArgs);
in
if lib.isAttrs result then
result
// {
overridePythonAttrs = newArgs: makeOverridablePythonPackage f (overrideWith newArgs);
overrideAttrs =
newArgs: makeOverridablePythonPackage (args: (f args).overrideAttrs newArgs) origArgs;
newArgs: makeOverridablePythonPackage (args: (f (getOutArgs args)).overrideAttrs newArgs) origArgs;
}
else
result
Expand Down
Loading