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.
This commit is contained in:
Frederik Rietdijk
2022-10-27 10:03:16 +02:00
committed by Frederik Rietdijk
parent 99bcead8dd
commit 33d12e5f0b
6 changed files with 185 additions and 242 deletions
@@ -1,21 +1,15 @@
# Hooks for building Python packages.
{ python
, lib
, makeSetupHook
, disabledIf
, isPy3k
}:
self: super: with self;
let
callPackage = python.pythonForBuild.pkgs.callPackage;
pythonInterpreter = python.pythonForBuild.interpreter;
pythonSitePackages = python.sitePackages;
pythonCheckInterpreter = python.interpreter;
pythonInterpreter = super.python.pythonForBuild.interpreter;
pythonSitePackages = super.python.sitePackages;
pythonCheckInterpreter = super.python.interpreter;
setuppy = ../run_setup.py;
in rec {
in {
makePythonHook = args: pkgs.makeSetupHook ({passthru.provides.setupHook = true; } // args);
condaInstallHook = callPackage ({ gnutar, lbzip2 }:
makeSetupHook {
condaInstallHook = callPackage ({ makePythonHook, gnutar, lbzip2 }:
makePythonHook {
name = "conda-install-hook";
deps = [ gnutar lbzip2 ];
substitutions = {
@@ -23,20 +17,20 @@ in rec {
};
} ./conda-install-hook.sh) {};
condaUnpackHook = callPackage ({}:
makeSetupHook {
condaUnpackHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "conda-unpack-hook";
deps = [];
} ./conda-unpack-hook.sh) {};
eggBuildHook = callPackage ({ }:
makeSetupHook {
eggBuildHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "egg-build-hook.sh";
deps = [ ];
} ./egg-build-hook.sh) {};
eggInstallHook = callPackage ({ setuptools }:
makeSetupHook {
eggInstallHook = callPackage ({ makePythonHook, setuptools }:
makePythonHook {
name = "egg-install-hook.sh";
deps = [ setuptools ];
substitutions = {
@@ -44,14 +38,14 @@ in rec {
};
} ./egg-install-hook.sh) {};
eggUnpackHook = callPackage ({ }:
makeSetupHook {
eggUnpackHook = callPackage ({ makePythonHook, }:
makePythonHook {
name = "egg-unpack-hook.sh";
deps = [ ];
} ./egg-unpack-hook.sh) {};
flitBuildHook = callPackage ({ flit }:
makeSetupHook {
flitBuildHook = callPackage ({ makePythonHook, flit }:
makePythonHook {
name = "flit-build-hook";
deps = [ flit ];
substitutions = {
@@ -59,8 +53,8 @@ in rec {
};
} ./flit-build-hook.sh) {};
pipBuildHook = callPackage ({ pip, wheel }:
makeSetupHook {
pipBuildHook = callPackage ({ makePythonHook, pip, wheel }:
makePythonHook {
name = "pip-build-hook.sh";
deps = [ pip wheel ];
substitutions = {
@@ -68,8 +62,8 @@ in rec {
};
} ./pip-build-hook.sh) {};
pipInstallHook = callPackage ({ pip }:
makeSetupHook {
pipInstallHook = callPackage ({ makePythonHook, pip }:
makePythonHook {
name = "pip-install-hook";
deps = [ pip ];
substitutions = {
@@ -77,8 +71,8 @@ in rec {
};
} ./pip-install-hook.sh) {};
pytestCheckHook = callPackage ({ pytest }:
makeSetupHook {
pytestCheckHook = callPackage ({ makePythonHook, pytest }:
makePythonHook {
name = "pytest-check-hook";
deps = [ pytest ];
substitutions = {
@@ -86,8 +80,8 @@ in rec {
};
} ./pytest-check-hook.sh) {};
pythonCatchConflictsHook = callPackage ({ setuptools }:
makeSetupHook {
pythonCatchConflictsHook = callPackage ({ makePythonHook, setuptools }:
makePythonHook {
name = "python-catch-conflicts-hook";
substitutions = {
inherit pythonInterpreter pythonSitePackages setuptools;
@@ -95,29 +89,29 @@ in rec {
};
} ./python-catch-conflicts-hook.sh) {};
pythonImportsCheckHook = callPackage ({}:
makeSetupHook {
pythonImportsCheckHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "python-imports-check-hook.sh";
substitutions = {
inherit pythonCheckInterpreter;
};
} ./python-imports-check-hook.sh) {};
pythonNamespacesHook = callPackage ({ findutils }:
makeSetupHook {
pythonNamespacesHook = callPackage ({ makePythonHook, findutils }:
makePythonHook {
name = "python-namespaces-hook.sh";
substitutions = {
inherit pythonSitePackages findutils;
};
} ./python-namespaces-hook.sh) {};
pythonOutputDistHook = callPackage ({ }:
makeSetupHook {
pythonOutputDistHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "python-output-dist-hook";
} ./python-output-dist-hook.sh ) {};
pythonRecompileBytecodeHook = callPackage ({ }:
makeSetupHook {
pythonRecompileBytecodeHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "python-recompile-bytecode-hook";
substitutions = {
inherit pythonInterpreter pythonSitePackages;
@@ -126,8 +120,8 @@ in rec {
};
} ./python-recompile-bytecode-hook.sh ) {};
pythonRelaxDepsHook = callPackage ({ wheel }:
makeSetupHook {
pythonRelaxDepsHook = callPackage ({ makePythonHook, wheel }:
makePythonHook {
name = "python-relax-deps-hook";
deps = [ wheel ];
substitutions = {
@@ -135,21 +129,21 @@ in rec {
};
} ./python-relax-deps-hook.sh) {};
pythonRemoveBinBytecodeHook = callPackage ({ }:
makeSetupHook {
pythonRemoveBinBytecodeHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "python-remove-bin-bytecode-hook";
} ./python-remove-bin-bytecode-hook.sh) {};
pythonRemoveTestsDirHook = callPackage ({ }:
makeSetupHook {
pythonRemoveTestsDirHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "python-remove-tests-dir-hook";
substitutions = {
inherit pythonSitePackages;
};
} ./python-remove-tests-dir-hook.sh) {};
setuptoolsBuildHook = callPackage ({ setuptools, wheel }:
makeSetupHook {
setuptoolsBuildHook = callPackage ({ makePythonHook, setuptools, wheel }:
makePythonHook {
name = "setuptools-setup-hook";
deps = [ setuptools wheel ];
substitutions = {
@@ -157,8 +151,8 @@ in rec {
};
} ./setuptools-build-hook.sh) {};
setuptoolsCheckHook = callPackage ({ setuptools }:
makeSetupHook {
setuptoolsCheckHook = callPackage ({ makePythonHook, setuptools }:
makePythonHook {
name = "setuptools-check-hook";
deps = [ setuptools ];
substitutions = {
@@ -166,16 +160,16 @@ in rec {
};
} ./setuptools-check-hook.sh) {};
unittestCheckHook = callPackage ({ }:
makeSetupHook {
unittestCheckHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "unittest-check-hook";
substitutions = {
inherit pythonCheckInterpreter;
};
} ./unittest-check-hook.sh) {};
venvShellHook = disabledIf (!isPy3k) (callPackage ({ ensureNewerSourcesForZipFilesHook }:
makeSetupHook {
venvShellHook = disabledIf (!isPy3k) (callPackage ({ makePythonHook, ensureNewerSourcesForZipFilesHook }:
makePythonHook {
name = "venv-shell-hook";
deps = [ ensureNewerSourcesForZipFilesHook ];
substitutions = {
@@ -183,14 +177,18 @@ in rec {
};
} ./venv-shell-hook.sh) {});
wheelUnpackHook = callPackage ({ wheel }:
makeSetupHook {
wheelUnpackHook = callPackage ({ makePythonHook, wheel }:
makePythonHook {
name = "wheel-unpack-hook.sh";
deps = [ wheel ];
} ./wheel-unpack-hook.sh) {};
sphinxHook = callPackage ({ sphinx, installShellFiles }:
makeSetupHook {
wrapPython = callPackage ../wrap-python.nix {
inherit (pkgs.buildPackages) makeWrapper;
};
sphinxHook = callPackage ({ makePythonHook, sphinx, installShellFiles }:
makePythonHook {
name = "python${python.pythonVersion}-sphinx-hook";
deps = [ sphinx installShellFiles ];
} ./sphinx-hook.sh) {};