Skip to content
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

Change Glob: Allow Recursion for Hidden Files #81759

Closed
k64 mannequin opened this issue Jul 13, 2019 · 9 comments
Closed

Change Glob: Allow Recursion for Hidden Files #81759

k64 mannequin opened this issue Jul 13, 2019 · 9 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@k64
Copy link
Mannequin

k64 mannequin commented Jul 13, 2019

BPO 37578
Nosy @encukou, @serhiy-storchaka, @miss-islington, @MyungSeKyo, @marload, @akulakov
PRs
  • bpo-37578: glob.glob -- added include_hidden parameter #30153
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-12-18.15:01:46.283>
    created_at = <Date 2019-07-13.02:23:53.212>
    labels = ['type-feature', 'library', '3.11']
    title = 'Change Glob: Allow Recursion for Hidden Files'
    updated_at = <Date 2021-12-18.15:01:46.282>
    user = 'https://bugs.python.org/k64'

    bugs.python.org fields:

    activity = <Date 2021-12-18.15:01:46.282>
    actor = 'AlexWaygood'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-12-18.15:01:46.283>
    closer = 'AlexWaygood'
    components = ['Library (Lib)']
    creation = <Date 2019-07-13.02:23:53.212>
    creator = 'k64'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37578
    keywords = ['patch']
    message_count = 9.0
    messages = ['347767', '347811', '373441', '391603', '408743', '408750', '408751', '408752', '408853']
    nosy_count = 8.0
    nosy_names = ['petr.viktorin', 'serhiy.storchaka', 'miss-islington', 'myungsekyo', 'k64', 'Isaac Muse', 'ys19991', 'andrei.avk']
    pr_nums = ['30153']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue37578'
    versions = ['Python 3.11']

    @k64
    Copy link
    Mannequin Author

    k64 mannequin commented Jul 13, 2019

    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.

    @k64 k64 mannequin added the type-feature A feature request or enhancement label Jul 13, 2019
    @tirkarthi tirkarthi added stdlib Python modules in the Lib dir 3.9 only security fixes labels Jul 13, 2019
    @serhiy-storchaka
    Copy link
    Member

    This is an interesting question. What other implementations behave?

    @marload
    Copy link
    Mannequin

    marload mannequin commented Jul 10, 2020

    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)
    

    @encukou
    Copy link
    Member

    encukou commented Apr 22, 2021

    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

    @akulakov
    Copy link
    Contributor

    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).

    @IsaacMuse
    Copy link
    Mannequin

    IsaacMuse mannequin commented Dec 17, 2021

    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 ..

    @akulakov
    Copy link
    Contributor

    Isaac: my PR does allow [.] to match. But I probably need to update the docs to note that.

    @akulakov
    Copy link
    Contributor

    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).

    @miss-islington
    Copy link
    Contributor

    New changeset ae36cd1 by andrei kulakov in branch 'main':
    bpo-37578: glob.glob -- added include_hidden parameter (GH-30153)
    ae36cd1

    @AlexWaygood AlexWaygood added 3.11 only security fixes and removed 3.9 only security fixes labels Dec 18, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    6 participants