-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checking directories via match_file() does not work on Path objects #65
Comments
If you acknowledge that this needs to addressed by When it creates the |
@yschroeder I'm undecided on this at the moment. I'm leaning towards supporting it but it's kind of inconsistent. Supporting Does black always use |
Yes, I am also not too sure, as Disclaimer: I am not a developer of What
In step 4, the TL;DR: |
Thanks for the summary. After thinking about this, I don't think the right behavior is to treat def append_dir_sep(path: pathlib.Path) -> str:
out_path = str(path)
if path.is_dir():
out_path += os.sep
return out_path Then to use it you can do: from pathspec.util import append_dir_sep
relative_path = append_dir_sep(relative_path)
if pattern.match_file(relative_path):
pass On a side note, looking the black's usage that you pointed out, here, it looks like |
I've added the |
I am currently investigating a problem in the
black
formatter which usespathspec
to figure out ignored files by parsing.gitignore
files.black
uses this library and tries to check if directories are ignored before checking their contents.It boils down to this minimum example:
It matches the file
important/bar.log
as expected, however, it does not match the folder when it has no trailing slash.This becomes especially problematic when using
Path
objects, as the trailing slash is removed bypathlib
.I don't know where this needs to be fixed. What do you think? Is
black
using it wrong? Should thematch_file()
method check if the givenPath
object is a directory and add the trailing slash on its own before checking?It would certainly be possible to implement a workaround in
black
and check withPath.is_dir()
, convert tostr
and append the slash...FYI, the place where the check happens in
black
is here.relative_path
is apathlib.Path
and can be a directory.The text was updated successfully, but these errors were encountered: