cypthon: moduralize so it can be called with other versions

authored by

Domen Kožar and committed by
Frederik Rietdijk
9f3e0de1 b4222d66

+107 -104
+2 -1
pkgs/development/interpreters/python/cpython/default.nix
··· 53 53 , enableLTO ? stdenv.is64bit && stdenv.isLinux 54 54 , reproducibleBuild ? false 55 55 , pythonAttr ? "python${sourceVersion.major}${sourceVersion.minor}" 56 + , noldconfigPatch ? ./. + "/${sourceVersion.major}.${sourceVersion.minor}/no-ldconfig.patch" 56 57 } @ inputs: 57 58 58 59 # Note: this package is used for bootstrapping fetchurl, and thus ··· 252 253 # ctypes.util.find_library during the loading of the uuid module 253 254 # (since it will do a futile invocation of gcc (!) to find 254 255 # libuuid, slowing down program startup a lot). 255 - (./. + "/${sourceVersion.major}.${sourceVersion.minor}/no-ldconfig.patch") 256 + noldconfigPatch 256 257 # Make sure that the virtualenv activation scripts are 257 258 # owner-writable, so venvs can be recreated without permission 258 259 # errors.
+2 -103
pkgs/development/interpreters/python/default.nix
··· 8 8 , makeScopeWithSplicing 9 9 , pythonPackagesExtensions 10 10 , stdenv 11 - }: 11 + }@args: 12 12 13 13 (let 14 14 15 15 # Common passthru for all Python interpreters. 16 - passthruFun = 17 - { implementation 18 - , libPrefix 19 - , executable 20 - , sourceVersion 21 - , pythonVersion 22 - , packageOverrides 23 - , sitePackages 24 - , hasDistutilsCxxPatch 25 - , pythonOnBuildForBuild 26 - , pythonOnBuildForHost 27 - , pythonOnBuildForTarget 28 - , pythonOnHostForHost 29 - , pythonOnTargetForTarget 30 - , pythonAttr ? null 31 - , self # is pythonOnHostForTarget 32 - }: let 33 - pythonPackages = let 34 - ensurePythonModules = items: let 35 - exceptions = [ 36 - stdenv 37 - ]; 38 - providesSetupHook = lib.attrByPath [ "provides" "setupHook"] false; 39 - valid = value: pythonPackages.hasPythonModule value || providesSetupHook value || lib.elem value exceptions; 40 - func = name: value: 41 - if lib.isDerivation value then 42 - lib.extendDerivation (valid value || throw "${name} should use `buildPythonPackage` or `toPythonModule` if it is to be part of the Python packages set.") {} value 43 - else 44 - value; 45 - in lib.mapAttrs func items; 46 - in ensurePythonModules (callPackage 47 - # Function that when called 48 - # - imports python-packages.nix 49 - # - adds spliced package sets to the package set 50 - # - applies overrides from `packageOverrides` and `pythonPackagesOverlays`. 51 - ({ pkgs, stdenv, python, overrides }: let 52 - pythonPackagesFun = import ./python-packages-base.nix { 53 - inherit stdenv pkgs lib; 54 - python = self; 55 - }; 56 - otherSplices = { 57 - selfBuildBuild = pythonOnBuildForBuild.pkgs; 58 - selfBuildHost = pythonOnBuildForHost.pkgs; 59 - selfBuildTarget = pythonOnBuildForTarget.pkgs; 60 - selfHostHost = pythonOnHostForHost.pkgs; 61 - selfTargetTarget = pythonOnTargetForTarget.pkgs or {}; # There is no Python TargetTarget. 62 - }; 63 - hooks = import ./hooks/default.nix; 64 - keep = lib.extends hooks pythonPackagesFun; 65 - extra = _: {}; 66 - optionalExtensions = cond: as: lib.optionals cond as; 67 - pythonExtension = import ../../../top-level/python-packages.nix; 68 - python2Extension = import ../../../top-level/python2-packages.nix; 69 - extensions = lib.composeManyExtensions ([ 70 - pythonExtension 71 - ] ++ (optionalExtensions (!self.isPy3k) [ 72 - python2Extension 73 - ]) ++ pythonPackagesExtensions ++ [ 74 - overrides 75 - ]); 76 - aliases = self: super: lib.optionalAttrs config.allowAliases (import ../../../top-level/python-aliases.nix lib self super); 77 - in makeScopeWithSplicing 78 - otherSplices 79 - keep 80 - extra 81 - (lib.extends (lib.composeExtensions aliases extensions) keep)) 82 - { 83 - overrides = packageOverrides; 84 - python = self; 85 - }); 86 - in rec { 87 - isPy27 = pythonVersion == "2.7"; 88 - isPy37 = pythonVersion == "3.7"; 89 - isPy38 = pythonVersion == "3.8"; 90 - isPy39 = pythonVersion == "3.9"; 91 - isPy310 = pythonVersion == "3.10"; 92 - isPy311 = pythonVersion == "3.11"; 93 - isPy312 = pythonVersion == "3.12"; 94 - isPy2 = lib.strings.substring 0 1 pythonVersion == "2"; 95 - isPy3 = lib.strings.substring 0 1 pythonVersion == "3"; 96 - isPy3k = isPy3; 97 - isPyPy = lib.hasInfix "pypy" interpreter; 98 - 99 - buildEnv = callPackage ./wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; }; 100 - withPackages = import ./with-packages.nix { inherit buildEnv pythonPackages;}; 101 - pkgs = pythonPackages; 102 - interpreter = "${self}/bin/${executable}"; 103 - inherit executable implementation libPrefix pythonVersion sitePackages; 104 - inherit sourceVersion; 105 - pythonAtLeast = lib.versionAtLeast pythonVersion; 106 - pythonOlder = lib.versionOlder pythonVersion; 107 - inherit hasDistutilsCxxPatch; 108 - # TODO: rename to pythonOnBuild 109 - # Not done immediately because its likely used outside Nixpkgs. 110 - pythonForBuild = pythonOnBuildForHost.override { inherit packageOverrides; self = pythonForBuild; }; 111 - 112 - tests = callPackage ./tests.nix { 113 - python = self; 114 - }; 115 - 116 - inherit pythonAttr; 117 - }; 16 + passthruFun = import ./passthrufun.nix args; 118 17 119 18 sources = { 120 19 python310 = {
+103
pkgs/development/interpreters/python/passthrufun.nix
··· 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 = lib.extends hooks pythonPackagesFun; 51 + extra = _: {}; 52 + optionalExtensions = cond: as: lib.optionals cond as; 53 + pythonExtension = import ../../../top-level/python-packages.nix; 54 + python2Extension = import ../../../top-level/python2-packages.nix; 55 + extensions = lib.composeManyExtensions ([ 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 + otherSplices 65 + keep 66 + extra 67 + (lib.extends (lib.composeExtensions aliases extensions) keep)) 68 + { 69 + overrides = packageOverrides; 70 + python = self; 71 + }); 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; 84 + 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 + # TODO: rename to pythonOnBuild 95 + # Not done immediately because its likely used outside Nixpkgs. 96 + pythonForBuild = pythonOnBuildForHost.override { inherit packageOverrides; self = pythonForBuild; }; 97 + 98 + tests = callPackage ./tests.nix { 99 + python = self; 100 + }; 101 + 102 + inherit pythonAttr; 103 + }