[issue13968] Add a recursive function to the glob package
New submission from Yuval Greenfield ubershme...@gmail.com: This is a feature I've wanted to use in too many times to remember. I've made a patch with an implementation, docs and a test. I've named the function rglob and tried to stay within the conventions of the glob package. -- components: Library (Lib) files: rglob.patch keywords: patch messages: 152843 nosy: ubershmekel priority: normal severity: normal status: open title: Add a recursive function to the glob package type: enhancement versions: Python 3.4 Added file: http://bugs.python.org/file24451/rglob.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Changes by Giampaolo Rodola' g.rod...@gmail.com: -- nosy: +giampaolo.rodola ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Nick Coghlan ncogh...@gmail.com added the comment: I'm inclined to close this as a functional duplicate of http://bugs.python.org/issue13229 -- nosy: +ncoghlan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Yuval Greenfield ubershme...@gmail.com added the comment: I'd say it's very close to a duplicate but maybe isn't so. If walkdir is added then rglob can be implemented using it. I'd say rglob to walkdir is like urlopen to http.client. One is the stupid and simple function (that still has a bazillion use cases) and the other is the heavy lifting swiss army knife. file_paths(filtered_walk('.', included_files=['*.py'])) is a lot longer than rglob('*.py'). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Antoine Pitrou pit...@free.fr added the comment: file_paths(filtered_walk('.', included_files=['*.py'])) is a lot longer than rglob('*.py'). Agreed. -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Nick Coghlan ncogh...@gmail.com added the comment: A fair point indeed. To follow the shutil naming convention (rmtree, copytree, and likely chmodtree, chowntree), a more appropriate name might be globtree. (Thanks to string methods, the 'r' prefix doesn't read correctly to me: what does globbing from the right mean?) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Antoine Pitrou pit...@free.fr added the comment: To follow the shutil naming convention (rmtree, copytree, and likely chmodtree, chowntree), a more appropriate name might be globtree. (Thanks to string methods, the 'r' prefix doesn't read correctly to me: what does globbing from the right mean?) Well, if you put it in the glob module, it doesn't have to follow the shutil naming convention :-) (I prefer rglob myself) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Nick Coghlan ncogh...@gmail.com added the comment: I can live with it either way - I just wanted to point out that our current examples of this kind of recursive filesystem access use a 'tree' suffix rather than an 'r' prefix. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Eli Bendersky eli...@gmail.com added the comment: file_paths(filtered_walk('.', included_files=['*.py'])) is a lot longer than rglob('*.py'). It is, but is that a good enough reason to have both? It can also be achieved with just a bit more code using the simple `os.walk`. I suppose there are a lot of instances of stdlib tools where we could add new tools that would make the code slightly shorter. However, this is not really faithful to the Python spirit, since it adds too many ways to do achieve the same effect, and ultimately confuses users. That it adds additional maintenance burden on the coredevs goes without saying :-) Each such new burden should have a very good reason. To conclude, personally I'm -1 on this, especially if `walkdir` eventually makes it into the stdlib. -- nosy: +eli.bendersky ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Antoine Pitrou pit...@free.fr added the comment: file_paths(filtered_walk('.', included_files=['*.py'])) is a lot longer than rglob('*.py'). It is, but is that a good enough reason to have both? It is. globbing is a well-known operation that many people expect to be easily done. However, this is not really faithful to the Python spirit, since it adds too many ways to do achieve the same effect, and ultimately confuses users. Which Python spirit are you talking about? We have many high-level tools in the stdlib. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Éric Araujo mer...@netwok.org added the comment: There is an alternative: supporting ** syntax, e.g. '**/*.py', which should find all *.py files in the current directory and all descendents. At present glob('**/*.py') is equivalent to glob('*/*.py'), but we would say this behavior was undefined and the new behavior would be a new feature. -- nosy: +eric.araujo versions: +Python 3.3 -Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Eli Bendersky eli...@gmail.com added the comment: It is. globbing is a well-known operation that many people expect to be easily done. According to Wikipedia (http://en.wikipedia.org/wiki/Glob_%28programming%29) - The noun glob is used to refer to a particular pattern, e.g. use the glob *.log to match all those log files. IOW, globbing is usually understood as the act of expanding a pattern to the files it matches. Nothing in that implies recursive traversal of a directory tree. On the other hand, os.walk and/or walkdir suggest that in their name. Which Python spirit are you talking about? We have many high-level tools in the stdlib. There should be one -- and preferably only one -- obvious way to do it. Admittedly, we already have more than one, and a high-level tool is proposed with Nick's walkdir. Why add *yet another* high-level tool? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Antoine Pitrou pit...@free.fr added the comment: IOW, globbing is usually understood as the act of expanding a pattern to the files it matches. Nothing in that implies recursive traversal of a directory tree. Still, that's a common need. I want all Python files in a subtree. On the other hand, os.walk and/or walkdir suggest that in their name. I don't know why walk is supposedly more recursive than glob. Admittedly, we already have more than one, and a high-level tool is proposed with Nick's walkdir. Why add *yet another* high-level tool? Because the walkdir spelling (IIUC) is longish, tedious and awkward. I could see myself typing rglob('*.py') in a short script or an interpreter session, without having to look up any kind of docs. Certainly not the walkdir alternative (I've already forgotten what it is). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Eli Bendersky eli...@gmail.com added the comment: IOW, globbing is usually understood as the act of expanding a pattern to the files it matches. Nothing in that implies recursive traversal of a directory tree. Still, that's a common need. I want all Python files in a subtree. On the other hand, os.walk and/or walkdir suggest that in their name. I don't know why walk is supposedly more recursive than glob. Google walk directory. First hit is a Rosetta code page with *recursive* walking implemented in various languages. So I guess it does have this connotation. Regardless, os.walk has been in Python for ages, and it's always been the go-to tool for recursive traversal. walkdir's name suggests the same. Admittedly, we already have more than one, and a high-level tool is proposed with Nick's walkdir. Why add *yet another* high-level tool? Because the walkdir spelling (IIUC) is longish, tedious and awkward. I could see myself typing rglob('*.py') in a short script or an interpreter session, without having to look up any kind of docs. Certainly not the walkdir alternative (I've already forgotten what it is). walkdir is a new module proposal. If its API is tedious and awkward, it should probably be improved *now* while it's in development. Adding yet another tool that implements part of its functionality, winning a golf tournament along the way, isn't the solution, IMHO. -- title: Support recursive globs - Add a recursive function to the glob package ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Éric Araujo mer...@netwok.org added the comment: Feedback from Antoine on IRC about my syntax proposal: “The ** meaning is not really universal like other quantifiers are. [...] (also, it would be quite harder to implement, I think)” That and the compat issue makes me go in favor of a new function. I’m not sure glob is the right place: when you use glob.glob, the search is rooted in the current directory, and you may have sub-directories in your pattern, e.g. 'Lib/*/__main__.py'. A function meaning “look for this file pattern recursively” would be IMO more at home in fnmatch. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Antoine Pitrou pit...@free.fr added the comment: Google walk directory. First hit is a Rosetta code page with *recursive* walking implemented in various languages. So I guess it does have this connotation. Regardless, os.walk has been in Python for ages, and it's always been the go-to tool for recursive traversal. walkdir's name suggests the same. You still haven't explained what your problem is with the idea of an explicitly recursive glob (as both rglob and globtree suggest). walkdir is a new module proposal. If its API is tedious and awkward, it should probably be improved *now* while it's in development. walkdir is not yet a module proposal, there's not even a PEP for it, and it's in a very young state. This issue has a working patch for rglob(), which is a single, obvious, incremental addition to the existing glob module. If you want to discuss walkdir, I suggest you do it in a separate issue. (and, yes, rglob() can be reimplemented using walkdir later, if there is a point in doing so) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Eli Bendersky eli...@gmail.com added the comment: Google walk directory. First hit is a Rosetta code page with *recursive* walking implemented in various languages. So I guess it does have this connotation. Regardless, os.walk has been in Python for ages, and it's always been the go-to tool for recursive traversal. walkdir's name suggests the same. You still haven't explained what your problem is with the idea of an explicitly recursive glob (as both rglob and globtree suggest). The problem is that I prefer the walkdir approach, because it solves a more general problem and overall more useful. This is also why I don't see how it makes sense to stop discussing it here and focus on rglob. They are related, after all! Anyway, I'm not sure what else I can add to the discussion. I'm starting to repeat myself, which means that I should just shut up :) I've stated my preference, and I understand and respect yours. So let's just see what others think. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13968] Add a recursive function to the glob package
Antoine Pitrou pit...@free.fr added the comment: I'm trying the patch and its behaviour is strange: list(glob.rglob('setup.py')) ['setup.py'] list(glob.rglob('setu*.py')) [] list(glob.rglob('*/setu*.py')) ['./setup.py', './Mac/Tools/Doc/setup.py', './Tools/test2to3/setup.py', './Doc/includes/setup.py', './PC/example_nt/setup.py'] I can understand the first example (although that makes the documentation slightly incorrect, since you need an explicit * path component for the search to be recursive), but the second one looks straight wrong. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13968 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com