1self: dontUse:
2with self;
3
4let
5 inherit (python) pythonOnBuildForHost;
6 inherit (pkgs) runCommand;
7 pythonInterpreter = pythonOnBuildForHost.interpreter;
8 pythonSitePackages = python.sitePackages;
9 pythonCheckInterpreter = python.interpreter;
10 setuppy = ../run_setup.py;
11in
12{
13 makePythonHook =
14 let
15 defaultArgs = {
16 passthru.provides.setupHook = true;
17 };
18 in
19 args: pkgs.makeSetupHook (lib.recursiveUpdate defaultArgs args);
20
21 condaInstallHook = callPackage (
22 {
23 makePythonHook,
24 gnutar,
25 lbzip2,
26 }:
27 makePythonHook {
28 name = "conda-install-hook";
29 propagatedBuildInputs = [
30 gnutar
31 lbzip2
32 ];
33 substitutions = {
34 inherit pythonSitePackages;
35 };
36 } ./conda-install-hook.sh
37 ) { };
38
39 condaUnpackHook = callPackage (
40 { makePythonHook }:
41 makePythonHook {
42 name = "conda-unpack-hook";
43 propagatedBuildInputs = [ ];
44 } ./conda-unpack-hook.sh
45 ) { };
46
47 eggBuildHook = callPackage (
48 { makePythonHook }:
49 makePythonHook {
50 name = "egg-build-hook.sh";
51 propagatedBuildInputs = [ ];
52 } ./egg-build-hook.sh
53 ) { };
54
55 eggInstallHook = callPackage (
56 { makePythonHook, setuptools }:
57 makePythonHook {
58 name = "egg-install-hook.sh";
59 propagatedBuildInputs = [ setuptools ];
60 substitutions = {
61 inherit pythonInterpreter pythonSitePackages;
62 };
63 } ./egg-install-hook.sh
64 ) { };
65
66 eggUnpackHook = callPackage (
67 { makePythonHook }:
68 makePythonHook {
69 name = "egg-unpack-hook.sh";
70 propagatedBuildInputs = [ ];
71 } ./egg-unpack-hook.sh
72 ) { };
73
74 pipBuildHook = callPackage (
75 {
76 makePythonHook,
77 pip,
78 wheel,
79 }:
80 makePythonHook {
81 name = "pip-build-hook.sh";
82 propagatedBuildInputs = [
83 pip
84 wheel
85 ];
86 substitutions = {
87 inherit pythonInterpreter pythonSitePackages;
88 };
89 } ./pip-build-hook.sh
90 ) { };
91
92 pypaBuildHook =
93 callPackage
94 (
95 {
96 makePythonHook,
97 build,
98 wheel,
99 }:
100 makePythonHook {
101 name = "pypa-build-hook.sh";
102 propagatedBuildInputs = [ wheel ];
103 substitutions = {
104 inherit build;
105 };
106 # A test to ensure that this hook never propagates any of its dependencies
107 # into the build environment.
108 # This prevents false positive alerts raised by catchConflictsHook.
109 # Such conflicts don't happen within the standard nixpkgs python package
110 # set, but in downstream projects that build packages depending on other
111 # versions of this hook's dependencies.
112 passthru.tests = callPackage ./pypa-build-hook-test.nix {
113 inherit pythonOnBuildForHost;
114 };
115 } ./pypa-build-hook.sh
116 )
117 {
118 inherit (pythonOnBuildForHost.pkgs) build;
119 };
120
121 pipInstallHook = callPackage (
122 { makePythonHook, pip }:
123 makePythonHook {
124 name = "pip-install-hook";
125 propagatedBuildInputs = [ pip ];
126 substitutions = {
127 inherit pythonInterpreter pythonSitePackages;
128 };
129 } ./pip-install-hook.sh
130 ) { };
131
132 pypaInstallHook =
133 callPackage
134 (
135 { makePythonHook, installer }:
136 makePythonHook {
137 name = "pypa-install-hook";
138 propagatedBuildInputs = [ installer ];
139 substitutions = {
140 inherit pythonInterpreter pythonSitePackages;
141 };
142 } ./pypa-install-hook.sh
143 )
144 {
145 inherit (pythonOnBuildForHost.pkgs) installer;
146 };
147
148 pytestCheckHook = callPackage (
149 { makePythonHook, pytest }:
150 makePythonHook {
151 name = "pytest-check-hook";
152 propagatedBuildInputs = [ pytest ];
153 substitutions = {
154 inherit pythonCheckInterpreter;
155 };
156 } ./pytest-check-hook.sh
157 ) { };
158
159 pythonCatchConflictsHook = callPackage (
160 { makePythonHook, setuptools }:
161 makePythonHook {
162 name = "python-catch-conflicts-hook";
163 substitutions =
164 let
165 useLegacyHook = lib.versionOlder python.pythonVersion "3";
166 in
167 {
168 inherit pythonInterpreter pythonSitePackages;
169 catchConflicts =
170 if useLegacyHook then
171 ../catch_conflicts/catch_conflicts_py2.py
172 else
173 ../catch_conflicts/catch_conflicts.py;
174 }
175 // lib.optionalAttrs useLegacyHook {
176 inherit setuptools;
177 };
178 passthru.tests = import ./python-catch-conflicts-hook-tests.nix {
179 inherit pythonOnBuildForHost runCommand;
180 inherit lib;
181 inherit (pkgs) coreutils gnugrep writeShellScript;
182 };
183 } ./python-catch-conflicts-hook.sh
184 ) { };
185
186 pythonImportsCheckHook = callPackage (
187 { makePythonHook }:
188 makePythonHook {
189 name = "python-imports-check-hook.sh";
190 substitutions = {
191 inherit pythonCheckInterpreter pythonSitePackages;
192 };
193 } ./python-imports-check-hook.sh
194 ) { };
195
196 pythonNamespacesHook = callPackage (
197 { makePythonHook, buildPackages }:
198 makePythonHook {
199 name = "python-namespaces-hook.sh";
200 substitutions = {
201 inherit pythonSitePackages;
202 inherit (buildPackages) findutils;
203 };
204 } ./python-namespaces-hook.sh
205 ) { };
206
207 pythonOutputDistHook = callPackage (
208 { makePythonHook }:
209 makePythonHook {
210 name = "python-output-dist-hook";
211 } ./python-output-dist-hook.sh
212 ) { };
213
214 pythonRecompileBytecodeHook = callPackage (
215 { makePythonHook }:
216 makePythonHook {
217 name = "python-recompile-bytecode-hook";
218 substitutions = {
219 inherit pythonInterpreter pythonSitePackages;
220 compileArgs = lib.concatStringsSep " " (
221 [
222 "-q"
223 "-f"
224 "-i -"
225 ]
226 ++ lib.optionals isPy3k [ "-j $NIX_BUILD_CORES" ]
227 );
228 bytecodeName = if isPy3k then "__pycache__" else "*.pyc";
229 };
230 } ./python-recompile-bytecode-hook.sh
231 ) { };
232
233 pythonRelaxDepsHook = callPackage (
234 { makePythonHook, wheel }:
235 makePythonHook {
236 name = "python-relax-deps-hook";
237 substitutions = {
238 inherit pythonInterpreter pythonSitePackages wheel;
239 };
240 } ./python-relax-deps-hook.sh
241 ) { };
242
243 pythonRemoveBinBytecodeHook = callPackage (
244 { makePythonHook }:
245 makePythonHook {
246 name = "python-remove-bin-bytecode-hook";
247 } ./python-remove-bin-bytecode-hook.sh
248 ) { };
249
250 pythonRemoveTestsDirHook = callPackage (
251 { makePythonHook }:
252 makePythonHook {
253 name = "python-remove-tests-dir-hook";
254 substitutions = {
255 inherit pythonSitePackages;
256 };
257 } ./python-remove-tests-dir-hook.sh
258 ) { };
259
260 pythonRuntimeDepsCheckHook = callPackage (
261 { makePythonHook, packaging }:
262 makePythonHook {
263 name = "python-runtime-deps-check-hook.sh";
264 propagatedBuildInputs = [ packaging ];
265 substitutions = {
266 inherit pythonInterpreter pythonSitePackages;
267 hook = ./python-runtime-deps-check-hook.py;
268 };
269 } ./python-runtime-deps-check-hook.sh
270 ) { };
271
272 setuptoolsBuildHook = callPackage (
273 {
274 makePythonHook,
275 setuptools,
276 wheel,
277 }:
278 makePythonHook {
279 name = "setuptools-build-hook";
280 propagatedBuildInputs = [
281 setuptools
282 wheel
283 ];
284 substitutions = {
285 inherit pythonInterpreter setuppy;
286 # python2.pkgs.setuptools does not support parallelism
287 setuptools_has_parallel = setuptools != null && lib.versionAtLeast setuptools.version "69";
288 };
289 } ./setuptools-build-hook.sh
290 ) { };
291
292 setuptoolsCheckHook = throw "The setuptoolsCheckHook has been removed, since the test command has been removed in setuptools 72.0";
293
294 setuptoolsRustBuildHook = callPackage (
295 { makePythonHook, setuptools-rust }:
296 makePythonHook {
297 name = "setuptools-rust-setup-hook";
298 propagatedBuildInputs = [ setuptools-rust ];
299 substitutions = {
300 pyLibDir = "${python}/lib/${python.libPrefix}";
301 cargoBuildTarget = stdenv.hostPlatform.rust.rustcTargetSpec;
302 cargoLinkerVar = stdenv.hostPlatform.rust.cargoEnvVarTarget;
303 targetLinker = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
304 };
305 } ./setuptools-rust-hook.sh
306 ) { };
307
308 unittestCheckHook = callPackage (
309 { makePythonHook }:
310 makePythonHook {
311 name = "unittest-check-hook";
312 substitutions = {
313 inherit pythonCheckInterpreter;
314 };
315 } ./unittest-check-hook.sh
316 ) { };
317
318 venvShellHook = disabledIf (!isPy3k) (
319 callPackage (
320 { makePythonHook, ensureNewerSourcesForZipFilesHook }:
321 makePythonHook {
322 name = "venv-shell-hook";
323 propagatedBuildInputs = [ ensureNewerSourcesForZipFilesHook ];
324 substitutions = {
325 inherit pythonInterpreter;
326 };
327 } ./venv-shell-hook.sh
328 ) { }
329 );
330
331 wheelUnpackHook = callPackage (
332 { makePythonHook, wheel }:
333 makePythonHook {
334 name = "wheel-unpack-hook.sh";
335 propagatedBuildInputs = [ wheel ];
336 } ./wheel-unpack-hook.sh
337 ) { };
338
339 wrapPython = callPackage ../wrap-python.nix {
340 inherit (pkgs.buildPackages) makeWrapper;
341 };
342
343 sphinxHook = callPackage (
344 { makePythonHook, installShellFiles }:
345 makePythonHook {
346 name = "python${python.pythonVersion}-sphinx-hook";
347 propagatedBuildInputs = [
348 pythonOnBuildForHost.pkgs.sphinx
349 installShellFiles
350 ];
351 substitutions = {
352 sphinxBuild = "${pythonOnBuildForHost.pkgs.sphinx}/bin/sphinx-build";
353 };
354 } ./sphinx-hook.sh
355 ) { };
356}