diff options
author | Frederik Rietdijk <fridh@fridh.nl> | 2022-10-03 12:25:02 +0200 |
---|---|---|
committer | Frederik Rietdijk <freddyrietdijk@fridh.nl> | 2022-10-27 10:03:16 +0200 |
commit | 33d12e5f0bcc61d8e12d07fd73ad981f0d42ab59 (patch) | |
tree | 4256db333001b343f095dc99789cb74b5d290dec /pkgs/development/interpreters/python/default.nix | |
parent | 99bcead8dd4698a7bb118b52aaf986074e66acf5 (diff) |
pythonPackages: ensure all derivations provide python modules
This adds a test to ensure no new uses of `buildPythonApplication` can be added to `python-packages.nix`. Python packages can be grouped into two groups: 1) applications and 2) packages providing importable modules. In `python-packages.nix` we only want to have 2). 1) should be in the top-level package set. To achieve this, all setup hooks need to be marked as being a setup hook. For the setup hooks in the Python packages set this is done by creating a new builder, `makePythonHook`. Because there were issues with splicing, the file importing all the hooks is converted to an extension. All non-packages were moved out of `python-packages.nix` into `python-packages-base.nix`. The `keep` argument to `makeScopeWithSplicing was cleaned up as well; there is no need to keep this one manually in sync reducing the risk of breaking cross-compilation.
Diffstat (limited to 'pkgs/development/interpreters/python/default.nix')
-rw-r--r-- | pkgs/development/interpreters/python/default.nix | 62 |
1 files changed, 20 insertions, 42 deletions
diff --git a/pkgs/development/interpreters/python/default.nix b/pkgs/development/interpreters/python/default.nix index f770f3fb52d75..1f425d60c63b6 100644 --- a/pkgs/development/interpreters/python/default.nix +++ b/pkgs/development/interpreters/python/default.nix @@ -31,13 +31,19 @@ , pythonAttr ? null , self # is pythonOnHostForTarget }: let - pythonPackages = callPackage + pythonPackages = let + ensurePythonModules = items: let + providesSetupHook = lib.attrByPath [ "provides" "setupHook"] false; + notValid = value: (lib.isDerivation value) && !((pythonPackages.hasPythonModule value) || (providesSetupHook value)); + func = name: value: if !(notValid value) then value else throw "${name} should use `buildPythonPackage` or `toPythonModule` if it is to be part of the Python packages set."; + in lib.mapAttrs func items; + in ensurePythonModules (callPackage # Function that when called # - imports python-packages.nix # - adds spliced package sets to the package set # - applies overrides from `packageOverrides` and `pythonPackagesOverlays`. ({ pkgs, stdenv, python, overrides }: let - pythonPackagesFun = import ../../../top-level/python-packages.nix { + pythonPackagesFun = import ./python-packages-base.nix { inherit stdenv pkgs lib; python = self; }; @@ -48,47 +54,19 @@ selfHostHost = pythonOnHostForHost.pkgs; selfTargetTarget = pythonOnTargetForTarget.pkgs or {}; # There is no Python TargetTarget. }; - keep = self: { - # TODO maybe only define these here so nothing is needed to be kept in sync. - inherit (self) - isPy27 isPy35 isPy36 isPy37 isPy38 isPy39 isPy310 isPy3k isPyPy pythonAtLeast pythonOlder - python bootstrapped-pip buildPythonPackage buildPythonApplication - fetchPypi - hasPythonModule requiredPythonModules makePythonPath disabledIf - toPythonModule toPythonApplication - buildSetupcfg - - condaInstallHook - condaUnpackHook - eggUnpackHook - eggBuildHook - eggInstallHook - flitBuildHook - pipBuildHook - pipInstallHook - pytestCheckHook - pythonCatchConflictsHook - pythonImportsCheckHook - pythonNamespacesHook - pythonRecompileBytecodeHook - pythonRemoveBinBytecodeHook - pythonRemoveTestsDirHook - setuptoolsBuildHook - setuptoolsCheckHook - venvShellHook - wheelUnpackHook - - wrapPython - - pythonPackages - - recursivePthLoader - ; - }; + hooks = import ./hooks/default.nix; + keep = lib.extends hooks pythonPackagesFun; extra = _: {}; optionalExtensions = cond: as: if cond then as else []; + pythonExtension = import ../../../top-level/python-packages.nix; python2Extension = import ../../../top-level/python2-packages.nix; - extensions = lib.composeManyExtensions ((optionalExtensions (!self.isPy3k) [python2Extension]) ++ pythonPackagesExtensions ++ [ overrides ]); + extensions = lib.composeManyExtensions ([ + pythonExtension + ] ++ (optionalExtensions (!self.isPy3k) [ + python2Extension + ]) ++ pythonPackagesExtensions ++ [ + overrides + ]); aliases = self: super: lib.optionalAttrs config.allowAliases (import ../../../top-level/python-aliases.nix lib self super); in lib.makeScopeWithSplicing splicePackages @@ -96,11 +74,11 @@ otherSplices keep extra - (lib.extends (lib.composeExtensions aliases extensions) pythonPackagesFun)) + (lib.extends (lib.composeExtensions aliases extensions) keep)) { overrides = packageOverrides; python = self; - }; + }); in rec { isPy27 = pythonVersion == "2.7"; isPy35 = pythonVersion == "3.5"; |