summary refs log tree commit diff
diff options
context:
space:
mode:
authoradisbladis <adisbladis@gmail.com>2020-01-08 13:29:03 +0000
committeradisbladis <adisbladis@gmail.com>2020-01-08 13:59:04 +0000
commit2d6f1ff4dd2ce208fce624466b4eeae54eafd61f (patch)
tree4c10fda6b6e45505f9845ceb80725c63a3ebbd26
parent380220c237d479b81182884afec76e77685e9a36 (diff)
python: Add support for installing Python eggs
-rw-r--r--doc/languages-frameworks/python.section.md3
-rw-r--r--pkgs/development/interpreters/python/hooks/default.nix21
-rw-r--r--pkgs/development/interpreters/python/hooks/egg-build-hook.sh15
-rw-r--r--pkgs/development/interpreters/python/hooks/egg-install-hook.sh21
-rw-r--r--pkgs/development/interpreters/python/hooks/egg-unpack-hook.sh17
-rw-r--r--pkgs/development/interpreters/python/mk-python-derivation.nix5
-rw-r--r--pkgs/top-level/python-packages.nix2
7 files changed, 83 insertions, 1 deletions
diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md
index 9cb0e1eecc168..41a5dae8b9b03 100644
--- a/doc/languages-frameworks/python.section.md
+++ b/doc/languages-frameworks/python.section.md
@@ -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.
diff --git a/pkgs/development/interpreters/python/hooks/default.nix b/pkgs/development/interpreters/python/hooks/default.nix
index 861cb38c06079..f05b3b1eec63e 100644
--- a/pkgs/development/interpreters/python/hooks/default.nix
+++ b/pkgs/development/interpreters/python/hooks/default.nix
@@ -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";
diff --git a/pkgs/development/interpreters/python/hooks/egg-build-hook.sh b/pkgs/development/interpreters/python/hooks/egg-build-hook.sh
new file mode 100644
index 0000000000000..d5abc8d55e5af
--- /dev/null
+++ b/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
diff --git a/pkgs/development/interpreters/python/hooks/egg-install-hook.sh b/pkgs/development/interpreters/python/hooks/egg-install-hook.sh
new file mode 100644
index 0000000000000..ae894fb1bde4b
--- /dev/null
+++ b/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
diff --git a/pkgs/development/interpreters/python/hooks/egg-unpack-hook.sh b/pkgs/development/interpreters/python/hooks/egg-unpack-hook.sh
new file mode 100644
index 0000000000000..c8ed3dee83bae
--- /dev/null
+++ b/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
diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix
index 700894eda6de9..020298cc8e9f7 100644
--- a/pkgs/development/interpreters/python/mk-python-derivation.nix
+++ b/pkgs/development/interpreters/python/mk-python-derivation.nix
@@ -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) [
diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index 4ce723bfa5d07..6215349c2f762 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -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