diff --git a/README.md b/README.md index 94d4f3b..15a3e6c 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ Returns a list containing the specified overlay and `defaultPoetryOverrides`. ### cleanPythonSources Provides a source filtering mechanism that: -- Filters gitignore (if it exists, non-recursive) +- Filters gitignore's - Filters pycache/pyc files - Uses cleanSourceFilter to filter out .git/.hg, .o/.so, editor backup files & nix result symlinks diff --git a/lib.nix b/lib.nix index 12b7416..3decbe7 100644 --- a/lib.nix +++ b/lib.nix @@ -96,16 +96,24 @@ let [ pythonPackages.${drvAttr} or (throw "unsupported build system ${buildSystem}") ] ); + # Find gitignore files recursively in parent directory stopping with .git + findGitIgnores = path: let + parent = path + "/.."; + gitIgnore = path + "/.gitignore"; + isGitRoot = builtins.pathExists (path + "/.git"); + hasGitIgnore = builtins.pathExists gitIgnore; + gitIgnores = if hasGitIgnore then [ gitIgnore ] else []; + in lib.optionals (! isGitRoot) (findGitIgnores parent) ++ gitIgnores; + /* Provides a source filtering mechanism that: - - Filters gitignore (if it exists, non-recursive) + - Filters gitignore's - Filters pycache/pyc files - Uses cleanSourceFilter to filter out .git/.hg, .o/.so, editor backup files & nix result symlinks */ cleanPythonSources = { src }: let - rootGitignore = src + "/.gitignore"; - hasGitignore = builtins.pathExists rootGitignore; + gitIgnores = findGitIgnores src; pycacheFilter = name: type: (type == "directory" && ! lib.strings.hasInfix "__pycache__" name) || (type == "regular" && ! lib.strings.hasSuffix ".pyc" name) @@ -114,7 +122,7 @@ let lib.cleanSourceWith { filter = lib.cleanSourceFilter; src = lib.cleanSourceWith { - filter = pkgs.nix-gitignore.gitignoreFilterPure pycacheFilter (lib.optional hasGitignore rootGitignore) src; + filter = pkgs.nix-gitignore.gitignoreFilterPure pycacheFilter gitIgnores src; inherit src; }; };