From 31effa4e4ef6df999b6f03449998b0b7ac6b0923 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Sat, 5 Feb 2022 21:32:09 +1200 Subject: [PATCH] Add hook to remove normal files from site-packages This is a fairly common packaging mistake that it's better that we solve in a hook than in one-by-one in overrides. Normal files in site-packages isn't always a mistake, so we can't clean them up wholesale, but we can clean up some common mistakes. --- hooks/default.nix | 7 +++++++ hooks/fixup-hook.sh | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/hooks/default.nix b/hooks/default.nix index 0abbe24..5d56201 100644 --- a/hooks/default.nix +++ b/hooks/default.nix @@ -67,6 +67,13 @@ in { name = "fixup-hook.sh"; deps = [ ]; + substitutions = { + inherit pythonSitePackages; + filenames = builtins.concatStringsSep " " [ + "pyproject.toml" + "README.md" + ]; + }; } ./fixup-hook.sh ) { }; diff --git a/hooks/fixup-hook.sh b/hooks/fixup-hook.sh index fc539e4..8cbe2b1 100644 --- a/hooks/fixup-hook.sh +++ b/hooks/fixup-hook.sh @@ -1,8 +1,20 @@ poetry2nix-fixup-hook() { + # Including tests in the output is a common mistake if [ -z "${dontFixupTests-}" ]; then - rm -rf $out/lib/python3.7/site-packages/tests + rm -rf $out/@pythonSitePackages@/tests fi + + # Including files in site-packages is a common packaging mistake + # + # While we cannot remove all normal files dumped in site-packages + # we can clean up some common mistakes + if [ -z "${dontFixupSitePackages-}" ]; then + for f in @filenames@; do + rm -f $out/@pythonSitePackages@/$f + done + fi + } postFixupHooks+=(poetry2nix-fixup-hook)