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

glob : some 'unix style' glob items are not supported #84037

Open
JeGeVa mannequin opened this issue Mar 4, 2020 · 4 comments
Open

glob : some 'unix style' glob items are not supported #84037

JeGeVa mannequin opened this issue Mar 4, 2020 · 4 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@JeGeVa
Copy link
Mannequin

JeGeVa mannequin commented Mar 4, 2020

BPO 39856
Nosy @serhiy-storchaka, @tirkarthi

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 2020-03-04.22:27:00.418>
labels = ['3.7', 'type-bug', 'library']
title = "glob : some 'unix style' glob items are not supported"
updated_at = <Date 2020-03-06.08:54:33.789>
user = 'https://bugs.python.org/JeGeVa'

bugs.python.org fields:

activity = <Date 2020-03-06.08:54:33.789>
actor = 'Je GeVa'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2020-03-04.22:27:00.418>
creator = 'Je GeVa'
dependencies = []
files = []
hgrepos = []
issue_num = 39856
keywords = []
message_count = 4.0
messages = ['363396', '363416', '363470', '363497']
nosy_count = 4.0
nosy_names = ['serhiy.storchaka', 'xtreak', 'Isaac Muse', 'Je GeVa']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue39856'
versions = ['Python 3.7']

@JeGeVa
Copy link
Mannequin Author

JeGeVa mannequin commented Mar 4, 2020

some common Unix style pathname pattern expansions are not supported :

~/ for $HOME
~user/ for $HOME of user
{1,abc,999} for enumeration

ex:

lets say
$ls ~
hello1.a hello2.a helli3.c

then :
$echo ~/hell*{1,3}.*
hello1.a helli3.c

while

> glob.glob("~/hel*")
[]
> glob.glob("/home/jegeva/hel*")
['hello1.a','hello2.a','helli3.c
> glob.glob("/home/jegeva/hell*{1,3}.*")
[]

@JeGeVa JeGeVa mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir labels Mar 4, 2020
@tirkarthi
Copy link
Member

This seems to be similar to bpo-9584. Below are the results in my zsh and bash in Mac.

bash

bash-3.2$ cd /tmp/
bash-3.2$ ls *py
hello_1.py hello_2.py hello_3.py
bash-3.2$ ls hell*{1-2}.*
ls: hell*{1-2}.*: No such file or directory
bash-3.2$ ls hell*[1-2].*
hello_1.py hello_2.py

zsh

➜ /tmp ls *py
hello_1.py hello_2.py hello_3.py
➜ /tmp ls hell*{1-2}.*
zsh: no matches found: hell*{1-2}.*
➜ /tmp ls hell*[1-2].*
hello_1.py hello_2.py

Try using []

>>> import glob
>>> glob.glob("hell*[1-2].*")
['hello_2.py', 'hello_1.py']

@tirkarthi tirkarthi added type-bug An unexpected behavior, bug, or error labels Mar 5, 2020
@IsaacMuse
Copy link
Mannequin

IsaacMuse mannequin commented Mar 6, 2020

Brace expansion does not currently exist in Python's glob. You'd have to use a third party module to expand the braces and then run glob on each returned pattern, or use a third party module that implements a glob that does it for you.

Shameless plug:

Brace expansion: https://github.com/facelessuser/bracex

Glob that does it for you (when the feature is enabled): https://github.com/facelessuser/wcmatch

Now whether Python should integrate such behavior by default is another question.

@JeGeVa
Copy link
Mannequin Author

JeGeVa mannequin commented Mar 6, 2020

well ;

  1. tilde expansion
    this is an issue

  2. brace expansion
    have no clue how the engineers at the fruity company maimed your bash and
    zsh man but brace expansion is core to both of them.
    https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html
    http://zsh.sourceforge.net/Doc/Release/Expansion.html#Brace-Expansion

hence :

BASH
/tmp/testdir_issue39856$ $SHELL --version|head -n1
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
/tmp/testdir_issue39856$ ls
hello_1.py hello_2.py hello_3.py
/tmp/testdir_issue39856$ ls hell*{1,2}.*
hello_1.py hello_2.py
/tmp/testdir_issue39856$ ls hell*{1..3}.*
hello_1.py hello_2.py hello_3.py

ZSH
nocte% $SHELL --version|head -n1
zsh 5.8 (x86_64-debian-linux-gnu)
nocte% ls hell*{1,2}.*
hello_1.py hello_2.py
nocte% ls hell*{1..3}.*
hello_1.py hello_2.py hello_3.py

TCSH
nocte:/tmp/testdir_issue39856> /bin/tcsh --version
tcsh 6.21.00 (Astron) 2019-05-08 (x86_64-unknown-linux) options
wide,nls,dl,al,kan,sm,rh,nd,color,filec
nocte:/tmp/testdir_issue39856> ls hell*{1,2}.*
hello_1.py hello_2.py

for history sake :
https://unix.stackexchange.com/questions/92819/why-is-brace-expansion-not-supported

Apparently :

"While brace expansion like {1,2} originates in csh in the late 70s, and
found its way to Bourne-like shells in bash/zsh/pdksh in the late 80s,
early 90s, the {n1..n2} variant came later first in zsh in 1995 (2.6-beta4).
bash copied it in 2004 (3.0) and ksh93 in 2005 (ksh93r)."
since glob claims the "unix style" and bash is the default unix shell, i
believe it should support it (or maybe change the tatile to 'unix from 40
years ago style' ),
i stand by the issue,

and Kart, on a side note i would sincerely update my base tools if i were
you, bash 3.2 is vulnerable to shellshock for exemple...

Le jeu. 5 mars 2020 à 04:58, Karthikeyan Singaravelan <
report@bugs.python.org> a écrit :

Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment:

This seems to be similar to bpo-9584. Below are the results in my zsh and
bash in Mac.

bash

bash-3.2$ cd /tmp/
bash-3.2$ ls *py
hello_1.py hello_2.py hello_3.py
bash-3.2$ ls hell*{1-2}.*
ls: hell*{1-2}.*: No such file or directory
bash-3.2$ ls hell*[1-2].*
hello_1.py hello_2.py

zsh

➜ /tmp ls *py
hello_1.py hello_2.py hello_3.py
➜ /tmp ls hell*{1-2}.*
zsh: no matches found: hell*{1-2}.*
➜ /tmp ls hell*[1-2].*
hello_1.py hello_2.py

Try using []

>>> import glob
>>> glob.glob("hell*[1-2].*")
['hello_2.py', 'hello_1.py']

----------
nosy: +serhiy.storchaka, xtreak
type: -> behavior


Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue39856\>


@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.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
Status: No status
Development

No branches or pull requests

1 participant