2020-02-23 13:52:57 +00:00
|
|
|
{ python
|
2023-03-23 13:35:41 +13:00
|
|
|
, stdenv
|
2020-11-27 04:27:13 +01:00
|
|
|
, buildPackages
|
2020-02-23 13:52:57 +00:00
|
|
|
, makeSetupHook
|
2020-04-01 00:10:00 +01:00
|
|
|
, wheel
|
|
|
|
, pip
|
2022-05-08 19:01:23 +02:00
|
|
|
, pkgs
|
2023-03-02 08:21:47 -05:00
|
|
|
, lib
|
2020-02-23 13:52:57 +00:00
|
|
|
}:
|
|
|
|
let
|
2023-03-02 08:21:47 -05:00
|
|
|
inherit (python.pythonForBuild.pkgs) callPackage;
|
2020-02-23 13:52:57 +00:00
|
|
|
pythonInterpreter = python.pythonForBuild.interpreter;
|
2020-04-01 00:10:00 +01:00
|
|
|
pythonSitePackages = python.sitePackages;
|
2022-05-09 17:27:24 +02:00
|
|
|
|
2022-05-08 19:01:23 +02:00
|
|
|
nonOverlayedPython = pkgs.python3.pythonForBuild.withPackages (ps: [ ps.tomlkit ]);
|
2022-05-09 17:27:24 +02:00
|
|
|
makeRemoveSpecialDependenciesHook = { fields, kind }:
|
|
|
|
nonOverlayedPython.pkgs.callPackage
|
|
|
|
(
|
2023-03-02 08:21:47 -05:00
|
|
|
_:
|
2022-05-09 17:27:24 +02:00
|
|
|
makeSetupHook
|
|
|
|
{
|
|
|
|
name = "remove-path-dependencies.sh";
|
|
|
|
substitutions = {
|
|
|
|
# NOTE: We have to use a non-overlayed Python here because otherwise we run into an infinite recursion
|
|
|
|
# because building of tomlkit and its dependencies also use these hooks.
|
|
|
|
pythonPath = nonOverlayedPython.pkgs.makePythonPath [ nonOverlayedPython ];
|
|
|
|
pythonInterpreter = nonOverlayedPython.interpreter;
|
|
|
|
pyprojectPatchScript = "${./pyproject-without-special-deps.py}";
|
2023-03-02 08:21:47 -05:00
|
|
|
inherit fields;
|
|
|
|
inherit kind;
|
2022-05-09 17:27:24 +02:00
|
|
|
};
|
|
|
|
} ./remove-special-dependencies.sh
|
|
|
|
)
|
|
|
|
{ };
|
2023-03-02 08:21:47 -05:00
|
|
|
makeSetupHookArgs = deps:
|
2023-03-24 14:31:25 +13:00
|
|
|
if lib.elem "propagatedBuildInputs" (builtins.attrNames (builtins.functionArgs makeSetupHook)) then
|
|
|
|
{ propagatedBuildInputs = deps; }
|
2023-03-02 08:21:47 -05:00
|
|
|
else
|
2023-03-24 14:31:25 +13:00
|
|
|
{ inherit deps; };
|
2020-02-23 13:52:57 +00:00
|
|
|
in
|
|
|
|
{
|
2022-05-09 17:27:24 +02:00
|
|
|
removePathDependenciesHook = makeRemoveSpecialDependenciesHook {
|
|
|
|
fields = [ "path" ];
|
|
|
|
kind = "path";
|
|
|
|
};
|
|
|
|
|
|
|
|
removeGitDependenciesHook = makeRemoveSpecialDependenciesHook {
|
|
|
|
fields = [ "git" "branch" "rev" "tag" ];
|
|
|
|
kind = "git";
|
|
|
|
};
|
2021-11-07 09:50:59 -05:00
|
|
|
|
2020-02-23 13:52:57 +00:00
|
|
|
|
2020-04-29 14:12:59 +01:00
|
|
|
pipBuildHook = callPackage
|
|
|
|
(
|
|
|
|
{ pip, wheel }:
|
2020-05-19 21:06:02 +01:00
|
|
|
makeSetupHook
|
2023-03-02 08:21:47 -05:00
|
|
|
({
|
2020-05-19 21:06:02 +01:00
|
|
|
name = "pip-build-hook.sh";
|
|
|
|
substitutions = {
|
|
|
|
inherit pythonInterpreter pythonSitePackages;
|
|
|
|
};
|
2023-03-02 08:21:47 -05:00
|
|
|
} // (makeSetupHookArgs [ pip wheel ])) ./pip-build-hook.sh
|
2020-10-01 19:08:57 +02:00
|
|
|
)
|
|
|
|
{ };
|
2020-04-01 00:10:00 +01:00
|
|
|
|
2020-04-29 14:12:59 +01:00
|
|
|
poetry2nixFixupHook = callPackage
|
|
|
|
(
|
2023-03-02 08:21:47 -05:00
|
|
|
_:
|
2020-05-19 21:06:02 +01:00
|
|
|
makeSetupHook
|
|
|
|
{
|
|
|
|
name = "fixup-hook.sh";
|
2022-02-05 21:32:09 +12:00
|
|
|
substitutions = {
|
|
|
|
inherit pythonSitePackages;
|
|
|
|
filenames = builtins.concatStringsSep " " [
|
|
|
|
"pyproject.toml"
|
|
|
|
"README.md"
|
2022-09-07 07:55:10 +12:00
|
|
|
"LICENSE"
|
2022-02-05 21:32:09 +12:00
|
|
|
];
|
|
|
|
};
|
2020-05-19 21:06:02 +01:00
|
|
|
} ./fixup-hook.sh
|
2020-10-01 19:08:57 +02:00
|
|
|
)
|
|
|
|
{ };
|
2020-02-28 19:45:23 +00:00
|
|
|
|
2023-03-23 13:35:41 +13:00
|
|
|
# As of 2023-03 a newer version of packaging introduced a new behaviour where python-requires
|
|
|
|
# cannot contain version wildcards. This behaviour is complaint with PEP440
|
|
|
|
#
|
|
|
|
# The wildcards are a no-op anyway so we can work around this issue by just dropping the precision down to the last known number.
|
|
|
|
poetry2nixPythonRequiresPatchHook = callPackage
|
|
|
|
(
|
|
|
|
_:
|
|
|
|
let
|
|
|
|
# Python pre 3.9 does not contain the ast.unparse method.
|
|
|
|
# We can extract this from Python 3.8 for any
|
|
|
|
unparser = stdenv.mkDerivation {
|
|
|
|
name = "${python.name}-astunparse";
|
|
|
|
inherit (python) src;
|
|
|
|
dontConfigure = true;
|
|
|
|
dontBuild = true;
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/poetry2nix_astunparse
|
|
|
|
cp ./Tools/parser/unparse.py $out/poetry2nix_astunparse/__init__.py
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
pythonPath =
|
|
|
|
[ ]
|
|
|
|
++ lib.optional (lib.versionOlder python.version "3.9") unparser;
|
|
|
|
|
|
|
|
in
|
|
|
|
makeSetupHook
|
|
|
|
{
|
|
|
|
name = "require-python-patch-hook.sh";
|
|
|
|
substitutions = {
|
|
|
|
inherit pythonInterpreter pythonPath;
|
|
|
|
patchScript = ./python-requires-patch-hook.py;
|
|
|
|
};
|
|
|
|
} ./python-requires-patch-hook.sh
|
|
|
|
)
|
|
|
|
{ };
|
|
|
|
|
2020-08-17 03:34:58 +02:00
|
|
|
# When the "wheel" package itself is a wheel the nixpkgs hook (which pulls in "wheel") leads to infinite recursion
|
|
|
|
# It doesn't _really_ depend on wheel though, it just copies the wheel.
|
|
|
|
wheelUnpackHook = callPackage
|
2023-03-02 08:21:47 -05:00
|
|
|
(_:
|
2020-08-17 03:34:58 +02:00
|
|
|
makeSetupHook
|
|
|
|
{
|
|
|
|
name = "wheel-unpack-hook.sh";
|
|
|
|
} ./wheel-unpack-hook.sh
|
2020-10-01 19:08:57 +02:00
|
|
|
)
|
|
|
|
{ };
|
2020-02-23 13:52:57 +00:00
|
|
|
}
|