2023-10-23 04:08:09 -04:00
|
|
|
{ python, stdenv, makeSetupHook, pkgs, lib }:
|
2020-02-23 13:52:57 +00:00
|
|
|
let
|
2023-10-23 04:08:09 -04:00
|
|
|
inherit (python) pythonForBuild;
|
|
|
|
inherit (pythonForBuild.pkgs) callPackage;
|
|
|
|
pythonInterpreter = 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 ]);
|
2023-08-29 21:22:31 -07:00
|
|
|
makeRemoveSpecialDependenciesHook =
|
|
|
|
{ fields
|
|
|
|
, kind
|
2023-08-29 22:20:12 -07:00
|
|
|
/*
|
|
|
|
* A script that takes in --fields-to-remove <fields, nargs="*">, transforms
|
|
|
|
* stdin pyproject.toml onto stdout pyproject.toml
|
|
|
|
*/
|
2023-08-29 21:22:31 -07:00
|
|
|
, pyprojectPatchScript ? "${./pyproject-without-special-deps.py}"
|
|
|
|
}:
|
2022-05-09 17:27:24 +02:00
|
|
|
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;
|
2023-08-29 21:22:31 -07:00
|
|
|
inherit pyprojectPatchScript;
|
2023-03-02 08:21:47 -05:00
|
|
|
inherit fields;
|
|
|
|
inherit kind;
|
2022-05-09 17:27:24 +02:00
|
|
|
};
|
2023-07-31 20:07:01 -04:00
|
|
|
}
|
|
|
|
./remove-special-dependencies.sh
|
2022-05-09 17:27:24 +02:00
|
|
|
)
|
|
|
|
{ };
|
2023-03-02 08:21:47 -05:00
|
|
|
makeSetupHookArgs = deps:
|
2023-07-31 20:07:01 -04:00
|
|
|
if lib.elem "propagatedBuildInputs" (builtins.attrNames (builtins.functionArgs makeSetupHook))
|
|
|
|
then { propagatedBuildInputs = deps; }
|
|
|
|
else { 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
|
|
|
|
2023-08-29 21:22:31 -07:00
|
|
|
removeWheelUrlDependenciesHook = makeRemoveSpecialDependenciesHook {
|
|
|
|
fields = [ "url" ];
|
|
|
|
kind = "wheel-url";
|
|
|
|
pyprojectPatchScript = "${./pyproject-without-url-whl.py}";
|
|
|
|
};
|
|
|
|
|
2023-07-31 20:07:01 -04:00
|
|
|
pipBuildHook =
|
|
|
|
callPackage
|
|
|
|
(
|
2023-10-23 04:08:09 -04:00
|
|
|
{ pip, wheel }:
|
2023-07-31 20:07:01 -04:00
|
|
|
makeSetupHook
|
|
|
|
({
|
|
|
|
name = "pip-build-hook.sh";
|
|
|
|
substitutions = {
|
|
|
|
inherit pythonInterpreter pythonSitePackages;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// (makeSetupHookArgs [ pip wheel ]))
|
|
|
|
./pip-build-hook.sh
|
|
|
|
)
|
|
|
|
{ };
|
2020-02-23 13:52:57 +00:00
|
|
|
|
2023-07-31 20:07:01 -04:00
|
|
|
poetry2nixFixupHook =
|
|
|
|
callPackage
|
|
|
|
(
|
|
|
|
_:
|
|
|
|
makeSetupHook
|
|
|
|
{
|
|
|
|
name = "fixup-hook.sh";
|
|
|
|
substitutions = {
|
|
|
|
inherit pythonSitePackages;
|
|
|
|
filenames = builtins.concatStringsSep " " [
|
|
|
|
"pyproject.toml"
|
|
|
|
"README.md"
|
|
|
|
"LICENSE"
|
|
|
|
"CHANGELOG.md"
|
|
|
|
"CHANGES.md"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
./fixup-hook.sh
|
|
|
|
)
|
|
|
|
{ };
|
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.
|
2023-07-31 20:07:01 -04:00
|
|
|
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;
|
2023-03-23 13:35:41 +13:00
|
|
|
|
2023-07-31 20:07:01 -04:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/poetry2nix_astunparse
|
|
|
|
cp ./Tools/parser/unparse.py $out/poetry2nix_astunparse/__init__.py
|
|
|
|
'';
|
2023-03-23 13:35:41 +13:00
|
|
|
};
|
2023-07-31 20:07:01 -04:00
|
|
|
|
2023-10-23 12:23:59 -04:00
|
|
|
pythonPath = lib.optional (lib.versionOlder python.version "3.9") unparser;
|
2023-07-31 20:07:01 -04:00
|
|
|
in
|
|
|
|
makeSetupHook
|
|
|
|
{
|
|
|
|
name = "require-python-patch-hook.sh";
|
|
|
|
substitutions = {
|
|
|
|
inherit pythonInterpreter pythonPath;
|
|
|
|
patchScript = ./python-requires-patch-hook.py;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
./python-requires-patch-hook.sh
|
|
|
|
)
|
|
|
|
{ };
|
2020-02-23 13:52:57 +00:00
|
|
|
}
|