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