anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / development / interpreters / python / passthrufun.nix
blobdc2f3c7dc17cf3187ba49aa375aaea83ec00f1c6
1 { lib, stdenv, callPackage, pythonPackagesExtensions, config, makeScopeWithSplicing', ... }:
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     });
70   pythonOnBuildForHost_overridden =
71     pythonOnBuildForHost.override { inherit packageOverrides; self = pythonOnBuildForHost_overridden; };
72 in rec {
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";
82     isPy3k = isPy3;
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.
95     pythonForBuild =
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 {
101       python = self;
102     };
104     inherit pythonAttr;