core/pkgs/by-name/py/python/hooks/default.nix

345 lines
9.3 KiB
Nix
Raw Normal View History

2024-06-30 08:16:52 +00:00
self: dontUse:
with self;
2024-05-02 00:46:19 +00:00
let
inherit (python) pythonOnBuildForHost;
inherit (pkgs) runCommand;
pythonInterpreter = pythonOnBuildForHost.interpreter;
pythonSitePackages = python.sitePackages;
pythonCheckInterpreter = python.interpreter;
setuppy = ../run_setup.py;
2024-06-30 08:16:52 +00:00
in
{
makePythonHook =
let
defaultArgs = {
passthru.provides.setupHook = true;
};
in
args: pkgs.makeSetupHook (lib.recursiveUpdate defaultArgs args);
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
condaInstallHook = callPackage (
{
makePythonHook,
gnutar,
lbzip2,
}:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "conda-install-hook";
2024-06-30 08:16:52 +00:00
propagatedBuildInputs = [
gnutar
lbzip2
];
2024-05-02 00:46:19 +00:00
substitutions = {
inherit pythonSitePackages;
};
2024-06-30 08:16:52 +00:00
} ./conda-install-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
condaUnpackHook = callPackage (
{ makePythonHook }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "conda-unpack-hook";
2024-06-30 08:16:52 +00:00
propagatedBuildInputs = [ ];
} ./conda-unpack-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
eggBuildHook = callPackage (
{ makePythonHook }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "egg-build-hook.sh";
propagatedBuildInputs = [ ];
2024-06-30 08:16:52 +00:00
} ./egg-build-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
eggInstallHook = callPackage (
{ makePythonHook, setuptools }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "egg-install-hook.sh";
propagatedBuildInputs = [ setuptools ];
substitutions = {
inherit pythonInterpreter pythonSitePackages;
};
2024-06-30 08:16:52 +00:00
} ./egg-install-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
eggUnpackHook = callPackage (
{ makePythonHook }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "egg-unpack-hook.sh";
propagatedBuildInputs = [ ];
2024-06-30 08:16:52 +00:00
} ./egg-unpack-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pipBuildHook = callPackage (
{
makePythonHook,
pip,
wheel,
}:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "pip-build-hook.sh";
2024-06-30 08:16:52 +00:00
propagatedBuildInputs = [
pip
wheel
];
2024-05-02 00:46:19 +00:00
substitutions = {
inherit pythonInterpreter pythonSitePackages;
};
2024-06-30 08:16:52 +00:00
} ./pip-build-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pypaBuildHook = callPackage (
{
makePythonHook,
build,
wheel,
}:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "pypa-build-hook.sh";
propagatedBuildInputs = [ wheel ];
substitutions = {
inherit build;
};
# A test to ensure that this hook never propagates any of its dependencies
# into the build environment.
# This prevents false positive alerts raised by catchConflictsHook.
# Such conflicts don't happen within the standard nixpkgs python package
# set, but in downstream projects that build packages depending on other
# versions of this hook's dependencies.
2024-06-30 08:16:52 +00:00
passthru.tests = callPackage ./pypa-build-hook-test.nix { inherit pythonOnBuildForHost; };
} ./pypa-build-hook.sh
) { inherit (pythonOnBuildForHost.pkgs) build; };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pipInstallHook = callPackage (
{ makePythonHook, pip }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "pip-install-hook";
propagatedBuildInputs = [ pip ];
substitutions = {
inherit pythonInterpreter pythonSitePackages;
};
2024-06-30 08:16:52 +00:00
} ./pip-install-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pypaInstallHook = callPackage (
{ makePythonHook, installer }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "pypa-install-hook";
propagatedBuildInputs = [ installer ];
substitutions = {
inherit pythonInterpreter pythonSitePackages;
};
2024-06-30 08:16:52 +00:00
} ./pypa-install-hook.sh
) { inherit (pythonOnBuildForHost.pkgs) installer; };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pytestCheckHook = callPackage (
{ makePythonHook, pytest }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "pytest-check-hook";
propagatedBuildInputs = [ pytest ];
substitutions = {
inherit pythonCheckInterpreter;
};
2024-06-30 08:16:52 +00:00
} ./pytest-check-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pythonCatchConflictsHook = callPackage (
{ makePythonHook, setuptools }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "python-catch-conflicts-hook";
2024-06-30 08:16:52 +00:00
substitutions =
let
useLegacyHook = lib.versionOlder python.pythonVersion "3";
in
{
inherit pythonInterpreter pythonSitePackages;
catchConflicts =
if useLegacyHook then
../catch_conflicts/catch_conflicts_py2.py
else
../catch_conflicts/catch_conflicts.py;
}
// lib.optionalAttrs useLegacyHook { inherit setuptools; };
2024-05-02 00:46:19 +00:00
passthru.tests = import ./python-catch-conflicts-hook-tests.nix {
inherit pythonOnBuildForHost runCommand;
inherit (pkgs) coreutils gnugrep writeShellScript;
};
2024-06-30 08:16:52 +00:00
} ./python-catch-conflicts-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pythonImportsCheckHook = callPackage (
{ makePythonHook }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "python-imports-check-hook.sh";
substitutions = {
inherit pythonCheckInterpreter pythonSitePackages;
};
2024-06-30 08:16:52 +00:00
} ./python-imports-check-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pythonNamespacesHook = callPackage (
{ makePythonHook, buildPackages }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "python-namespaces-hook.sh";
substitutions = {
inherit pythonSitePackages;
inherit (buildPackages) findutils;
};
2024-06-30 08:16:52 +00:00
} ./python-namespaces-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pythonOutputDistHook = callPackage (
{ makePythonHook }:
makePythonHook { name = "python-output-dist-hook"; } ./python-output-dist-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pythonRecompileBytecodeHook = callPackage (
{ makePythonHook }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "python-recompile-bytecode-hook";
substitutions = {
inherit pythonInterpreter pythonSitePackages;
2024-06-30 08:16:52 +00:00
compileArgs = lib.concatStringsSep " " (
[
"-q"
"-f"
"-i -"
]
++ lib.optionals isPy3k [ "-j $NIX_BUILD_CORES" ]
);
2024-05-02 00:46:19 +00:00
bytecodeName = if isPy3k then "__pycache__" else "*.pyc";
};
2024-06-30 08:16:52 +00:00
} ./python-recompile-bytecode-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pythonRelaxDepsHook = callPackage (
{ makePythonHook, wheel }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "python-relax-deps-hook";
substitutions = {
inherit pythonInterpreter pythonSitePackages wheel;
};
2024-06-30 08:16:52 +00:00
} ./python-relax-deps-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pythonRemoveBinBytecodeHook = callPackage (
{ makePythonHook }:
makePythonHook { name = "python-remove-bin-bytecode-hook"; } ./python-remove-bin-bytecode-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pythonRemoveTestsDirHook = callPackage (
{ makePythonHook }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "python-remove-tests-dir-hook";
substitutions = {
inherit pythonSitePackages;
};
2024-06-30 08:16:52 +00:00
} ./python-remove-tests-dir-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
pythonRuntimeDepsCheckHook = callPackage (
{ makePythonHook, packaging }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "python-runtime-deps-check-hook.sh";
propagatedBuildInputs = [ packaging ];
substitutions = {
inherit pythonInterpreter pythonSitePackages;
hook = ./python-runtime-deps-check-hook.py;
};
2024-06-30 08:16:52 +00:00
} ./python-runtime-deps-check-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
setuptoolsBuildHook = callPackage (
{
makePythonHook,
setuptools,
wheel,
}:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "setuptools-build-hook";
2024-06-30 08:16:52 +00:00
propagatedBuildInputs = [
setuptools
wheel
];
2024-05-02 00:46:19 +00:00
substitutions = {
inherit pythonInterpreter setuppy;
# python2.pkgs.setuptools does not support parallelism
setuptools_has_parallel = setuptools != null && lib.versionAtLeast setuptools.version "69";
};
2024-06-30 08:16:52 +00:00
} ./setuptools-build-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
setuptoolsCheckHook = callPackage (
{ makePythonHook, setuptools }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "setuptools-check-hook";
propagatedBuildInputs = [ setuptools ];
substitutions = {
inherit pythonCheckInterpreter setuppy;
};
2024-06-30 08:16:52 +00:00
} ./setuptools-check-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
setuptoolsRustBuildHook = callPackage (
{ makePythonHook, setuptools-rust }:
2024-05-02 00:46:19 +00:00
makePythonHook {
2024-06-30 08:16:52 +00:00
name = "setuptools-rust-setup-hook";
propagatedBuildInputs = [ setuptools-rust ];
2024-05-02 00:46:19 +00:00
substitutions = {
2024-06-30 08:16:52 +00:00
pyLibDir = "${python}/lib/${python.libPrefix}";
cargoBuildTarget = stdenv.hostPlatform.rust.rustcTargetSpec;
cargoLinkerVar = stdenv.hostPlatform.rust.cargoEnvVarTarget;
targetLinker = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
2024-05-02 00:46:19 +00:00
};
2024-06-30 08:16:52 +00:00
} ./setuptools-rust-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
unittestCheckHook = callPackage (
{ makePythonHook }:
2024-05-02 00:46:19 +00:00
makePythonHook {
2024-06-30 08:16:52 +00:00
name = "unittest-check-hook";
2024-05-02 00:46:19 +00:00
substitutions = {
2024-06-30 08:16:52 +00:00
inherit pythonCheckInterpreter;
2024-05-02 00:46:19 +00:00
};
2024-06-30 08:16:52 +00:00
} ./unittest-check-hook.sh
) { };
venvShellHook = disabledIf (!isPy3k) (
callPackage (
{ makePythonHook, ensureNewerSourcesForZipFilesHook }:
makePythonHook {
name = "venv-shell-hook";
propagatedBuildInputs = [ ensureNewerSourcesForZipFilesHook ];
substitutions = {
inherit pythonInterpreter;
};
} ./venv-shell-hook.sh
) { }
);
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
wheelUnpackHook = callPackage (
{ makePythonHook, wheel }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "wheel-unpack-hook.sh";
propagatedBuildInputs = [ wheel ];
2024-06-30 08:16:52 +00:00
} ./wheel-unpack-hook.sh
) { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
wrapPython = callPackage ../wrap-python.nix { inherit (pkgs.buildPackages) makeWrapper; };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
sphinxHook = callPackage (
{ makePythonHook, installShellFiles }:
2024-05-02 00:46:19 +00:00
makePythonHook {
name = "python${python.pythonVersion}-sphinx-hook";
2024-06-30 08:16:52 +00:00
propagatedBuildInputs = [
pythonOnBuildForHost.pkgs.sphinx
installShellFiles
];
2024-05-02 00:46:19 +00:00
substitutions = {
sphinxBuild = "${pythonOnBuildForHost.pkgs.sphinx}/bin/sphinx-build";
};
2024-06-30 08:16:52 +00:00
} ./sphinx-hook.sh
) { };
2024-05-02 00:46:19 +00:00
}