Make gitignore recursive

This commit is contained in:
adisbladis 2020-02-29 21:19:09 +00:00
parent 753c7965dc
commit 924746ff9a
No known key found for this signature in database
GPG key ID: 110BFAD44C6249B7
2 changed files with 13 additions and 5 deletions

View file

@ -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

16
lib.nix
View file

@ -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;
};
};