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

Add parameter @case_sensitive to glob and rglob in pathlib #81079

Closed
ChuangMen mannequin opened this issue May 13, 2019 · 6 comments
Closed

Add parameter @case_sensitive to glob and rglob in pathlib #81079

ChuangMen mannequin opened this issue May 13, 2019 · 6 comments
Labels
3.8 (EOL) end of life stdlib Python modules in the Lib dir topic-pathlib type-feature A feature request or enhancement

Comments

@ChuangMen
Copy link
Mannequin

ChuangMen mannequin commented May 13, 2019

BPO 36898
Nosy @serhiy-storchaka
PRs
  • bpo-36898: Add parameter @case_sensitive to glob and rglob in pathlib #13274
  • Files
  • pathlib.py
  • 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 = None
    created_at = <Date 2019-05-13.07:17:56.195>
    labels = ['3.8', 'type-feature', 'library']
    title = 'Add parameter @case_sensitive to glob and rglob in pathlib'
    updated_at = <Date 2019-05-13.07:58:11.844>
    user = 'https://bugs.python.org/ChuangMen'

    bugs.python.org fields:

    activity = <Date 2019-05-13.07:58:11.844>
    actor = 'Chuang Men'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2019-05-13.07:17:56.195>
    creator = 'Chuang Men'
    dependencies = []
    files = ['48328']
    hgrepos = []
    issue_num = 36898
    keywords = []
    message_count = 3.0
    messages = ['342284', '342287', '342289']
    nosy_count = 2.0
    nosy_names = ['serhiy.storchaka', 'Chuang Men']
    pr_nums = ['13274']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue36898'
    versions = ['Python 3.8']

    Linked PRs

    @ChuangMen
    Copy link
    Mannequin Author

    ChuangMen mannequin commented May 13, 2019

    In pathlib, I add a parameter @case_sensitive to glob and rglob.

    Sometimes the extension would be in upper case but sometimes it would be lower case, for example: *.tif and *.TIF. So the parameter @case_sensitive may be useful in some cases.

    Usage example:
    In [1]: from pathlib import Path

    In [2]: path = Path('.')

    In [3]: for each_file in path.glob('*.tif'):
    ...: print(each_file)
    ...:
    a.tif
    b.tif

    In [4]: for each_file in path.rglob('*.TIF'):
    ...: print(each_file)
    ...:
    c.TIF
    TEST/d.TIF

    In [5]: for each_file in path.glob('*.TIF', case_sensitive=False):
    ...: print(each_file)
    ...:
    a.tif
    c.TIF
    b.tif

    In [6]: for each_file in path.rglob('*.TIF', case_sensitive=False):
    ...: print(each_file)
    ...:
    a.tif
    c.TIF
    b.tif
    TEST/d.TIF
    TEST/e.tif

    @ChuangMen ChuangMen mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels May 13, 2019
    @SilentGhost SilentGhost mannequin added 3.8 (EOL) end of life and removed 3.7 (EOL) end of life labels May 13, 2019
    @serhiy-storchaka
    Copy link
    Member

    You can use the pattern '*.[Tt][Ii][Ff]'.

    @ChuangMen
    Copy link
    Mannequin Author

    ChuangMen mannequin commented May 13, 2019

    It is a good solution but when pattern is long, it might be a little inconvenient.
    Anyway, just an advice. Thank you for your reply!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    barneygale added a commit to barneygale/cpython that referenced this issue Mar 12, 2023
    Add a keyword-only *follow_symlinks* parameter to `pathlib.Path.glob()` and
    `rglob()`, defaulting to false. When set to true, symlinks to directories
    are followed as if they were directories.
    
    Previously these methods followed symlinks except when evaluating "`**`"
    wildcards; on Windows they returned paths in filesystem casing except when
    evaluating non-wildcard tokens. Both these problems are solved here. This
    will allow us to address pythonGH-102613 and pythonGH-81079 in future commits.
    @barneygale
    Copy link
    Contributor

    This should be straightforward to add once #102616 lands.

    barneygale added a commit to barneygale/cpython that referenced this issue Mar 15, 2023
    This argument allows case-sensitive matching to be enabled on Windows, and
    case-insensitive matching to be enabled on Posix.
    @barneygale
    Copy link
    Contributor

    PR available: #102710

    barneygale added a commit to barneygale/cpython that referenced this issue Mar 22, 2023
    barneygale added a commit to barneygale/cpython that referenced this issue Mar 27, 2023
    barneygale added a commit to barneygale/cpython that referenced this issue Apr 29, 2023
    barneygale added a commit to barneygale/cpython that referenced this issue May 2, 2023
    barneygale added a commit to barneygale/cpython that referenced this issue May 3, 2023
    …ern segment case
    
    We now use `_WildcardSelector` to evaluate literal pattern segments, which
    allows us to retrieve the real filesystem case.
    
    This change is necessary in order to implement a *case_sensitive* argument
    (see pythonGH-81079) and a *follow_symlinks* argument (see pythonGH-77609).
    barneygale added a commit that referenced this issue May 3, 2023
    …gment case (GH-104116)
    
    We now use `_WildcardSelector` to evaluate literal pattern segments, which
    allows us to retrieve the real filesystem case.
    
    This change is necessary in order to implement a *case_sensitive* argument
    (see GH-81079) and a *follow_symlinks* argument (see GH-77609).
    barneygale added a commit to barneygale/cpython that referenced this issue May 3, 2023
    barneygale added a commit that referenced this issue May 4, 2023
    …2710)
    
    This argument allows case-sensitive matching to be enabled on Windows, and
    case-insensitive matching to be enabled on Posix.
    
    Co-authored-by: Steve Dower <steve.dower@microsoft.com>
    @barneygale
    Copy link
    Contributor

    Implemented in 3.12: #102710 / 8100be5

    carljm added a commit to carljm/cpython that referenced this issue May 5, 2023
    * main: (61 commits)
      pythongh-64595: Argument Clinic: Touch source file if any output file changed (python#104152)
      pythongh-64631: Test exception messages in cloned Argument Clinic funcs (python#104167)
      pythongh-68395: Avoid naming conflicts by mangling variable names in Argument Clinic (python#104065)
      pythongh-64658: Expand Argument Clinic return converter docs (python#104175)
      pythonGH-103092: port `_asyncio` freelist to module state (python#104196)
      pythongh-104051: fix crash in test_xxtestfuzz with -We (python#104052)
      pythongh-104190: fix ubsan crash (python#104191)
      pythongh-104106: Add gcc fallback of mkfifoat/mknodat for macOS (pythongh-104129)
      pythonGH-104142: Fix _Py_RefcntAdd to respect immortality (pythonGH-104143)
      pythongh-104112: link from cached_property docs to method-caching FAQ (python#104113)
      pythongh-68968: Correcting message display issue with assertEqual (python#103937)
      pythonGH-103899: Provide a hint when accidentally calling a module (pythonGH-103900)
      pythongh-103963: fix 'make regen-opcode' in out-of-tree builds (python#104177)
      pythongh-102500: Add PEP 688 and 698 to the 3.12 release highlights (python#104174)
      pythonGH-81079: Add case_sensitive argument to `pathlib.Path.glob()` (pythonGH-102710)
      pythongh-91896: Deprecate collections.abc.ByteString (python#102096)
      pythongh-99593: Add tests for Unicode C API (part 2) (python#99868)
      pythongh-102500: Document PEP 688 (python#102571)
      pythongh-102500: Implement PEP 688 (python#102521)
      pythongh-96534: socketmodule: support FreeBSD divert(4) socket (python#96536)
      ...
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 (EOL) end of life stdlib Python modules in the Lib dir topic-pathlib type-feature A feature request or enhancement
    Projects
    Development

    No branches or pull requests

    3 participants