Python: the pythonModule attribute

Python libraries or modules now have an attribute `pythonModule = interpreter;` to indicate
they provide Python modules for the specified `interpreter`.

The package set provides the following helper functions:

- hasPythonModule: Check whether a derivation provides a Python module.
- requiredPythonModules: Recurse into a list of Python modules, returning all Python modules that are required.
- makePythonPath: Create a PYTHONPATH from a list of Python modules.

Also included in this commit is:
- disabledIf: Helper function for disabling non-buildPythonPackage functions.
This commit is contained in:
Frederik Rietdijk
2017-05-28 09:20:47 +02:00
parent a30fa6d9a2
commit 40851a4d26
9 changed files with 67 additions and 21 deletions

View File

@@ -5,7 +5,12 @@
{ lib
, python
, mkPythonDerivation
, wrapPython
, setuptools
, unzip
, ensureNewerSourcesHook
, pythonModule
, namePrefix
, bootstrapped-pip
, flit
}:
@@ -15,6 +20,9 @@ let
flit-specific = import ./build-python-package-flit.nix { inherit python flit; };
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;
};
in
{

View File

@@ -201,7 +201,7 @@ in stdenv.mkDerivation {
in rec {
inherit libPrefix sitePackages x11Support hasDistutilsCxxPatch;
executable = libPrefix;
buildEnv = callPackage ../../wrapper.nix { python = self; };
buildEnv = callPackage ../../wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;};
pkgs = pythonPackages;
isPy2 = true;

View File

@@ -160,7 +160,7 @@ in stdenv.mkDerivation {
in rec {
inherit libPrefix sitePackages x11Support;
executable = "${libPrefix}m";
buildEnv = callPackage ../../wrapper.nix { python = self; };
buildEnv = callPackage ../../wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;};
pkgs = pythonPackages;
isPy3 = true;

View File

@@ -154,7 +154,7 @@ in stdenv.mkDerivation {
in rec {
inherit libPrefix sitePackages x11Support;
executable = "${libPrefix}m";
buildEnv = callPackage ../../wrapper.nix { python = self; };
buildEnv = callPackage ../../wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;};
pkgs = pythonPackages;
isPy3 = true;

View File

@@ -153,7 +153,7 @@ in stdenv.mkDerivation {
in rec {
inherit libPrefix sitePackages x11Support;
executable = "${libPrefix}m";
buildEnv = callPackage ../../wrapper.nix { python = self; };
buildEnv = callPackage ../../wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;};
pkgs = pythonPackages;
isPy3 = true;

View File

@@ -6,13 +6,13 @@
, setuptools
, unzip
, ensureNewerSourcesHook
# Whether the derivation provides a Python module or not.
, pythonModule
, namePrefix
}:
{ name ? "${attrs.pname}-${attrs.version}"
# by default prefix `name` e.g. "python3.3-${name}"
, namePrefix ? python.libPrefix + "-"
# Dependencies for building the package
, buildInputs ? []
@@ -54,7 +54,7 @@ if disabled
then throw "${name} not supported for interpreter ${python.executable}"
else
python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "checkInputs"] // {
python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "checkInputs" "pythonModule"] // {
name = namePrefix + name;
@@ -83,6 +83,7 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "checkInputs"
passthru = {
inherit python; # The python interpreter
inherit pythonModule;
} // passthru;
meta = with lib.maintainers; {

View File

@@ -137,7 +137,7 @@ in stdenv.mkDerivation rec {
inherit zlibSupport libPrefix sitePackages;
executable = "pypy";
isPypy = true;
buildEnv = callPackage ../../wrapper.nix { python = self; };
buildEnv = callPackage ../../wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
interpreter = "${self}/bin/${executable}";
withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;};
pkgs = pythonPackages;

View File

@@ -2,13 +2,14 @@
, extraLibs ? []
, extraOutputsToInstall ? []
, postBuild ? ""
, ignoreCollisions ? false }:
, ignoreCollisions ? false
, requiredPythonModules
, }:
# Create a python executable that knows about additional packages.
let
recursivePthLoader = import ../../python-modules/recursive-pth-loader/default.nix { stdenv = stdenv; python = python; };
env = let
paths = stdenv.lib.closePropagation (extraLibs ++ [ python recursivePthLoader ] ) ;
paths = requiredPythonModules (extraLibs ++ [ python ] ) ;
in buildEnv {
name = "${python.name}-env";