summary refs log tree commit diff
path: root/pkgs/development/interpreters/python/build-python-package.nix
blob: b55d6d874bbb7182c3b175c552f644b1f6c9f3d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# This function provides a generic Python package builder,
# and can build packages that use distutils, setuptools or flit.

{ lib
, config
, python
, wrapPython
, setuptools
, unzip
, ensureNewerSourcesForZipFilesHook
, toPythonModule
, namePrefix
, bootstrapped-pip
, flit
}:

let
  setuptools-specific = import ./build-python-package-setuptools.nix { inherit lib python bootstrapped-pip; };
  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 config python wrapPython setuptools unzip ensureNewerSourcesForZipFilesHook toPythonModule namePrefix;
  };
in

{
# Several package formats are supported.
# "setuptools" : Install a common setuptools/distutils based package. This builds a wheel.
# "wheel" : Install from a pre-compiled wheel.
# "flit" : Install a flit package. This builds a wheel.
# "other" : Provide your own buildPhase and installPhase.
format ? "setuptools"
, ... } @ attrs:

let
  formatspecific =
    if format == "setuptools" then common (setuptools-specific attrs)
    else if format == "flit" then common (flit-specific attrs)
    else if format == "wheel" then common (wheel-specific attrs)
    else if format == "other" then {}
    else throw "Unsupported format ${format}";

in mkPythonDerivation ( attrs // formatspecific )