python / cpython

The Python programming language
https://www.python.org
Other
62.32k stars 29.93k forks source link

option to not follow symlinks when globbing #73661

Open c1b2d23c-2f4d-4d32-b768-4bdf89431bb7 opened 7 years ago

c1b2d23c-2f4d-4d32-b768-4bdf89431bb7 commented 7 years ago
BPO 29475
Nosy @ethanfurman, @o11c, @wimglenn
Files
  • python-glob-symlink.diff: Patch to add symlinks= argument to glob.glob and glob.iglob
  • 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: ```python assignee = None closed_at = None created_at = labels = ['type-feature', 'library'] title = 'option to not follow symlinks when globbing' updated_at = user = 'https://github.com/o11c' ``` bugs.python.org fields: ```python activity = actor = 'wim.glenn' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'o11c' dependencies = [] files = ['46566'] hgrepos = [] issue_num = 29475 keywords = ['patch'] message_count = 3.0 messages = ['287256', '287279', '302002'] nosy_count = 3.0 nosy_names = ['ethan.furman', 'o11c', 'wim.glenn'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue29475' versions = ['Python 3.6'] ```

    c1b2d23c-2f4d-4d32-b768-4bdf89431bb7 commented 7 years ago

    Background: I have a data hierarchy with a lot of "sibling" symlinked directories/files. I want to glob only the non-symlink files, because it's a *huge* performance increase.

    Before os.scandir, I was using a local copy of glob.py and calling os.path.islink every time, which was faster for my use case, but unacceptable for upstreaming. With os.scandir, my new patch should be acceptable.

    The patch includes tests.

    Current discussion points:

    Future discussion points (don't derail):

    ethanfurman commented 7 years ago

    Before talking about the patch, have you signed the Contributer License Agreement yet? The issue tracker isn't showing that you have. Check out https://www.python.org/psf/contrib/contrib-form/ to do so.

    ---

    The symlinks flag: can you give some glob examples showing when, and when not, symlinks will be matched when the symlinks param is False?

    A bit flags enum: There is now an IntFlag Enum type which implements bit flags.

    310dd13a-adf5-42f8-b3ef-a4a4f2d763e3 commented 7 years ago

    +1, would like to use this feature too, and I would like it also in pathlib.PosixPath.glob

    gpshead commented 5 months ago

    The upcoming 3.13 release gains a follow_symlinks= argument to the pathlib.Path.glob API: https://docs.python.org/3.13/library/pathlib.html#pathlib.Path.glob via https://github.com/python/cpython/issues/77609.

    barneygale commented 5 months ago

    I plan to work on this once #77609 and #116380 are done.