Skip to content

Commit

Permalink
python: Add support for installing Python eggs
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Jan 8, 2020
1 parent 380220c commit 2d6f1ff
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/languages-frameworks/python.section.md
Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions pkgs/development/interpreters/python/hooks/default.nix
Expand Up @@ -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";
Expand Down
15 changes: 15 additions & 0 deletions pkgs/development/interpreters/python/hooks/egg-build-hook.sh
@@ -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
21 changes: 21 additions & 0 deletions pkgs/development/interpreters/python/hooks/egg-install-hook.sh
@@ -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
17 changes: 17 additions & 0 deletions pkgs/development/interpreters/python/hooks/egg-unpack-hook.sh
@@ -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
5 changes: 5 additions & 0 deletions pkgs/development/interpreters/python/mk-python-derivation.nix
Expand Up @@ -20,6 +20,9 @@
, setuptoolsBuildHook
, setuptoolsCheckHook
, wheelUnpackHook
, eggUnpackHook
, eggBuildHook
, eggInstallHook
}:

{ name ? "${attrs.pname}-${attrs.version}"
Expand Down Expand Up @@ -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) [
Expand Down
2 changes: 1 addition & 1 deletion pkgs/top-level/python-packages.nix
Expand Up @@ -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

Expand Down

0 comments on commit 2d6f1ff

Please sign in to comment.