diff --git a/pkgs/development/interpreters/python/hooks/default.nix b/pkgs/development/interpreters/python/hooks/default.nix index 46b01999f96c..e241bef042d5 100644 --- a/pkgs/development/interpreters/python/hooks/default.nix +++ b/pkgs/development/interpreters/python/hooks/default.nix @@ -1,7 +1,8 @@ self: dontUse: with self; let - pythonInterpreter = python.pythonForBuild.interpreter; + inherit (python) pythonForBuild; + pythonInterpreter = pythonForBuild.interpreter; pythonSitePackages = python.sitePackages; pythonCheckInterpreter = python.interpreter; setuppy = ../run_setup.py; @@ -81,6 +82,17 @@ in { }; } ./pip-install-hook.sh) {}; + pypaInstallHook = callPackage ({ makePythonHook, installer }: + makePythonHook { + name = "pypa-install-hook"; + propagatedBuildInputs = [ installer ]; + substitutions = { + inherit pythonInterpreter pythonSitePackages; + }; + } ./pypa-install-hook.sh) { + inherit (pythonForBuild.pkgs) installer; + }; + pytestCheckHook = callPackage ({ makePythonHook, pytest }: makePythonHook { name = "pytest-check-hook"; diff --git a/pkgs/development/interpreters/python/hooks/pypa-install-hook.sh b/pkgs/development/interpreters/python/hooks/pypa-install-hook.sh new file mode 100644 index 000000000000..1a7b30116904 --- /dev/null +++ b/pkgs/development/interpreters/python/hooks/pypa-install-hook.sh @@ -0,0 +1,21 @@ +# Setup hook for PyPA installer. +echo "Sourcing pypa-install-hook" + +pypaInstallPhase() { + echo "Executing pypaInstallPhase" + runHook preInstall + + for wheel in dist/*.whl; do + @pythonInterpreter@ -m installer --prefix "$out" "$wheel" + done + + export PYTHONPATH="$out/@pythonSitePackages@:$PYTHONPATH" + + runHook postInstall + echo "Finished executing pypaInstallPhase" +} + +if [ -z "${dontUsePypaInstall-}" ] && [ -z "${installPhase-}" ]; then + echo "Using pypaInstallPhase" + installPhase=pypaInstallPhase +fi