Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Here is what my current implementation boils down to:
spec = pathspec.PathSpec.from_lines(pathspec.GitIgnorePattern, patterns) def match_file(file_path): return len(list(spec.match_files([file_path]))) > 0 # This should not be so complicated is_ignored = match_file(u'testfile.py')
As you can see, it's pretty cumbersome: I have to create a a collection with a single item, run the matcher and then extract the result.
Ideally, I would imagine that PathSpec exposes a
class PathSpec(object): # ... def match_file(self, file, separators=None): # Core logic norm, path = util.normalize_file(file, separators=separators) # Single file version is_matched = util.match_file(self.patterns, norm) # Single file version return is_matched # bool def match_files(self, files, separators=None): # Quality of life function: it just replaces a one line generator return (file for file in files if self.match_file(file, separators))
Basically, it boils down to the fact the library does not expose single item functions to let me iterate other my files as I want but hides a loop inside every function.
Side note: the real name of the gitignore matcher is wildmatch. How about adding this as an alias name when registering the pattern ? Your module deserves to be better referenced (I had some troubles to find it even if I knew what I was looking for).
@demurgos That is quite cumbersome to match files one at a time. In the next release, I'll add