Reset PYTHONPATH before running Python script in hooks

This commit is contained in:
Sem Mulder 2022-05-09 17:27:24 +02:00 committed by adisbladis
parent 59a79de540
commit e4a98cf325
2 changed files with 36 additions and 35 deletions

View file

@ -9,44 +9,40 @@ let
callPackage = python.pythonForBuild.pkgs.callPackage;
pythonInterpreter = python.pythonForBuild.interpreter;
pythonSitePackages = python.sitePackages;
nonOverlayedPython = pkgs.python3.pythonForBuild.withPackages (ps: [ ps.tomlkit ]);
makeRemoveSpecialDependenciesHook = { fields, kind }:
nonOverlayedPython.pkgs.callPackage
(
{}:
makeSetupHook
{
name = "remove-path-dependencies.sh";
deps = [ ];
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}";
fields = fields;
kind = kind;
};
} ./remove-special-dependencies.sh
)
{ };
in
{
# 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.
removePathDependenciesHook = nonOverlayedPython.pkgs.callPackage
(
{}:
makeSetupHook
{
name = "remove-path-dependencies.sh";
deps = [ ];
substitutions = {
pythonInterpreter = nonOverlayedPython.interpreter;
pyprojectPatchScript = "${./pyproject-without-special-deps.py}";
fields = [ "path" ];
kind = "path";
};
} ./remove-special-dependencies.sh
)
{ };
removePathDependenciesHook = makeRemoveSpecialDependenciesHook {
fields = [ "path" ];
kind = "path";
};
removeGitDependenciesHook = makeRemoveSpecialDependenciesHook {
fields = [ "git" "branch" "rev" "tag" ];
kind = "git";
};
removeGitDependenciesHook = nonOverlayedPython.pkgs.callPackage
(
{}:
makeSetupHook
{
name = "remove-git-dependencies.sh";
deps = [ ];
substitutions = {
pythonInterpreter = nonOverlayedPython.interpreter;
pyprojectPatchScript = "${./pyproject-without-special-deps.py}";
fields = [ "git" "branch" "rev" "tag" ];
kind = "git";
};
} ./remove-special-dependencies.sh
)
{ };
pipBuildHook = callPackage
(

View file

@ -1,11 +1,16 @@
remove-@kind@-dependencies-hook() {
# Tell poetry not to resolve special dependencies. Any version is fine!
if ! test -f pyproject.toml; then
return
fi
echo "Removing @kind@ dependencies"
# Tell poetry not to resolve special dependencies. Any version is fine!
# NOTE: We have to reset PYTHONPATH to avoid having propagatedBuildInputs
# from the currently building derivation leaking into our unrelated Python
# environment.
PYTHONPATH=@pythonPath@ \
@pythonInterpreter@ \
@pyprojectPatchScript@ \
--fields-to-remove @fields@ < pyproject.toml > pyproject.formatted.toml