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

231 lines
8.7 KiB
Nix
Raw Normal View History

2024-05-13 21:24:10 +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;
in {
2024-05-13 21:24:10 +00:00
makePythonHook = let defaultArgs = { passthru.provides.setupHook = true; };
2024-05-02 00:46:19 +00:00
in args: pkgs.makeSetupHook (lib.recursiveUpdate defaultArgs args);
condaInstallHook = callPackage ({ makePythonHook, gnutar, lbzip2 }:
makePythonHook {
name = "conda-install-hook";
propagatedBuildInputs = [ gnutar lbzip2 ];
2024-05-13 21:24:10 +00:00
substitutions = { inherit pythonSitePackages; };
} ./conda-install-hook.sh) { };
2024-05-02 00:46:19 +00:00
condaUnpackHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "conda-unpack-hook";
2024-05-13 21:24:10 +00:00
propagatedBuildInputs = [ ];
} ./conda-unpack-hook.sh) { };
2024-05-02 00:46:19 +00:00
eggBuildHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "egg-build-hook.sh";
propagatedBuildInputs = [ ];
2024-05-13 21:24:10 +00:00
} ./egg-build-hook.sh) { };
2024-05-02 00:46:19 +00:00
eggInstallHook = callPackage ({ makePythonHook, setuptools }:
makePythonHook {
name = "egg-install-hook.sh";
propagatedBuildInputs = [ setuptools ];
2024-05-13 21:24:10 +00:00
substitutions = { inherit pythonInterpreter pythonSitePackages; };
} ./egg-install-hook.sh) { };
2024-05-02 00:46:19 +00:00
eggUnpackHook = callPackage ({ makePythonHook, }:
makePythonHook {
name = "egg-unpack-hook.sh";
propagatedBuildInputs = [ ];
2024-05-13 21:24:10 +00:00
} ./egg-unpack-hook.sh) { };
2024-05-02 00:46:19 +00:00
pipBuildHook = callPackage ({ makePythonHook, pip, wheel }:
makePythonHook {
name = "pip-build-hook.sh";
propagatedBuildInputs = [ pip wheel ];
2024-05-13 21:24:10 +00:00
substitutions = { inherit pythonInterpreter pythonSitePackages; };
} ./pip-build-hook.sh) { };
2024-05-02 00:46:19 +00:00
pypaBuildHook = callPackage ({ makePythonHook, build, wheel }:
makePythonHook {
name = "pypa-build-hook.sh";
propagatedBuildInputs = [ wheel ];
2024-05-13 21:24:10 +00:00
substitutions = { inherit build; };
2024-05-02 00:46:19 +00:00
# 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.
passthru.tests = callPackage ./pypa-build-hook-test.nix {
inherit pythonOnBuildForHost;
};
2024-05-13 21:24:10 +00:00
} ./pypa-build-hook.sh) { inherit (pythonOnBuildForHost.pkgs) build; };
2024-05-02 00:46:19 +00:00
pipInstallHook = callPackage ({ makePythonHook, pip }:
makePythonHook {
name = "pip-install-hook";
propagatedBuildInputs = [ pip ];
2024-05-13 21:24:10 +00:00
substitutions = { inherit pythonInterpreter pythonSitePackages; };
} ./pip-install-hook.sh) { };
2024-05-02 00:46:19 +00:00
pypaInstallHook = callPackage ({ makePythonHook, installer }:
makePythonHook {
name = "pypa-install-hook";
propagatedBuildInputs = [ installer ];
2024-05-13 21:24:10 +00:00
substitutions = { inherit pythonInterpreter pythonSitePackages; };
}
./pypa-install-hook.sh) { inherit (pythonOnBuildForHost.pkgs) installer; };
2024-05-02 00:46:19 +00:00
pytestCheckHook = callPackage ({ makePythonHook, pytest }:
makePythonHook {
name = "pytest-check-hook";
propagatedBuildInputs = [ pytest ];
2024-05-13 21:24:10 +00:00
substitutions = { inherit pythonCheckInterpreter; };
} ./pytest-check-hook.sh) { };
2024-05-02 00:46:19 +00:00
pythonCatchConflictsHook = callPackage ({ makePythonHook, setuptools }:
makePythonHook {
name = "python-catch-conflicts-hook";
2024-05-13 21:24:10 +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-05-13 21:24:10 +00:00
} ./python-catch-conflicts-hook.sh) { };
2024-05-02 00:46:19 +00:00
pythonImportsCheckHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "python-imports-check-hook.sh";
2024-05-13 21:24:10 +00:00
substitutions = { inherit pythonCheckInterpreter pythonSitePackages; };
} ./python-imports-check-hook.sh) { };
2024-05-02 00:46:19 +00:00
pythonNamespacesHook = callPackage ({ makePythonHook, buildPackages }:
makePythonHook {
name = "python-namespaces-hook.sh";
substitutions = {
inherit pythonSitePackages;
inherit (buildPackages) findutils;
};
2024-05-13 21:24:10 +00:00
} ./python-namespaces-hook.sh) { };
2024-05-02 00:46:19 +00:00
pythonOutputDistHook = callPackage ({ makePythonHook }:
2024-05-13 21:24:10 +00:00
makePythonHook { name = "python-output-dist-hook"; }
./python-output-dist-hook.sh) { };
2024-05-02 00:46:19 +00:00
pythonRecompileBytecodeHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "python-recompile-bytecode-hook";
substitutions = {
inherit pythonInterpreter pythonSitePackages;
2024-05-13 21:24:10 +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-05-13 21:24:10 +00:00
} ./python-recompile-bytecode-hook.sh) { };
2024-05-02 00:46:19 +00:00
pythonRelaxDepsHook = callPackage ({ makePythonHook, wheel }:
makePythonHook {
name = "python-relax-deps-hook";
2024-05-13 21:24:10 +00:00
substitutions = { inherit pythonInterpreter pythonSitePackages wheel; };
} ./python-relax-deps-hook.sh) { };
2024-05-02 00:46:19 +00:00
pythonRemoveBinBytecodeHook = callPackage ({ makePythonHook }:
2024-05-13 21:24:10 +00:00
makePythonHook { name = "python-remove-bin-bytecode-hook"; }
./python-remove-bin-bytecode-hook.sh) { };
2024-05-02 00:46:19 +00:00
pythonRemoveTestsDirHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "python-remove-tests-dir-hook";
2024-05-13 21:24:10 +00:00
substitutions = { inherit pythonSitePackages; };
} ./python-remove-tests-dir-hook.sh) { };
2024-05-02 00:46:19 +00:00
pythonRuntimeDepsCheckHook = callPackage ({ makePythonHook, packaging }:
makePythonHook {
name = "python-runtime-deps-check-hook.sh";
propagatedBuildInputs = [ packaging ];
substitutions = {
inherit pythonInterpreter pythonSitePackages;
hook = ./python-runtime-deps-check-hook.py;
};
2024-05-13 21:24:10 +00:00
} ./python-runtime-deps-check-hook.sh) { };
2024-05-02 00:46:19 +00:00
setuptoolsBuildHook = callPackage ({ makePythonHook, setuptools, wheel }:
makePythonHook {
name = "setuptools-build-hook";
propagatedBuildInputs = [ setuptools wheel ];
substitutions = {
inherit pythonInterpreter setuppy;
# python2.pkgs.setuptools does not support parallelism
2024-05-13 21:24:10 +00:00
setuptools_has_parallel = setuptools != null
&& lib.versionAtLeast setuptools.version "69";
2024-05-02 00:46:19 +00:00
};
2024-05-13 21:24:10 +00:00
} ./setuptools-build-hook.sh) { };
2024-05-02 00:46:19 +00:00
setuptoolsCheckHook = callPackage ({ makePythonHook, setuptools }:
makePythonHook {
name = "setuptools-check-hook";
propagatedBuildInputs = [ setuptools ];
2024-05-13 21:24:10 +00:00
substitutions = { inherit pythonCheckInterpreter setuppy; };
} ./setuptools-check-hook.sh) { };
setuptoolsRustBuildHook = callPackage ({ makePythonHook, setuptools-rust }:
makePythonHook {
name = "setuptools-rust-setup-hook";
propagatedBuildInputs = [ setuptools-rust ];
2024-05-02 00:46:19 +00:00
substitutions = {
2024-05-13 21:24:10 +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-05-13 21:24:10 +00:00
} ./setuptools-rust-hook.sh) { };
2024-05-02 00:46:19 +00:00
unittestCheckHook = callPackage ({ makePythonHook }:
makePythonHook {
name = "unittest-check-hook";
2024-05-13 21:24:10 +00:00
substitutions = { inherit pythonCheckInterpreter; };
} ./unittest-check-hook.sh) { };
2024-05-02 00:46:19 +00:00
2024-05-13 21:24:10 +00:00
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
wheelUnpackHook = callPackage ({ makePythonHook, wheel }:
makePythonHook {
name = "wheel-unpack-hook.sh";
propagatedBuildInputs = [ wheel ];
2024-05-13 21:24:10 +00:00
} ./wheel-unpack-hook.sh) { };
2024-05-02 00:46:19 +00:00
wrapPython = callPackage ../wrap-python.nix {
inherit (pkgs.buildPackages) makeWrapper;
};
sphinxHook = callPackage ({ makePythonHook, installShellFiles }:
makePythonHook {
name = "python${python.pythonVersion}-sphinx-hook";
2024-05-13 21:24:10 +00:00
propagatedBuildInputs =
[ pythonOnBuildForHost.pkgs.sphinx installShellFiles ];
2024-05-02 00:46:19 +00:00
substitutions = {
sphinxBuild = "${pythonOnBuildForHost.pkgs.sphinx}/bin/sphinx-build";
};
2024-05-13 21:24:10 +00:00
} ./sphinx-hook.sh) { };
2024-05-02 00:46:19 +00:00
}