1{
2 lib,
3 stdenv,
4 callPackage,
5 pythonPackagesExtensions,
6 config,
7 makeScopeWithSplicing',
8 ...
9}:
10
11{
12 implementation,
13 libPrefix,
14 executable,
15 sourceVersion,
16 pythonVersion,
17 packageOverrides,
18 sitePackages,
19 hasDistutilsCxxPatch,
20 pythonOnBuildForBuild,
21 pythonOnBuildForHost,
22 pythonOnBuildForTarget,
23 pythonOnHostForHost,
24 pythonOnTargetForTarget,
25 pythonAttr ? null,
26 self, # is pythonOnHostForTarget
27}:
28let
29 pythonPackages =
30 let
31 ensurePythonModules =
32 items:
33 let
34 exceptions = [
35 stdenv
36 ];
37 providesSetupHook = lib.attrByPath [ "provides" "setupHook" ] false;
38 valid =
39 value: pythonPackages.hasPythonModule value || providesSetupHook value || lib.elem value exceptions;
40 func =
41 name: value:
42 if lib.isDerivation value then
43 lib.extendDerivation (
44 valid value
45 || throw "${name} should use `buildPythonPackage` or `toPythonModule` if it is to be part of the Python packages set."
46 ) { } value
47 else
48 value;
49 in
50 lib.mapAttrs func items;
51 in
52 ensurePythonModules (
53 callPackage
54 # Function that when called
55 # - imports python-packages.nix
56 # - adds spliced package sets to the package set
57 # - applies overrides from `packageOverrides` and `pythonPackagesOverlays`.
58 (
59 {
60 pkgs,
61 stdenv,
62 python,
63 overrides,
64 }:
65 let
66 pythonPackagesFun = import ./python-packages-base.nix {
67 inherit stdenv pkgs lib;
68 python = self;
69 };
70 otherSplices = {
71 selfBuildBuild = pythonOnBuildForBuild.pkgs;
72 selfBuildHost = pythonOnBuildForHost.pkgs;
73 selfBuildTarget = pythonOnBuildForTarget.pkgs;
74 selfHostHost = pythonOnHostForHost.pkgs;
75 selfTargetTarget = pythonOnTargetForTarget.pkgs or { }; # There is no Python TargetTarget.
76 };
77 hooks = import ./hooks/default.nix;
78 keep = self: hooks self { };
79 optionalExtensions = cond: as: lib.optionals cond as;
80 pythonExtension = import ../../../top-level/python-packages.nix;
81 python2Extension = import ../../../top-level/python2-packages.nix;
82 extensions = lib.composeManyExtensions (
83 [
84 hooks
85 pythonExtension
86 ]
87 ++ (optionalExtensions (!self.isPy3k) [
88 python2Extension
89 ])
90 ++ pythonPackagesExtensions
91 ++ [
92 overrides
93 ]
94 );
95 aliases =
96 self: super:
97 lib.optionalAttrs config.allowAliases (import ../../../top-level/python-aliases.nix lib self super);
98 in
99 makeScopeWithSplicing' {
100 inherit otherSplices keep;
101 f = lib.extends (lib.composeExtensions aliases extensions) pythonPackagesFun;
102 }
103 )
104 {
105 overrides = packageOverrides;
106 python = self;
107 }
108 );
109in
110rec {
111 isPy27 = pythonVersion == "2.7";
112 isPy37 = pythonVersion == "3.7";
113 isPy38 = pythonVersion == "3.8";
114 isPy39 = pythonVersion == "3.9";
115 isPy310 = pythonVersion == "3.10";
116 isPy311 = pythonVersion == "3.11";
117 isPy312 = pythonVersion == "3.12";
118 isPy313 = pythonVersion == "3.13";
119 isPy314 = pythonVersion == "3.14";
120 isPy2 = lib.strings.substring 0 1 pythonVersion == "2";
121 isPy3 = lib.strings.substring 0 1 pythonVersion == "3";
122 isPy3k = isPy3;
123 isPyPy = lib.hasInfix "pypy" interpreter;
124
125 buildEnv = callPackage ./wrapper.nix {
126 python = self;
127 inherit (pythonPackages) requiredPythonModules;
128 };
129 withPackages = import ./with-packages.nix { inherit buildEnv pythonPackages; };
130 pkgs = pythonPackages;
131 interpreter = "${self}/bin/${executable}";
132 inherit
133 executable
134 implementation
135 libPrefix
136 pythonVersion
137 sitePackages
138 ;
139 inherit sourceVersion;
140 pythonAtLeast = lib.versionAtLeast pythonVersion;
141 pythonOlder = lib.versionOlder pythonVersion;
142 inherit hasDistutilsCxxPatch;
143 inherit pythonOnBuildForHost;
144
145 tests = callPackage ./tests.nix {
146 python = self;
147 };
148
149 inherit pythonAttr;
150}