-
Notifications
You must be signed in to change notification settings - Fork 59
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
Add support for skipping license paths #851
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,3 +274,31 @@ def open_auto(*args, **kwargs): | |
assert 'encoding' not in kwargs | ||
assert 'errors' not in kwargs | ||
return open(*args, encoding="utf-8", errors="surrogateescape", **kwargs) | ||
|
||
|
||
def globlike_match(filename, match_name): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming you didn't edit this aside from moving it to util? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, same function though the signature had to change since it isn't a class method (though it wasn't using any of the object's fields). |
||
"""Compare the filename to the match_name in a way that simulates the shell glob '*'.""" | ||
fsplit = filename.split('/') | ||
if len(fsplit) != len(match_name): | ||
return False | ||
match = True | ||
for fpart, mpart in zip(fsplit, match_name): | ||
if fpart != mpart: | ||
if '*' not in mpart: | ||
match = False | ||
break | ||
if len(mpart) > len(fpart) + 1: | ||
match = False | ||
break | ||
mpl, mpr = mpart.split('*') | ||
try: | ||
if fpart.index(mpl) != 0: | ||
match = False | ||
break | ||
if fpart.rindex(mpr) != len(fpart) - len(mpr): | ||
match = False | ||
break | ||
except ValueError: | ||
match = False | ||
break | ||
return match |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,53 @@ def isfile_mock(_): | |
util.call = call_backup | ||
self.assertTrue(len(mock_call.mock_calls) == 3) | ||
|
||
def test_globlike_match(self): | ||
""" | ||
Test globlike_match | ||
""" | ||
match_name = ['a', 'b', 'c'] | ||
file_path = 'a/b' | ||
self.assertFalse(util.globlike_match(file_path, match_name)) | ||
|
||
match_name = ['a', 'c'] | ||
file_path = 'a/b' | ||
self.assertFalse(util.globlike_match(file_path, match_name)) | ||
|
||
match_name = ['a', 'bb*'] | ||
file_path = 'a/b' | ||
self.assertFalse(util.globlike_match(file_path, match_name)) | ||
|
||
match_name = ['a', 'b*'] | ||
file_path = 'a/ab' | ||
self.assertFalse(util.globlike_match(file_path, match_name)) | ||
|
||
match_name = ['a', 'b*'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oopsie, will fix. |
||
file_path = 'a/ab' | ||
self.assertFalse(util.globlike_match(file_path, match_name)) | ||
|
||
match_name = ['a', '*a'] | ||
file_path = 'a/ab' | ||
self.assertFalse(util.globlike_match(file_path, match_name)) | ||
|
||
match_name = ['a', 'c*'] | ||
file_path = 'a/b' | ||
self.assertFalse(util.globlike_match(file_path, match_name)) | ||
|
||
match_name = ['a', '*c'] | ||
file_path = 'a/b' | ||
self.assertFalse(util.globlike_match(file_path, match_name)) | ||
|
||
match_name = ['a', 'b*'] | ||
file_path = 'a/b' | ||
self.assertTrue(util.globlike_match(file_path, match_name)) | ||
|
||
match_name = ['a', '*b'] | ||
file_path = 'a/b' | ||
self.assertTrue(util.globlike_match(file_path, match_name)) | ||
|
||
match_name = ['a', 'b'] | ||
file_path = 'a/b' | ||
self.assertTrue(util.globlike_match(file_path, match_name)) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
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.
Shouldn't we hide some of this prefix? Especially if it's going to be boilerplate
/tmp/*/
... we should just prepend it whenskip_license
callsgloblike_match
, right?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.
Ugh that is nicer, thanks.