python: Add support for installing Python eggs

Changed files
+83 -1
doc
languages-frameworks
pkgs
+3
doc/languages-frameworks/python.section.md
···
The following are setup hooks specifically for Python packages. Most of these are
used in `buildPythonPackage`.
- `flitBuildHook` to build a wheel using `flit`.
- `pipBuildHook` to build a wheel using `pip` and PEP 517. Note a build system (e.g. `setuptools` or `flit`) should still be added as `nativeBuildInput`.
- `pipInstallHook` to install wheels.
···
The following are setup hooks specifically for Python packages. Most of these are
used in `buildPythonPackage`.
+
- `eggUnpackhook` to move an egg to the correct folder so it can be installed with the `eggInstallHook`
+
- `eggBuildHook` to skip building for eggs.
+
- `eggInstallHook` to install eggs.
- `flitBuildHook` to build a wheel using `flit`.
- `pipBuildHook` to build a wheel using `pip` and PEP 517. Note a build system (e.g. `setuptools` or `flit`) should still be added as `nativeBuildInput`.
- `pipInstallHook` to install wheels.
+21
pkgs/development/interpreters/python/hooks/default.nix
···
setuppy = ../run_setup.py;
in rec {
flitBuildHook = callPackage ({ flit }:
makeSetupHook {
name = "flit-build-hook";
···
setuppy = ../run_setup.py;
in rec {
+
eggBuildHook = callPackage ({ }:
+
makeSetupHook {
+
name = "egg-build-hook.sh";
+
deps = [ ];
+
} ./egg-build-hook.sh) {};
+
+
eggInstallHook = callPackage ({ setuptools }:
+
makeSetupHook {
+
name = "egg-install-hook.sh";
+
deps = [ setuptools ];
+
substitutions = {
+
inherit pythonInterpreter pythonSitePackages;
+
};
+
} ./egg-install-hook.sh) {};
+
+
eggUnpackHook = callPackage ({ }:
+
makeSetupHook {
+
name = "egg-unpack-hook.sh";
+
deps = [ ];
+
} ./egg-unpack-hook.sh) {};
+
flitBuildHook = callPackage ({ flit }:
makeSetupHook {
name = "flit-build-hook";
+15
pkgs/development/interpreters/python/hooks/egg-build-hook.sh
···
···
+
# Setup hook to use for eggs
+
echo "Sourcing egg-build-hook"
+
+
eggBuildPhase() {
+
echo "Executing eggBuildPhase"
+
runHook preBuild
+
+
runHook postBuild
+
echo "Finished executing eggBuildPhase"
+
}
+
+
if [ -z "${dontUseEggBuild-}" ] && [ -z "${buildPhase-}" ]; then
+
echo "Using eggBuildPhase"
+
buildPhase=eggBuildPhase
+
fi
+21
pkgs/development/interpreters/python/hooks/egg-install-hook.sh
···
···
+
# Setup hook for eggs
+
echo "Sourcing egg-install-hook"
+
+
eggInstallPhase() {
+
echo "Executing eggInstallPhase"
+
runHook preInstall
+
+
mkdir -p "$out/@pythonSitePackages@"
+
export PYTHONPATH="$out/@pythonSitePackages@:$PYTHONPATH"
+
+
find
+
@pythonInterpreter@ -m easy_install --prefix="$out" *.egg
+
+
runHook postInstall
+
echo "Finished executing eggInstallPhase"
+
}
+
+
if [ -z "${dontUseEggInstall-}" ] && [ -z "${installPhase-}" ]; then
+
echo "Using eggInstallPhase"
+
installPhase=eggInstallPhase
+
fi
+17
pkgs/development/interpreters/python/hooks/egg-unpack-hook.sh
···
···
+
# Setup hook to use in case an egg is fetched
+
echo "Sourcing egg setup hook"
+
+
eggUnpackPhase(){
+
echo "Executing eggUnpackPhase"
+
runHook preUnpack
+
+
cp "$src" "$(stripHash "$src")"
+
+
# runHook postUnpack # Calls find...?
+
echo "Finished executing eggUnpackPhase"
+
}
+
+
if [ -z "${dontUseEggUnpack-}" ] && [ -z "${unpackPhase-}" ]; then
+
echo "Using eggUnpackPhase"
+
unpackPhase=eggUnpackPhase
+
fi
+5
pkgs/development/interpreters/python/mk-python-derivation.nix
···
, setuptoolsBuildHook
, setuptoolsCheckHook
, wheelUnpackHook
}:
{ name ? "${attrs.pname}-${attrs.version}"
···
pipBuildHook
] ++ lib.optionals (format == "wheel") [
wheelUnpackHook
] ++ lib.optionals (!(format == "other") || dontUsePipInstall) [
pipInstallHook
] ++ lib.optionals (stdenv.buildPlatform == stdenv.hostPlatform) [
···
, setuptoolsBuildHook
, setuptoolsCheckHook
, wheelUnpackHook
+
, eggUnpackHook
+
, eggBuildHook
+
, eggInstallHook
}:
{ name ? "${attrs.pname}-${attrs.version}"
···
pipBuildHook
] ++ lib.optionals (format == "wheel") [
wheelUnpackHook
+
] ++ lib.optionals (format == "egg") [
+
eggUnpackHook eggBuildHook eggInstallHook
] ++ lib.optionals (!(format == "other") || dontUsePipInstall) [
pipInstallHook
] ++ lib.optionals (stdenv.buildPlatform == stdenv.hostPlatform) [
+1 -1
pkgs/top-level/python-packages.nix
···
inherit buildSetupcfg;
inherit (callPackage ../development/interpreters/python/hooks { })
-
flitBuildHook pipBuildHook pipInstallHook pytestCheckHook pythonCatchConflictsHook pythonImportsCheckHook pythonRemoveBinBytecodeHook setuptoolsBuildHook setuptoolsCheckHook wheelUnpackHook;
# helpers
···
inherit buildSetupcfg;
inherit (callPackage ../development/interpreters/python/hooks { })
+
eggUnpackHook eggBuildHook eggInstallHook flitBuildHook pipBuildHook pipInstallHook pytestCheckHook pythonCatchConflictsHook pythonImportsCheckHook pythonRemoveBinBytecodeHook setuptoolsBuildHook setuptoolsCheckHook wheelUnpackHook;
# helpers