From a3349304909aee736bc9a9ad1c35d698a27df23d Mon Sep 17 00:00:00 2001 From: Frederik Rietdijk Date: Sun, 10 Dec 2017 14:20:38 +0100 Subject: [PATCH 1/3] Python: rewrite requiredPythonModules. Add requiredPythonModules attribute to derivation --- .../interpreters/python/build-python-package.nix | 4 ++-- .../interpreters/python/mk-python-derivation.nix | 11 +++-------- pkgs/top-level/python-packages.nix | 14 ++++++-------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/pkgs/development/interpreters/python/build-python-package.nix b/pkgs/development/interpreters/python/build-python-package.nix index 982542c1fc3e..12d17b2e8322 100644 --- a/pkgs/development/interpreters/python/build-python-package.nix +++ b/pkgs/development/interpreters/python/build-python-package.nix @@ -7,7 +7,7 @@ , setuptools , unzip , ensureNewerSourcesHook -, pythonModule +, toPythonModule , namePrefix , bootstrapped-pip , flit @@ -19,7 +19,7 @@ let wheel-specific = import ./build-python-package-wheel.nix { }; common = import ./build-python-package-common.nix { inherit python bootstrapped-pip; }; mkPythonDerivation = import ./mk-python-derivation.nix { - inherit lib python wrapPython setuptools unzip ensureNewerSourcesHook pythonModule namePrefix; + inherit lib python wrapPython setuptools unzip ensureNewerSourcesHook toPythonModule namePrefix; }; in diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index a0cac7d1ddda..b92167ce42d6 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -7,7 +7,7 @@ , unzip , ensureNewerSourcesHook # Whether the derivation provides a Python module or not. -, pythonModule +, toPythonModule , namePrefix }: @@ -54,7 +54,7 @@ if disabled then throw "${name} not supported for interpreter ${python.executable}" else -python.stdenv.mkDerivation (builtins.removeAttrs attrs [ +toPythonModule (python.stdenv.mkDerivation (builtins.removeAttrs attrs [ "disabled" "checkInputs" "doCheck" "doInstallCheck" "dontWrapPythonPrograms" "catchConflicts" ] // { @@ -84,14 +84,9 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs [ ${python.interpreter} ${./catch_conflicts}/catch_conflicts.py '' + attrs.postFixup or ''''; - passthru = { - inherit python; # The python interpreter - inherit pythonModule; - } // passthru; - meta = { # default to python's platforms platforms = python.meta.platforms; isBuildPythonPackage = python.meta.platforms; } // meta; -}) +})) diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index b4e4e274893e..7068ccedb73a 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -56,14 +56,14 @@ let flit = self.flit; # We want Python libraries to be named like e.g. "python3.6-${name}" inherit namePrefix; - pythonModule = python; + inherit toPythonModule; })); buildPythonApplication = makeOverridablePythonPackage ( makeOverridable (callPackage ../development/interpreters/python/build-python-package.nix { inherit bootstrapped-pip; flit = self.flit; namePrefix = ""; - pythonModule = false; + toPythonModule = x: x; # Application does not provide modules. })); graphiteVersion = "1.0.2"; @@ -91,11 +91,9 @@ let # Get list of required Python modules given a list of derivations. requiredPythonModules = drvs: let - filterNull = list: filter (x: !isNull x) list; - conditionalGetRecurse = attr: condition: drv: let f = conditionalGetRecurse attr condition; in - (if (condition drv) then unique [drv]++(concatMap f (filterNull(getAttr attr drv))) else []); - _required = drv: conditionalGetRecurse "propagatedBuildInputs" hasPythonModule drv; - in [python] ++ (unique (concatMap _required (filterNull drvs))); + removeNull = list: filter (x: !isNull x) list; + modules = filter hasPythonModule (removeNull drvs); + in unique ([python] ++ modules ++ concatLists (catAttrs "requiredPythonModules" modules)); # Create a PYTHONPATH from a list of derivations. This function recurses into the items to find derivations # providing Python modules. @@ -106,9 +104,9 @@ let drv.overrideAttrs( oldAttrs: { # Use passthru in order to prevent rebuilds when possible. passthru = (oldAttrs.passthru or {})// { - name = namePrefix + oldAttrs.name; pythonModule = python; pythonPath = [ ]; # Deprecated, for compatibility. + requiredPythonModules = requiredPythonModules drv.propagatedBuildInputs; }; }); From 9630bd52323e335c422d4da208590abb535fda43 Mon Sep 17 00:00:00 2001 From: Frederik Rietdijk Date: Sun, 10 Dec 2017 14:20:52 +0100 Subject: [PATCH 2/3] python.pkgs.setuptools: mark as python module --- pkgs/top-level/python-packages.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 7068ccedb73a..d164b80279bb 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -127,7 +127,7 @@ in { recursivePthLoader = callPackage ../development/python-modules/recursive-pth-loader { }; - setuptools = callPackage ../development/python-modules/setuptools { }; + setuptools = toPythonModule (callPackage ../development/python-modules/setuptools { }); vowpalwabbit = callPackage ../development/python-modules/vowpalwabbit { pythonPackages = self; From c86b19cb20f68e6b65af6ac884940ea125e4a8f8 Mon Sep 17 00:00:00 2001 From: Orivej Desh Date: Sun, 10 Dec 2017 20:10:35 +0000 Subject: [PATCH 3/3] Python: simplify hasPythonModule --- pkgs/top-level/python-packages.nix | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index d164b80279bb..bcc1bcd7d6b6 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -87,12 +87,11 @@ let in fetcher (builtins.removeAttrs attrs ["format"]) ); # Check whether a derivation provides a Python module. - hasPythonModule = drv: (hasAttr "pythonModule" drv) && ( (getAttr "pythonModule" drv) == python); + hasPythonModule = drv: drv?pythonModule && drv.pythonModule == python; # Get list of required Python modules given a list of derivations. requiredPythonModules = drvs: let - removeNull = list: filter (x: !isNull x) list; - modules = filter hasPythonModule (removeNull drvs); + modules = filter hasPythonModule drvs; in unique ([python] ++ modules ++ concatLists (catAttrs "requiredPythonModules" modules)); # Create a PYTHONPATH from a list of derivations. This function recurses into the items to find derivations