This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Change Glob: Allow Recursion for Hidden Files
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Isaac Muse, andrei.avk, k64, miss-islington, myungsekyo, petr.viktorin, serhiy.storchaka, ys19991
Priority: normal Keywords: patch

Created on 2019-07-13 02:23 by k64, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30153 merged andrei.avk, 2021-12-16 19:50
Messages (9)
msg347767 - (view) Author: Kalev Maricq (k64) Date: 2019-07-13 02:23
First, sorry if this isn't in the correct place or correctly labeled. I'm new to this platform.  Feel free to edit this (if that's even possible on this platform). 

In the glob.py module, _ishidden(pattern) is used to determine whether to show hidden files and folders by checking if pattern[0]=='.'.  It also uses _isrecursive(pattern) to determine whether to perform a recursive search by checking whether the pattern=='**'.  As a result, one cannot perform a recursive search which shows hidden folders and files, since '**'[0]!='.'.  

Suggestion: Alter _isrecursive to return '**' in pattern to allow for this.
msg347811 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-07-13 13:08
This is an interesting question. What other implementations behave?
msg373441 - (view) Author: Wansoo Kim (ys19991) * Date: 2020-07-10 06:38
Can you reproduce this bug? I was able to find the hidden file by recursive search by excuting the code below.

```
from glob import glob

hidden = glob('**/.*')

print(hidden)
```
msg391603 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2021-04-22 14:29
I wonder if it would be worth it to add a new option to include hidden files (except . and ..)
For the record, setuptools' fork of glob does this unconditionally: https://github.com/pypa/setuptools/blob/main/setuptools/glob.py
msg408743 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-12-17 00:38
Zsh allows use of *, ? and ** to match hidden files and directories.

Bash allows the same for * and ? with `dotglob` option. There is also a `globstar` but my version of bash (on macos) is too old to have it.

By the way setting options in bash is done with `shopt -s <option>`.

I've put up a PR that enables behavior similar to Zsh and Bash (at least for ? and * chars).
msg408750 - (view) Author: Isaac Muse (Isaac Muse) Date: 2021-12-17 02:25
If this was to be done, you'd want to make sure character sequences also match hidden files: [.]. Just * and ? would be incomplete. If allowing ** to match a leading dot, it would not match . or ..
msg408751 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-12-17 02:31
Isaac: my PR does allow [.] to match. But I probably need to update the docs to note that.
msg408752 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-12-17 02:35
I want to clarify my first comment: my PR is similar to Zsh behaviour as described above; as I'm not 100% sure how bash behaves with `**` with globstar option, I can say that bash is the same as Zsh with ? and * magic characters (with dotglob option), and likely the same for `**` as well, but I can't test it (if someone can test it, please comment).
msg408853 - (view) Author: miss-islington (miss-islington) Date: 2021-12-18 14:23
New changeset ae36cd1e792db9d6db4c6847ec2a7d50a71f2b68 by andrei kulakov in branch 'main':
bpo-37578: glob.glob -- added include_hidden parameter (GH-30153)
https://github.com/python/cpython/commit/ae36cd1e792db9d6db4c6847ec2a7d50a71f2b68
History
Date User Action Args
2022-04-11 14:59:17adminsetgithub: 81759
2021-12-18 15:01:46AlexWaygoodsetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.11, - Python 3.9
2021-12-18 14:23:42miss-islingtonsetnosy: + miss-islington
messages: + msg408853
2021-12-17 02:35:51andrei.avksetmessages: + msg408752
2021-12-17 02:31:14andrei.avksetmessages: + msg408751
2021-12-17 02:25:21Isaac Musesetnosy: + Isaac Muse
messages: + msg408750
2021-12-17 00:38:57andrei.avksetmessages: + msg408743
2021-12-16 19:50:06andrei.avksetkeywords: + patch
nosy: + andrei.avk

pull_requests: + pull_request28372
stage: patch review
2021-04-22 14:29:42petr.viktorinsetnosy: + petr.viktorin
messages: + msg391603
2020-07-10 06:38:12ys19991setnosy: + ys19991
messages: + msg373441
2019-07-17 08:58:59myungsekyosetnosy: + myungsekyo
2019-07-13 13:08:53serhiy.storchakasetmessages: + msg347811
2019-07-13 05:56:58xtreaksetnosy: + serhiy.storchaka

components: + Library (Lib)
versions: + Python 3.9
2019-07-13 02:23:53k64create