2023-08-04 22:15:48 +00:00
|
|
|
self: dontUse: with self;
|
2019-07-17 18:36:47 +00:00
|
|
|
|
|
|
|
let
|
2023-11-06 01:38:24 +00:00
|
|
|
inherit (python) pythonOnBuildForHost;
|
|
|
|
pythonInterpreter = pythonOnBuildForHost.interpreter;
|
2023-08-04 22:15:48 +00:00
|
|
|
pythonSitePackages = python.sitePackages;
|
|
|
|
pythonCheckInterpreter = python.interpreter;
|
2019-07-17 18:36:47 +00:00
|
|
|
setuppy = ../run_setup.py;
|
2022-10-03 10:25:02 +00:00
|
|
|
in {
|
|
|
|
makePythonHook = args: pkgs.makeSetupHook ({passthru.provides.setupHook = true; } // args);
|
2019-07-17 18:36:47 +00:00
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
condaInstallHook = callPackage ({ makePythonHook, gnutar, lbzip2 }:
|
|
|
|
makePythonHook {
|
2021-05-16 08:13:39 +00:00
|
|
|
name = "conda-install-hook";
|
2023-01-01 20:10:24 +00:00
|
|
|
propagatedBuildInputs = [ gnutar lbzip2 ];
|
2021-05-16 08:13:39 +00:00
|
|
|
substitutions = {
|
|
|
|
inherit pythonSitePackages;
|
|
|
|
};
|
|
|
|
} ./conda-install-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
condaUnpackHook = callPackage ({ makePythonHook }:
|
|
|
|
makePythonHook {
|
2021-05-16 08:13:39 +00:00
|
|
|
name = "conda-unpack-hook";
|
2023-01-01 20:10:24 +00:00
|
|
|
propagatedBuildInputs = [];
|
2021-05-16 08:13:39 +00:00
|
|
|
} ./conda-unpack-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
eggBuildHook = callPackage ({ makePythonHook }:
|
|
|
|
makePythonHook {
|
2020-01-08 13:29:03 +00:00
|
|
|
name = "egg-build-hook.sh";
|
2023-01-01 20:10:24 +00:00
|
|
|
propagatedBuildInputs = [ ];
|
2020-01-08 13:29:03 +00:00
|
|
|
} ./egg-build-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
eggInstallHook = callPackage ({ makePythonHook, setuptools }:
|
|
|
|
makePythonHook {
|
2020-01-08 13:29:03 +00:00
|
|
|
name = "egg-install-hook.sh";
|
2023-01-01 20:10:24 +00:00
|
|
|
propagatedBuildInputs = [ setuptools ];
|
2020-01-08 13:29:03 +00:00
|
|
|
substitutions = {
|
|
|
|
inherit pythonInterpreter pythonSitePackages;
|
|
|
|
};
|
|
|
|
} ./egg-install-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
eggUnpackHook = callPackage ({ makePythonHook, }:
|
|
|
|
makePythonHook {
|
2020-01-08 13:29:03 +00:00
|
|
|
name = "egg-unpack-hook.sh";
|
2023-01-01 20:10:24 +00:00
|
|
|
propagatedBuildInputs = [ ];
|
2020-01-08 13:29:03 +00:00
|
|
|
} ./egg-unpack-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
pipBuildHook = callPackage ({ makePythonHook, pip, wheel }:
|
|
|
|
makePythonHook {
|
2019-07-17 18:36:47 +00:00
|
|
|
name = "pip-build-hook.sh";
|
2023-01-01 20:10:24 +00:00
|
|
|
propagatedBuildInputs = [ pip wheel ];
|
2019-07-17 18:36:47 +00:00
|
|
|
substitutions = {
|
|
|
|
inherit pythonInterpreter pythonSitePackages;
|
|
|
|
};
|
|
|
|
} ./pip-build-hook.sh) {};
|
|
|
|
|
2023-07-12 12:37:43 +00:00
|
|
|
pypaBuildHook = callPackage ({ makePythonHook, build, wheel }:
|
|
|
|
makePythonHook {
|
|
|
|
name = "pypa-build-hook.sh";
|
2023-09-11 11:49:53 +00:00
|
|
|
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.
|
|
|
|
passthru.tests = import ./pypa-build-hook-tests.nix {
|
2023-11-06 01:38:24 +00:00
|
|
|
inherit pythonOnBuildForHost runCommand;
|
2023-09-11 11:49:53 +00:00
|
|
|
};
|
2023-07-28 16:57:50 +00:00
|
|
|
} ./pypa-build-hook.sh) {
|
2023-11-06 01:38:24 +00:00
|
|
|
inherit (pythonOnBuildForHost.pkgs) build;
|
2023-07-28 16:57:50 +00:00
|
|
|
};
|
2023-07-12 12:37:43 +00:00
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
pipInstallHook = callPackage ({ makePythonHook, pip }:
|
|
|
|
makePythonHook {
|
2019-07-17 18:36:47 +00:00
|
|
|
name = "pip-install-hook";
|
2023-01-01 20:10:24 +00:00
|
|
|
propagatedBuildInputs = [ pip ];
|
2019-07-17 18:36:47 +00:00
|
|
|
substitutions = {
|
|
|
|
inherit pythonInterpreter pythonSitePackages;
|
|
|
|
};
|
|
|
|
} ./pip-install-hook.sh) {};
|
|
|
|
|
2023-07-28 00:30:31 +00:00
|
|
|
pypaInstallHook = callPackage ({ makePythonHook, installer }:
|
|
|
|
makePythonHook {
|
|
|
|
name = "pypa-install-hook";
|
|
|
|
propagatedBuildInputs = [ installer ];
|
|
|
|
substitutions = {
|
|
|
|
inherit pythonInterpreter pythonSitePackages;
|
|
|
|
};
|
|
|
|
} ./pypa-install-hook.sh) {
|
2023-11-06 01:38:24 +00:00
|
|
|
inherit (pythonOnBuildForHost.pkgs) installer;
|
2023-07-28 00:30:31 +00:00
|
|
|
};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
pytestCheckHook = callPackage ({ makePythonHook, pytest }:
|
|
|
|
makePythonHook {
|
2019-07-17 18:36:47 +00:00
|
|
|
name = "pytest-check-hook";
|
2023-01-01 20:10:24 +00:00
|
|
|
propagatedBuildInputs = [ pytest ];
|
2019-07-17 18:36:47 +00:00
|
|
|
substitutions = {
|
|
|
|
inherit pythonCheckInterpreter;
|
|
|
|
};
|
|
|
|
} ./pytest-check-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
pythonCatchConflictsHook = callPackage ({ makePythonHook, setuptools }:
|
|
|
|
makePythonHook {
|
2019-07-17 18:36:47 +00:00
|
|
|
name = "python-catch-conflicts-hook";
|
|
|
|
substitutions = {
|
2022-09-20 07:49:27 +00:00
|
|
|
inherit pythonInterpreter pythonSitePackages setuptools;
|
2019-07-17 18:36:47 +00:00
|
|
|
catchConflicts=../catch_conflicts/catch_conflicts.py;
|
|
|
|
};
|
|
|
|
} ./python-catch-conflicts-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
pythonImportsCheckHook = callPackage ({ makePythonHook }:
|
|
|
|
makePythonHook {
|
2019-07-17 18:36:47 +00:00
|
|
|
name = "python-imports-check-hook.sh";
|
|
|
|
substitutions = {
|
2022-05-29 03:35:59 +00:00
|
|
|
inherit pythonCheckInterpreter pythonSitePackages;
|
2019-07-17 18:36:47 +00:00
|
|
|
};
|
|
|
|
} ./python-imports-check-hook.sh) {};
|
|
|
|
|
2023-08-18 05:39:36 +00:00
|
|
|
pythonNamespacesHook = callPackage ({ makePythonHook, buildPackages }:
|
2022-10-03 10:25:02 +00:00
|
|
|
makePythonHook {
|
2020-03-17 21:29:47 +00:00
|
|
|
name = "python-namespaces-hook.sh";
|
|
|
|
substitutions = {
|
2023-08-18 05:39:36 +00:00
|
|
|
inherit pythonSitePackages;
|
|
|
|
inherit (buildPackages) findutils;
|
2020-03-17 21:29:47 +00:00
|
|
|
};
|
|
|
|
} ./python-namespaces-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
pythonOutputDistHook = callPackage ({ makePythonHook }:
|
|
|
|
makePythonHook {
|
2022-09-20 07:49:55 +00:00
|
|
|
name = "python-output-dist-hook";
|
|
|
|
} ./python-output-dist-hook.sh ) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
pythonRecompileBytecodeHook = callPackage ({ makePythonHook }:
|
|
|
|
makePythonHook {
|
2020-06-12 19:28:27 +00:00
|
|
|
name = "python-recompile-bytecode-hook";
|
|
|
|
substitutions = {
|
|
|
|
inherit pythonInterpreter pythonSitePackages;
|
|
|
|
compileArgs = lib.concatStringsSep " " (["-q" "-f" "-i -"] ++ lib.optionals isPy3k ["-j $NIX_BUILD_CORES"]);
|
|
|
|
bytecodeName = if isPy3k then "__pycache__" else "*.pyc";
|
|
|
|
};
|
|
|
|
} ./python-recompile-bytecode-hook.sh ) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
pythonRelaxDepsHook = callPackage ({ makePythonHook, wheel }:
|
|
|
|
makePythonHook {
|
pythonRelaxDepsHook: init
We have a common pattern here in nixpkgs for Python applications: when a
Python package ships with either a requirements.txt or setup.py file, we
generally end up having to modify its version restriction, otherwise we have
build failures since we package only one specific version of each package
normally.
However, this end up being done in a completely ad-hoc way: some people
use substituteInPlace, some others use sed, others uses patches, etc.
In many cases, the code ends up being buggy, so it may work in one
version and breaks on the next one. We can instead implement one
standard way of doing this, and trying to be a correct as possible.
So this is what this commit does: it implements a new build hook, that
when called will automatically patch the wheel file. This is one of the
most generic ways to patch Python dependencies, and should work in
multiple cases.
2022-04-28 19:58:59 +00:00
|
|
|
name = "python-relax-deps-hook";
|
|
|
|
substitutions = {
|
2023-08-02 06:34:49 +00:00
|
|
|
inherit pythonInterpreter pythonSitePackages wheel;
|
pythonRelaxDepsHook: init
We have a common pattern here in nixpkgs for Python applications: when a
Python package ships with either a requirements.txt or setup.py file, we
generally end up having to modify its version restriction, otherwise we have
build failures since we package only one specific version of each package
normally.
However, this end up being done in a completely ad-hoc way: some people
use substituteInPlace, some others use sed, others uses patches, etc.
In many cases, the code ends up being buggy, so it may work in one
version and breaks on the next one. We can instead implement one
standard way of doing this, and trying to be a correct as possible.
So this is what this commit does: it implements a new build hook, that
when called will automatically patch the wheel file. This is one of the
most generic ways to patch Python dependencies, and should work in
multiple cases.
2022-04-28 19:58:59 +00:00
|
|
|
};
|
|
|
|
} ./python-relax-deps-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
pythonRemoveBinBytecodeHook = callPackage ({ makePythonHook }:
|
|
|
|
makePythonHook {
|
2019-07-17 18:36:47 +00:00
|
|
|
name = "python-remove-bin-bytecode-hook";
|
|
|
|
} ./python-remove-bin-bytecode-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
pythonRemoveTestsDirHook = callPackage ({ makePythonHook }:
|
|
|
|
makePythonHook {
|
2020-03-02 17:37:05 +00:00
|
|
|
name = "python-remove-tests-dir-hook";
|
|
|
|
substitutions = {
|
|
|
|
inherit pythonSitePackages;
|
|
|
|
};
|
|
|
|
} ./python-remove-tests-dir-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
setuptoolsBuildHook = callPackage ({ makePythonHook, setuptools, wheel }:
|
|
|
|
makePythonHook {
|
2019-07-17 18:36:47 +00:00
|
|
|
name = "setuptools-setup-hook";
|
2023-01-01 20:10:24 +00:00
|
|
|
propagatedBuildInputs = [ setuptools wheel ];
|
2019-07-17 18:36:47 +00:00
|
|
|
substitutions = {
|
|
|
|
inherit pythonInterpreter pythonSitePackages setuppy;
|
|
|
|
};
|
|
|
|
} ./setuptools-build-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
setuptoolsCheckHook = callPackage ({ makePythonHook, setuptools }:
|
|
|
|
makePythonHook {
|
2019-07-17 18:36:47 +00:00
|
|
|
name = "setuptools-check-hook";
|
2023-01-01 20:10:24 +00:00
|
|
|
propagatedBuildInputs = [ setuptools ];
|
2019-07-17 18:36:47 +00:00
|
|
|
substitutions = {
|
|
|
|
inherit pythonCheckInterpreter setuppy;
|
|
|
|
};
|
|
|
|
} ./setuptools-check-hook.sh) {};
|
|
|
|
|
2023-01-26 15:19:05 +00:00
|
|
|
setuptoolsRustBuildHook = callPackage ({ makePythonHook, setuptools-rust, rust }:
|
|
|
|
makePythonHook {
|
|
|
|
name = "setuptools-rust-setup-hook";
|
|
|
|
propagatedBuildInputs = [ setuptools-rust ];
|
|
|
|
substitutions = {
|
|
|
|
pyLibDir = "${python}/lib/${python.libPrefix}";
|
|
|
|
cargoBuildTarget = rust.toRustTargetSpec stdenv.hostPlatform;
|
|
|
|
cargoLinkerVar = lib.toUpper (
|
|
|
|
builtins.replaceStrings ["-"] ["_"] (
|
|
|
|
rust.toRustTarget stdenv.hostPlatform));
|
|
|
|
targetLinker = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
|
|
|
|
};
|
|
|
|
} ./setuptools-rust-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
unittestCheckHook = callPackage ({ makePythonHook }:
|
|
|
|
makePythonHook {
|
2022-08-06 16:31:53 +00:00
|
|
|
name = "unittest-check-hook";
|
|
|
|
substitutions = {
|
|
|
|
inherit pythonCheckInterpreter;
|
|
|
|
};
|
|
|
|
} ./unittest-check-hook.sh) {};
|
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
venvShellHook = disabledIf (!isPy3k) (callPackage ({ makePythonHook, ensureNewerSourcesForZipFilesHook }:
|
|
|
|
makePythonHook {
|
2020-01-13 20:45:24 +00:00
|
|
|
name = "venv-shell-hook";
|
2023-01-01 20:10:24 +00:00
|
|
|
propagatedBuildInputs = [ ensureNewerSourcesForZipFilesHook ];
|
2020-01-13 20:45:24 +00:00
|
|
|
substitutions = {
|
|
|
|
inherit pythonInterpreter;
|
pythonRelaxDepsHook: init
We have a common pattern here in nixpkgs for Python applications: when a
Python package ships with either a requirements.txt or setup.py file, we
generally end up having to modify its version restriction, otherwise we have
build failures since we package only one specific version of each package
normally.
However, this end up being done in a completely ad-hoc way: some people
use substituteInPlace, some others use sed, others uses patches, etc.
In many cases, the code ends up being buggy, so it may work in one
version and breaks on the next one. We can instead implement one
standard way of doing this, and trying to be a correct as possible.
So this is what this commit does: it implements a new build hook, that
when called will automatically patch the wheel file. This is one of the
most generic ways to patch Python dependencies, and should work in
multiple cases.
2022-04-28 19:58:59 +00:00
|
|
|
};
|
|
|
|
} ./venv-shell-hook.sh) {});
|
2020-01-13 20:45:24 +00:00
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
wheelUnpackHook = callPackage ({ makePythonHook, wheel }:
|
|
|
|
makePythonHook {
|
2019-07-17 18:36:47 +00:00
|
|
|
name = "wheel-unpack-hook.sh";
|
2023-01-01 20:10:24 +00:00
|
|
|
propagatedBuildInputs = [ wheel ];
|
2019-07-17 18:36:47 +00:00
|
|
|
} ./wheel-unpack-hook.sh) {};
|
2021-08-28 15:52:28 +00:00
|
|
|
|
2022-10-03 10:25:02 +00:00
|
|
|
wrapPython = callPackage ../wrap-python.nix {
|
|
|
|
inherit (pkgs.buildPackages) makeWrapper;
|
|
|
|
};
|
|
|
|
|
2023-09-09 19:34:33 +00:00
|
|
|
sphinxHook = callPackage ({ makePythonHook, installShellFiles }:
|
2022-10-03 10:25:02 +00:00
|
|
|
makePythonHook {
|
2021-08-28 15:52:28 +00:00
|
|
|
name = "python${python.pythonVersion}-sphinx-hook";
|
2023-11-06 01:38:24 +00:00
|
|
|
propagatedBuildInputs = [ pythonOnBuildForHost.pkgs.sphinx installShellFiles ];
|
2021-08-28 15:52:28 +00:00
|
|
|
} ./sphinx-hook.sh) {};
|
2019-07-17 18:36:47 +00:00
|
|
|
}
|