1self: dontUse: with self;
2
3let
4 inherit (python) pythonOnBuildForHost;
5 pythonInterpreter = pythonOnBuildForHost.interpreter;
6 pythonSitePackages = python.sitePackages;
7 pythonCheckInterpreter = python.interpreter;
8 setuppy = ../run_setup.py;
9in {
10 makePythonHook = args: pkgs.makeSetupHook ({passthru.provides.setupHook = true; } // args);
11
12 condaInstallHook = callPackage ({ makePythonHook, gnutar, lbzip2 }:
13 makePythonHook {
14 name = "conda-install-hook";
15 propagatedBuildInputs = [ gnutar lbzip2 ];
16 substitutions = {
17 inherit pythonSitePackages;
18 };
19 } ./conda-install-hook.sh) {};
20
21 condaUnpackHook = callPackage ({ makePythonHook }:
22 makePythonHook {
23 name = "conda-unpack-hook";
24 propagatedBuildInputs = [];
25 } ./conda-unpack-hook.sh) {};
26
27 eggBuildHook = callPackage ({ makePythonHook }:
28 makePythonHook {
29 name = "egg-build-hook.sh";
30 propagatedBuildInputs = [ ];
31 } ./egg-build-hook.sh) {};
32
33 eggInstallHook = callPackage ({ makePythonHook, setuptools }:
34 makePythonHook {
35 name = "egg-install-hook.sh";
36 propagatedBuildInputs = [ setuptools ];
37 substitutions = {
38 inherit pythonInterpreter pythonSitePackages;
39 };
40 } ./egg-install-hook.sh) {};
41
42 eggUnpackHook = callPackage ({ makePythonHook, }:
43 makePythonHook {
44 name = "egg-unpack-hook.sh";
45 propagatedBuildInputs = [ ];
46 } ./egg-unpack-hook.sh) {};
47
48 pipBuildHook = callPackage ({ makePythonHook, pip, wheel }:
49 makePythonHook {
50 name = "pip-build-hook.sh";
51 propagatedBuildInputs = [ pip wheel ];
52 substitutions = {
53 inherit pythonInterpreter pythonSitePackages;
54 };
55 } ./pip-build-hook.sh) {};
56
57 pypaBuildHook = callPackage ({ makePythonHook, build, wheel }:
58 makePythonHook {
59 name = "pypa-build-hook.sh";
60 propagatedBuildInputs = [ wheel ];
61 substitutions = {
62 inherit build;
63 };
64 # A test to ensure that this hook never propagates any of its dependencies
65 # into the build environment.
66 # This prevents false positive alerts raised by catchConflictsHook.
67 # Such conflicts don't happen within the standard nixpkgs python package
68 # set, but in downstream projects that build packages depending on other
69 # versions of this hook's dependencies.
70 passthru.tests = import ./pypa-build-hook-tests.nix {
71 inherit pythonOnBuildForHost runCommand;
72 };
73 } ./pypa-build-hook.sh) {
74 inherit (pythonOnBuildForHost.pkgs) build;
75 };
76
77 pipInstallHook = callPackage ({ makePythonHook, pip }:
78 makePythonHook {
79 name = "pip-install-hook";
80 propagatedBuildInputs = [ pip ];
81 substitutions = {
82 inherit pythonInterpreter pythonSitePackages;
83 };
84 } ./pip-install-hook.sh) {};
85
86 pypaInstallHook = callPackage ({ makePythonHook, installer }:
87 makePythonHook {
88 name = "pypa-install-hook";
89 propagatedBuildInputs = [ installer ];
90 substitutions = {
91 inherit pythonInterpreter pythonSitePackages;
92 };
93 } ./pypa-install-hook.sh) {
94 inherit (pythonOnBuildForHost.pkgs) installer;
95 };
96
97 pytestCheckHook = callPackage ({ makePythonHook, pytest }:
98 makePythonHook {
99 name = "pytest-check-hook";
100 propagatedBuildInputs = [ pytest ];
101 substitutions = {
102 inherit pythonCheckInterpreter;
103 };
104 } ./pytest-check-hook.sh) {};
105
106 pythonCatchConflictsHook = callPackage ({ makePythonHook, setuptools }:
107 makePythonHook {
108 name = "python-catch-conflicts-hook";
109 substitutions = let
110 useLegacyHook = lib.versionOlder python.version "3.10";
111 in {
112 inherit pythonInterpreter pythonSitePackages;
113 catchConflicts = if useLegacyHook then
114 ../catch_conflicts/catch_conflicts_py2.py
115 else
116 ../catch_conflicts/catch_conflicts.py;
117 } // lib.optionalAttrs useLegacyHook {
118 inherit setuptools;
119 };
120 } ./python-catch-conflicts-hook.sh) {};
121
122 pythonImportsCheckHook = callPackage ({ makePythonHook }:
123 makePythonHook {
124 name = "python-imports-check-hook.sh";
125 substitutions = {
126 inherit pythonCheckInterpreter pythonSitePackages;
127 };
128 } ./python-imports-check-hook.sh) {};
129
130 pythonNamespacesHook = callPackage ({ makePythonHook, buildPackages }:
131 makePythonHook {
132 name = "python-namespaces-hook.sh";
133 substitutions = {
134 inherit pythonSitePackages;
135 inherit (buildPackages) findutils;
136 };
137 } ./python-namespaces-hook.sh) {};
138
139 pythonOutputDistHook = callPackage ({ makePythonHook }:
140 makePythonHook {
141 name = "python-output-dist-hook";
142 } ./python-output-dist-hook.sh ) {};
143
144 pythonRecompileBytecodeHook = callPackage ({ makePythonHook }:
145 makePythonHook {
146 name = "python-recompile-bytecode-hook";
147 substitutions = {
148 inherit pythonInterpreter pythonSitePackages;
149 compileArgs = lib.concatStringsSep " " (["-q" "-f" "-i -"] ++ lib.optionals isPy3k ["-j $NIX_BUILD_CORES"]);
150 bytecodeName = if isPy3k then "__pycache__" else "*.pyc";
151 };
152 } ./python-recompile-bytecode-hook.sh ) {};
153
154 pythonRelaxDepsHook = callPackage ({ makePythonHook, wheel }:
155 makePythonHook {
156 name = "python-relax-deps-hook";
157 substitutions = {
158 inherit pythonInterpreter pythonSitePackages wheel;
159 };
160 } ./python-relax-deps-hook.sh) {};
161
162 pythonRemoveBinBytecodeHook = callPackage ({ makePythonHook }:
163 makePythonHook {
164 name = "python-remove-bin-bytecode-hook";
165 } ./python-remove-bin-bytecode-hook.sh) {};
166
167 pythonRemoveTestsDirHook = callPackage ({ makePythonHook }:
168 makePythonHook {
169 name = "python-remove-tests-dir-hook";
170 substitutions = {
171 inherit pythonSitePackages;
172 };
173 } ./python-remove-tests-dir-hook.sh) {};
174
175 setuptoolsBuildHook = callPackage ({ makePythonHook, setuptools, wheel }:
176 makePythonHook {
177 name = "setuptools-setup-hook";
178 propagatedBuildInputs = [ setuptools wheel ];
179 substitutions = {
180 inherit pythonInterpreter pythonSitePackages setuppy;
181 };
182 } ./setuptools-build-hook.sh) {};
183
184 setuptoolsCheckHook = callPackage ({ makePythonHook, setuptools }:
185 makePythonHook {
186 name = "setuptools-check-hook";
187 propagatedBuildInputs = [ setuptools ];
188 substitutions = {
189 inherit pythonCheckInterpreter setuppy;
190 };
191 } ./setuptools-check-hook.sh) {};
192
193 setuptoolsRustBuildHook = callPackage ({ makePythonHook, setuptools-rust }:
194 makePythonHook {
195 name = "setuptools-rust-setup-hook";
196 propagatedBuildInputs = [ setuptools-rust ];
197 substitutions = {
198 pyLibDir = "${python}/lib/${python.libPrefix}";
199 cargoBuildTarget = stdenv.hostPlatform.rust.rustcTargetSpec;
200 cargoLinkerVar = stdenv.hostPlatform.rust.cargoEnvVarTarget;
201 targetLinker = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
202 };
203 } ./setuptools-rust-hook.sh) {};
204
205 unittestCheckHook = callPackage ({ makePythonHook }:
206 makePythonHook {
207 name = "unittest-check-hook";
208 substitutions = {
209 inherit pythonCheckInterpreter;
210 };
211 } ./unittest-check-hook.sh) {};
212
213 venvShellHook = disabledIf (!isPy3k) (callPackage ({ makePythonHook, ensureNewerSourcesForZipFilesHook }:
214 makePythonHook {
215 name = "venv-shell-hook";
216 propagatedBuildInputs = [ ensureNewerSourcesForZipFilesHook ];
217 substitutions = {
218 inherit pythonInterpreter;
219 };
220 } ./venv-shell-hook.sh) {});
221
222 wheelUnpackHook = callPackage ({ makePythonHook, wheel }:
223 makePythonHook {
224 name = "wheel-unpack-hook.sh";
225 propagatedBuildInputs = [ wheel ];
226 } ./wheel-unpack-hook.sh) {};
227
228 wrapPython = callPackage ../wrap-python.nix {
229 inherit (pkgs.buildPackages) makeWrapper;
230 };
231
232 sphinxHook = callPackage ({ makePythonHook, installShellFiles }:
233 makePythonHook {
234 name = "python${python.pythonVersion}-sphinx-hook";
235 propagatedBuildInputs = [ pythonOnBuildForHost.pkgs.sphinx installShellFiles ];
236 substitutions = {
237 sphinxBuild = "${pythonOnBuildForHost.pkgs.sphinx}/bin/sphinx-build";
238 };
239 } ./sphinx-hook.sh) {};
240}