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 {
150 makePythonHook,
151 pytest,
152 # For package tests
153 testers,
154 objprint,
155 }:
156 makePythonHook {
157 name = "pytest-check-hook";
158 propagatedBuildInputs = [ pytest ];
159 substitutions = {
160 inherit pythonCheckInterpreter;
161 };
162 passthru = {
163 tests = {
164 basic = objprint.overridePythonAttrs (previousPythonAttrs: {
165 pname = "test-pytestCheckHook-basic-${previousPythonAttrs.pname}";
166 });
167 disabledTests = objprint.overridePythonAttrs (previousPythonAttrs: {
168 pname = "test-pytestCheckHook-disabledTests-${previousPythonAttrs.pname}";
169 disabledTests = [
170 "test_print"
171 ]
172 ++ previousPythonAttrs.disabledTests or [ ];
173 });
174 disabledTests-expression = objprint.overridePythonAttrs (previousPythonAttrs: {
175 __structuredAttrs = true;
176 pname = "test-pytestCheckHook-disabledTests-expression-${previousPythonAttrs.pname}";
177 disabledTests = [
178 "TestBasic and test_print"
179 "test_str"
180 ]
181 ++ previousPythonAttrs.disabledTests or [ ];
182 });
183 disabledTestPaths = objprint.overridePythonAttrs (previousPythonAttrs: {
184 pname = "test-pytestCheckHook-disabledTestPaths-${previousPythonAttrs.pname}";
185 disabledTestPaths = [
186 "tests/test_basic.py"
187 ]
188 ++ previousPythonAttrs.disabledTestPaths or [ ];
189 });
190 disabledTestPaths-nonexistent = testers.testBuildFailure (
191 objprint.overridePythonAttrs (previousPythonAttrs: {
192 pname = "test-pytestCheckHook-disabledTestPaths-nonexistent-${previousPythonAttrs.pname}";
193 disabledTestPaths = [
194 "tests/test_foo.py"
195 ]
196 ++ previousPythonAttrs.disabledTestPaths or [ ];
197 })
198 );
199 disabledTestPaths-item = objprint.overridePythonAttrs (previousPythonAttrs: {
200 pname = "test-pytestCheckHook-disabledTestPaths-item-${previousPythonAttrs.pname}";
201 disabledTestPaths = [
202 "tests/test_basic.py::TestBasic"
203 ]
204 ++ previousPythonAttrs.disabledTestPaths or [ ];
205 });
206 disabledTestPaths-glob = objprint.overridePythonAttrs (previousPythonAttrs: {
207 pname = "test-pytestCheckHook-disabledTestPaths-glob-${previousPythonAttrs.pname}";
208 disabledTestPaths = [
209 "tests/test_obj*.py"
210 ]
211 ++ previousPythonAttrs.disabledTestPaths or [ ];
212 });
213 disabledTestPaths-glob-nonexistent = testers.testBuildFailure (
214 objprint.overridePythonAttrs (previousPythonAttrs: {
215 pname = "test-pytestCheckHook-disabledTestPaths-glob-nonexistent-${previousPythonAttrs.pname}";
216 disabledTestPaths = [
217 "tests/test_foo*.py"
218 ]
219 ++ previousPythonAttrs.disabledTestPaths or [ ];
220 })
221 );
222 enabledTests = objprint.overridePythonAttrs (previousPythonAttrs: {
223 pname = "test-pytestCheckHook-enabledTests-${previousPythonAttrs.pname}";
224 enabledTests = [
225 "TestBasic"
226 ]
227 ++ previousPythonAttrs.disabledTests or [ ];
228 });
229 enabledTests-expression = objprint.overridePythonAttrs (previousPythonAttrs: {
230 __structuredAttrs = true;
231 pname = "test-pytestCheckHook-enabledTests-expression-${previousPythonAttrs.pname}";
232 enabledTests = [
233 "TestBasic and test_print"
234 "test_str"
235 ]
236 ++ previousPythonAttrs.disabledTests or [ ];
237 });
238 enabledTests-disabledTests = objprint.overridePythonAttrs (previousPythonAttrs: {
239 pname = "test-pytestCheckHook-enabledTests-disabledTests-${previousPythonAttrs.pname}";
240 enabledTests = [
241 "TestBasic"
242 ]
243 ++ previousPythonAttrs.disabledTests or [ ];
244 disabledTests = [
245 "test_print"
246 ]
247 ++ previousPythonAttrs.disabledTests or [ ];
248 });
249 enabledTestPaths = objprint.overridePythonAttrs (previousPythonAttrs: {
250 pname = "test-pytestCheckHook-enabledTestPaths-${previousPythonAttrs.pname}";
251 enabledTestPaths = [
252 "tests/test_basic.py"
253 ]
254 ++ previousPythonAttrs.enabledTestPaths or [ ];
255 });
256 enabledTestPaths-nonexistent = testers.testBuildFailure (
257 objprint.overridePythonAttrs (previousPythonAttrs: {
258 pname = "test-pytestCheckHook-enabledTestPaths-nonexistent-${previousPythonAttrs.pname}";
259 enabledTestPaths = [
260 "tests/test_foo.py"
261 ]
262 ++ previousPythonAttrs.enabledTestPaths or [ ];
263 })
264 );
265 enabledTestPaths-dir = objprint.overridePythonAttrs (previousPythonAttrs: {
266 pname = "test-pytestCheckHook-enabledTestPaths-dir-${previousPythonAttrs.pname}";
267 enabledTestPaths = [
268 "tests"
269 ]
270 ++ previousPythonAttrs.enabledTestPaths or [ ];
271 });
272 enabledTestPaths-dir-disabledTestPaths = objprint.overridePythonAttrs (previousPythonAttrs: {
273 pname = "test-pytestCheckHook-enabledTestPaths-dir-disabledTestPaths-${previousPythonAttrs.pname}";
274 enabledTestPaths = [
275 "tests"
276 ]
277 ++ previousPythonAttrs.enabledTestPaths or [ ];
278 disabledTestPaths = [
279 "tests/test_basic.py"
280 ]
281 ++ previousPythonAttrs.disabledTestPaths or [ ];
282 });
283 enabledTestPaths-glob = objprint.overridePythonAttrs (previousPythonAttrs: {
284 pname = "test-pytestCheckHook-enabledTestPaths-glob-${previousPythonAttrs.pname}";
285 enabledTestPaths = [
286 "tests/test_obj*.py"
287 ]
288 ++ previousPythonAttrs.enabledTestPaths or [ ];
289 });
290 enabledTestPaths-glob-nonexistent = testers.testBuildFailure (
291 objprint.overridePythonAttrs (previousPythonAttrs: {
292 pname = "test-pytestCheckHook-enabledTestPaths-glob-nonexistent-${previousPythonAttrs.pname}";
293 enabledTestPaths = [
294 "tests/test_foo*.py"
295 ]
296 ++ previousPythonAttrs.enabledTestPaths or [ ];
297 })
298 );
299 enabledTestPaths-item = objprint.overridePythonAttrs (previousPythonAttrs: {
300 pname = "test-pytestCheckHook-enabledTestPaths-item-${previousPythonAttrs.pname}";
301 enabledTestPaths = [
302 "tests/test_basic.py::TestBasic"
303 ]
304 ++ previousPythonAttrs.enabledTestPaths or [ ];
305 });
306 };
307 };
308 } ./pytest-check-hook.sh
309 ) { };
310
311 pythonCatchConflictsHook = callPackage (
312 { makePythonHook, setuptools }:
313 makePythonHook {
314 name = "python-catch-conflicts-hook";
315 substitutions =
316 let
317 useLegacyHook = lib.versionOlder python.pythonVersion "3";
318 in
319 {
320 inherit pythonInterpreter pythonSitePackages;
321 catchConflicts =
322 if useLegacyHook then
323 ../catch_conflicts/catch_conflicts_py2.py
324 else
325 ../catch_conflicts/catch_conflicts.py;
326 }
327 // lib.optionalAttrs useLegacyHook {
328 inherit setuptools;
329 };
330 passthru.tests = import ./python-catch-conflicts-hook-tests.nix {
331 inherit pythonOnBuildForHost runCommand;
332 inherit lib;
333 inherit (pkgs) coreutils gnugrep writeShellScript;
334 };
335 } ./python-catch-conflicts-hook.sh
336 ) { };
337
338 pythonImportsCheckHook = callPackage (
339 { makePythonHook }:
340 makePythonHook {
341 name = "python-imports-check-hook.sh";
342 substitutions = {
343 inherit pythonCheckInterpreter pythonSitePackages;
344 };
345 } ./python-imports-check-hook.sh
346 ) { };
347
348 pythonNamespacesHook = callPackage (
349 { makePythonHook, buildPackages }:
350 makePythonHook {
351 name = "python-namespaces-hook.sh";
352 substitutions = {
353 inherit pythonSitePackages;
354 inherit (buildPackages) findutils;
355 };
356 } ./python-namespaces-hook.sh
357 ) { };
358
359 pythonOutputDistHook = callPackage (
360 { makePythonHook }:
361 makePythonHook {
362 name = "python-output-dist-hook";
363 } ./python-output-dist-hook.sh
364 ) { };
365
366 pythonRecompileBytecodeHook = callPackage (
367 { makePythonHook }:
368 makePythonHook {
369 name = "python-recompile-bytecode-hook";
370 substitutions = {
371 inherit pythonInterpreter pythonSitePackages;
372 compileArgs = lib.concatStringsSep " " (
373 [
374 "-q"
375 "-f"
376 "-i -"
377 ]
378 ++ lib.optionals isPy3k [ "-j $NIX_BUILD_CORES" ]
379 );
380 bytecodeName = if isPy3k then "__pycache__" else "*.pyc";
381 };
382 } ./python-recompile-bytecode-hook.sh
383 ) { };
384
385 pythonRelaxDepsHook = callPackage (
386 { makePythonHook, wheel }:
387 makePythonHook {
388 name = "python-relax-deps-hook";
389 substitutions = {
390 inherit pythonInterpreter pythonSitePackages wheel;
391 };
392 } ./python-relax-deps-hook.sh
393 ) { };
394
395 pythonRemoveBinBytecodeHook = callPackage (
396 { makePythonHook }:
397 makePythonHook {
398 name = "python-remove-bin-bytecode-hook";
399 } ./python-remove-bin-bytecode-hook.sh
400 ) { };
401
402 pythonRemoveTestsDirHook = callPackage (
403 { makePythonHook }:
404 makePythonHook {
405 name = "python-remove-tests-dir-hook";
406 substitutions = {
407 inherit pythonSitePackages;
408 };
409 } ./python-remove-tests-dir-hook.sh
410 ) { };
411
412 pythonRuntimeDepsCheckHook = callPackage (
413 { makePythonHook, packaging }:
414 makePythonHook {
415 name = "python-runtime-deps-check-hook.sh";
416 propagatedBuildInputs = [ packaging ];
417 substitutions = {
418 inherit pythonInterpreter pythonSitePackages;
419 hook = ./python-runtime-deps-check-hook.py;
420 };
421 } ./python-runtime-deps-check-hook.sh
422 ) { };
423
424 setuptoolsBuildHook = callPackage (
425 {
426 makePythonHook,
427 setuptools,
428 wheel,
429 }:
430 makePythonHook {
431 name = "setuptools-build-hook";
432 propagatedBuildInputs = [
433 setuptools
434 wheel
435 ];
436 substitutions = {
437 inherit pythonInterpreter setuppy;
438 # python2.pkgs.setuptools does not support parallelism
439 setuptools_has_parallel = setuptools != null && lib.versionAtLeast setuptools.version "69";
440 };
441 } ./setuptools-build-hook.sh
442 ) { };
443
444 setuptoolsRustBuildHook = callPackage (
445 { makePythonHook, setuptools-rust }:
446 makePythonHook {
447 name = "setuptools-rust-setup-hook";
448 propagatedBuildInputs = [ setuptools-rust ];
449 substitutions = {
450 pyLibDir = "${python}/lib/${python.libPrefix}";
451 cargoBuildTarget = stdenv.hostPlatform.rust.rustcTargetSpec;
452 cargoLinkerVar = stdenv.hostPlatform.rust.cargoEnvVarTarget;
453 targetLinker = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
454 };
455 } ./setuptools-rust-hook.sh
456 ) { };
457
458 unittestCheckHook = callPackage (
459 { makePythonHook }:
460 makePythonHook {
461 name = "unittest-check-hook";
462 substitutions = {
463 inherit pythonCheckInterpreter;
464 };
465 } ./unittest-check-hook.sh
466 ) { };
467
468 venvShellHook = disabledIf (!isPy3k) (
469 callPackage (
470 { makePythonHook, ensureNewerSourcesForZipFilesHook }:
471 makePythonHook {
472 name = "venv-shell-hook";
473 propagatedBuildInputs = [ ensureNewerSourcesForZipFilesHook ];
474 substitutions = {
475 inherit pythonInterpreter;
476 };
477 } ./venv-shell-hook.sh
478 ) { }
479 );
480
481 wheelUnpackHook = callPackage (
482 { makePythonHook, wheel }:
483 makePythonHook {
484 name = "wheel-unpack-hook.sh";
485 propagatedBuildInputs = [ wheel ];
486 } ./wheel-unpack-hook.sh
487 ) { };
488
489 wrapPython = callPackage ../wrap-python.nix {
490 inherit (pkgs.buildPackages) makeWrapper;
491 };
492
493 sphinxHook = callPackage (
494 { makePythonHook, installShellFiles }:
495 makePythonHook {
496 name = "python${python.pythonVersion}-sphinx-hook";
497 propagatedBuildInputs = [
498 pythonOnBuildForHost.pkgs.sphinx
499 installShellFiles
500 ];
501 substitutions = {
502 sphinxBuild = "${pythonOnBuildForHost.pkgs.sphinx}/bin/sphinx-build";
503 };
504 } ./sphinx-hook.sh
505 ) { };
506}