1 { lib, stdenv, callPackage, pythonPackagesExtensions, config, makeScopeWithSplicing', ... }:
10 , hasDistutilsCxxPatch
11 , pythonOnBuildForBuild
12 , pythonOnBuildForHost
13 , pythonOnBuildForTarget
15 , pythonOnTargetForTarget
17 , self # is pythonOnHostForTarget
20 ensurePythonModules = items: let
24 providesSetupHook = lib.attrByPath [ "provides" "setupHook"] false;
25 valid = value: pythonPackages.hasPythonModule value || providesSetupHook value || lib.elem value exceptions;
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
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;
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.
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 ([
57 ] ++ (optionalExtensions (!self.isPy3k) [
59 ]) ++ pythonPackagesExtensions ++ [
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;
67 overrides = packageOverrides;
70 pythonOnBuildForHost_overridden =
71 pythonOnBuildForHost.override { inherit packageOverrides; self = pythonOnBuildForHost_overridden; };
73 isPy27 = pythonVersion == "2.7";
74 isPy37 = pythonVersion == "3.7";
75 isPy38 = pythonVersion == "3.8";
76 isPy39 = pythonVersion == "3.9";
77 isPy310 = pythonVersion == "3.10";
78 isPy311 = pythonVersion == "3.11";
79 isPy312 = pythonVersion == "3.12";
80 isPy2 = lib.strings.substring 0 1 pythonVersion == "2";
81 isPy3 = lib.strings.substring 0 1 pythonVersion == "3";
83 isPyPy = lib.hasInfix "pypy" interpreter;
85 buildEnv = callPackage ./wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
86 withPackages = import ./with-packages.nix { inherit buildEnv pythonPackages;};
87 pkgs = pythonPackages;
88 interpreter = "${self}/bin/${executable}";
89 inherit executable implementation libPrefix pythonVersion sitePackages;
90 inherit sourceVersion;
91 pythonAtLeast = lib.versionAtLeast pythonVersion;
92 pythonOlder = lib.versionOlder pythonVersion;
93 inherit hasDistutilsCxxPatch;
94 # Remove after 24.11 is released.
96 lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2311) "`pythonForBuild` (from `python*`) has been renamed to `pythonOnBuildForHost`"
97 pythonOnBuildForHost_overridden;
98 pythonOnBuildForHost = pythonOnBuildForHost_overridden;
100 tests = callPackage ./tests.nix {