1/* Generic builder for Python packages that come without a setup.py. */
2
3{ lib
4, python
5, wrapPython
6, setuptools
7, unzip
8, ensureNewerSourcesHook
9}:
10
11{ name
12
13# by default prefix `name` e.g. "python3.3-${name}"
14, namePrefix ? python.libPrefix + "-"
15
16# Dependencies for building the package
17, buildInputs ? []
18
19# Dependencies needed for running the checkPhase.
20# These are added to buildInputs when doCheck = true.
21, checkInputs ? []
22
23# propagate build dependencies so in case we have A -> B -> C,
24# C can import package A propagated by B
25, propagatedBuildInputs ? []
26
27# DEPRECATED: use propagatedBuildInputs
28, pythonPath ? []
29
30# used to disable derivation, useful for specific python versions
31, disabled ? false
32
33# Raise an error if two packages are installed with the same name
34, catchConflicts ? true
35
36# Additional arguments to pass to the makeWrapper function, which wraps
37# generated binaries.
38, makeWrapperArgs ? []
39
40, meta ? {}
41
42, passthru ? {}
43
44, doCheck ? false
45
46, ... } @ attrs:
47
48
49# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
50if disabled
51then throw "${name} not supported for interpreter ${python.executable}"
52else
53
54python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled"] // {
55
56 name = namePrefix + name;
57
58 inherit pythonPath;
59
60 buildInputs = [ wrapPython ] ++ buildInputs ++ pythonPath
61 ++ [ (ensureNewerSourcesHook { year = "1980"; }) ]
62 ++ (lib.optional (lib.hasSuffix "zip" attrs.src.name or "") unzip)
63 ++ lib.optionals doCheck checkInputs;
64
65 # propagate python/setuptools to active setup-hook in nix-shell
66 propagatedBuildInputs = propagatedBuildInputs ++ [ python setuptools ];
67
68 # Python packages don't have a checkPhase, only an installCheckPhase
69 doCheck = false;
70 doInstallCheck = doCheck;
71
72 postFixup = attrs.postFixup or ''
73 wrapPythonPrograms
74 '' + lib.optionalString catchConflicts ''
75 # check if we have two packages with the same name in closure and fail
76 # this shouldn't happen, something went wrong with dependencies specs
77 ${python.interpreter} ${./catch_conflicts.py}
78 '';
79
80 passthru = {
81 inherit python; # The python interpreter
82 } // passthru;
83
84 meta = with lib.maintainers; {
85 # default to python's platforms
86 platforms = python.meta.platforms;
87 } // meta // {
88 # add extra maintainer(s) to every package
89 maintainers = (meta.maintainers or []) ++ [ chaoflow domenkozar ];
90 # a marker for release utilities to discover python packages
91 isBuildPythonPackage = python.meta.platforms;
92 };
93})
94
95