-
-
Notifications
You must be signed in to change notification settings - Fork 690
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
Use the standard pathlib instead of pathtools #704
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the patch :)
Could you add a line in the changelog + your nickname?
And I did not say it, but this is a clever usage of subclasses to emulate case-sensitivity 💪 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the changelog entry.
f6af0a2
to
2cd2f77
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the tests. They actually work now.
if case_sensitive: | ||
path = PurePosixPath(path) | ||
else: | ||
included_patterns = {pattern.lower() for pattern in included_patterns} | ||
excluded_patterns = {pattern.lower() for pattern in excluded_patterns} | ||
path = PureWindowsPath(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the handling of case-sensitivity into _match_path
so that the test for _match_path
can use {"*.py"}
and {"*.PY"}
to raise the ValueError
.
_match_path
is still assuming that included_patterns
and excluded_patterns
are sets, which is guaranteed by filter_path
and match_any_paths
. I'm also not against moving the call to set()
over here.
("/users/gorakhargosh/foobar.py", {"*.py"}, {"*.PY"}, True, True), | ||
("/users/gorakhargosh/foobar.py", {"*.py"}, {"*.PY"}, True, True), | ||
("/users/gorakhargosh/", {"*.py"}, {"*.txt"}, False, False), | ||
("/users/gorakhargosh/foobar.py", {"*.py"}, {"*.PY"}, False, ValueError), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once I moved the if case_sensitive
to _match_path
, I was able to use plain old strings as input as well.
Travis is done. The errors don't seem related to my changes...
|
Yes, those are known issues. |
Is there anything else I should do? Travis has finished running, it's just the github status that is stuck. |
Thanks a lot @bstaletic 🍾 |
Now with docstrings and tests. To be honest, I have not actually ran the tests and am hoping CI will be green and I won't have to.
The tests are taken directly from pathtools'
patterns.py
, so those should work.One thing to note is the license. I have no idea if I'm supposed to copy/paste the complete license notice and if I'm supposed to attribute it to the original author. Just a thing to check...
Finally, to answer this question (which I did, but never hit "post"), that was intentional, though the reason is not immediately obvious.
pathlib
doesn't have acase_sensitive
parameter anywhere in its API -PurePosixPath
andPosixPath
are always case-sensitive andPureWindowsPath
andWindowsPath
are always case-insensitive. On top of that, only "pure" path objects can be instantiated anywhere -WindowsPath
can't be instantiated on POSIX systems and vice versa.This lead me to "emulating" the
case_sensitive
parameter, by converting the input paths (as strings) to eitherPurePosixPath
orPureWindowsPath
, to satisfycase_sensitive
.In short, it allows this: