Title: fnmatch does not follow Unix fnmatch functionality
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Varun Agrawal, r.david.murray
Priority: normal Keywords:

Created on 2017-08-04 23:22 by Varun Agrawal, last changed 2017-08-08 13:14 by r.david.murray.

Messages (5)
msg299763 - (view) Author: Varun Agrawal (Varun Agrawal) Date: 2017-08-04 23:22
Currently, the fnmatch module in Python does not operate like the Unix equivalent command. This is especially the case with patterns such as `dir/` which does not match directory path returned by `os` (which would be `dir`) and neither does the pattern match the underlying files and sub-directories. Adding these functionalities so that fnmatch matches it's Unix equivalent would make it much more powerful to use.

Glob is not useful since glob is a special case that matches only with the current directory paths rather than the a general purpose filename pattern matcher.
msg299764 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-08-04 23:34
I don't believe there is an equivalent unix command.  Are you referring to the fnmatch glibc function?  Can you demonstrate the differences?  I doubt we will change the functionality, but that would be the minimum starting point for a discussion.
msg299767 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-08-05 01:58
Looking at the fnmatch man page, it looks like there are option flags that some shells use that our fnmatch doesn't support.  I'm not sure if supporting them is a good idea for us or not, but it is probably worth discussing.  I suspect our fnmatch was implemented before gnu added those extensions.
msg299874 - (view) Author: Varun Agrawal (Varun Agrawal) Date: 2017-08-07 22:30
Hi David,
It seems you already took a look at the man page. There are some subtle differences such as being unable to match to a directory when the pattern ends with a forward slash.
Overall, I'd like to see fnmatch be used to create a program that can perform pattern matching of files similar to how a gitignore works. Currently, this involves quite a bit of hackery to get working well.
msg299917 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-08-08 13:14
That seems like a reasonable use case, but is fnmatch what git is using for this?  If so, what is the feature set required?  In any case, the existing functionality must remain as is for backward compatibility reasons, so this would either be a new function or keyword controlled optional behavior.

(You will note that our fnmatch documentation specifically mentions treating / as a normal character.)
Date User Action Args
2017-08-08 13:14:33r.david.murraysetmessages: + msg299917
2017-08-07 22:30:03Varun Agrawalsetmessages: + msg299874
2017-08-05 01:58:08r.david.murraysetmessages: + msg299767
2017-08-04 23:34:44r.david.murraysettype: behavior -> enhancement
versions: - Python 2.7, Python 3.4, Python 3.5, Python 3.6
2017-08-04 23:34:25r.david.murraysetnosy: + r.david.murray
messages: + msg299764
2017-08-04 23:22:19Varun Agrawalcreate