diff --git a/pkgs/development/interpreters/python/hooks/pytest-check-hook.sh b/pkgs/development/interpreters/python/hooks/pytest-check-hook.sh index 84643a3b50ca7..274059483a7ae 100644 --- a/pkgs/development/interpreters/python/hooks/pytest-check-hook.sh +++ b/pkgs/development/interpreters/python/hooks/pytest-check-hook.sh @@ -22,7 +22,7 @@ function _pytestIncludeExcludeExpr() { function pytestCheckPhase() { echo "Executing pytestCheckPhase" - runHook preCheck + runHook preInstallCheck # Compose arguments local -a flagsArray=(-m pytest) @@ -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 diff --git a/pkgs/development/interpreters/python/hooks/unittest-check-hook.sh b/pkgs/development/interpreters/python/hooks/unittest-check-hook.sh index 3ee947e278e66..897df721d2cfe 100644 --- a/pkgs/development/interpreters/python/hooks/unittest-check-hook.sh +++ b/pkgs/development/interpreters/python/hooks/unittest-check-hook.sh @@ -5,7 +5,7 @@ echo "Sourcing unittest-check-hook" unittestCheckPhase() { echo "Executing unittestCheckPhase" - runHook preCheck + runHook preInstallCheck local -a flagsArray=() @@ -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 diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index 04deb32b6a3a4..56b8e54e30d11 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -102,10 +102,11 @@ let cleanAttrs = flip removeAttrs [ "disabled" "checkPhase" + "preCheck" + "postCheck" "checkInputs" "nativeCheckInputs" "doCheck" - "doInstallCheck" "pyproject" "format" "stdenv" @@ -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 @@ -192,7 +193,7 @@ in meta ? { }, - doCheck ? true, + doInstallCheck ? true, ... }@attrs: @@ -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") [ @@ -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; @@ -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 ( diff --git a/pkgs/development/interpreters/python/python-packages-base.nix b/pkgs/development/interpreters/python/python-packages-base.nix index 97ec3f5076f20..757afdd4d4a95 100644 --- a/pkgs/development/interpreters/python/python-packages-base.nix +++ b/pkgs/development/interpreters/python/python-packages-base.nix @@ -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 @@ -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