mirror of
https://github.com/vale981/poetry2nix
synced 2025-03-04 08:41:42 -05:00
Reset PYTHONPATH before running Python script in hooks
This commit is contained in:
parent
59a79de540
commit
e4a98cf325
2 changed files with 36 additions and 35 deletions
|
@ -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
|
||||
(
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue