python: Add support for installing Python eggs

This commit is contained in:
adisbladis 2020-01-08 13:29:03 +00:00
parent 380220c237
commit 2d6f1ff4dd
No known key found for this signature in database
GPG Key ID: 110BFAD44C6249B7
7 changed files with 83 additions and 1 deletions

View File

@ -821,6 +821,9 @@ should be used with `ignoreCollisions = true`.
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.

View File

@ -11,6 +11,27 @@ let
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";

View File

@ -0,0 +1,15 @@
# 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

View File

@ -0,0 +1,21 @@
# 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

View File

@ -0,0 +1,17 @@
# 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

View File

@ -20,6 +20,9 @@
, setuptoolsBuildHook
, setuptoolsCheckHook
, wheelUnpackHook
, eggUnpackHook
, eggBuildHook
, eggInstallHook
}:
{ name ? "${attrs.pname}-${attrs.version}"
@ -119,6 +122,8 @@ let
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) [

View File

@ -108,7 +108,7 @@ in {
inherit buildSetupcfg;
inherit (callPackage ../development/interpreters/python/hooks { })
flitBuildHook pipBuildHook pipInstallHook pytestCheckHook pythonCatchConflictsHook pythonImportsCheckHook pythonRemoveBinBytecodeHook setuptoolsBuildHook setuptoolsCheckHook wheelUnpackHook;
eggUnpackHook eggBuildHook eggInstallHook flitBuildHook pipBuildHook pipInstallHook pytestCheckHook pythonCatchConflictsHook pythonImportsCheckHook pythonRemoveBinBytecodeHook setuptoolsBuildHook setuptoolsCheckHook wheelUnpackHook;
# helpers