From 03e54c5e8831def65208e65886e6e7afbfc29bb8 Mon Sep 17 00:00:00 2001 From: Frederik Rietdijk Date: Sat, 3 Mar 2018 17:14:09 +0100 Subject: [PATCH] Python: introduce toPythonApplication function This commit introduces the `toPythonApplication` function. Certain Python packages are considered both a library and an application, that is, they expose importable modules, but typically executables that are part of the package are used instead. In this case, the package needs to be added to `python-packages.nix` in order for it to be available as a library. An alias with this function can then be added in `all-packages.nix`, e.g.: ``` ansible = with pythonPackages; toPythonApplication ansible; ``` --- pkgs/top-level/python-packages.nix | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index c17112e623c0..f216da0e0afa 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -98,6 +98,9 @@ let # providing Python modules. makePythonPath = drvs: stdenv.lib.makeSearchPath python.sitePackages (requiredPythonModules drvs); + removePythonPrefix = name: + removePrefix namePrefix name; + # Convert derivation to a Python module. toPythonModule = drv: drv.overrideAttrs( oldAttrs: { @@ -109,14 +112,27 @@ let }; }); + # Convert a Python library to an application. + toPythonApplication = drv: + drv.overrideAttrs( oldAttrs: { + passthru = (oldAttrs.passthru or {}) // { + # Remove Python prefix from name so we have a "normal" name. + # While the prefix shows up in the store path, it won't be + # used by `nix-env`. + name = removePythonPrefix oldAttrs.name; + pythonModule = false; + }; + }); + disabledIf = x: drv: - if x then throw "${removePrefix namePrefix (drv.pname or drv.name)} not supported for interpreter ${python.executable}" else drv; + if x then throw "${removePythonPrefix (drv.pname or drv.name)} not supported for interpreter ${python.executable}" else drv; in { inherit python bootstrapped-pip pythonAtLeast pythonOlder isPy26 isPy27 isPy33 isPy34 isPy35 isPy36 isPyPy isPy3k buildPythonPackage buildPythonApplication; inherit fetchPypi callPackage; inherit hasPythonModule requiredPythonModules makePythonPath disabledIf; + inherit toPythonModule toPythonApplication; # helpers