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