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: Convert glob.glob to generator-based DFS
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: cben, jlgijsbers
Priority: high Keywords: patch

Created on 2004-04-27 18:25 by cben, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
glob-iglobfix.diff cben, 2004-08-20 11:25 Add `glob.iglob()`, make `glob` a wrapper for it.
Messages (3)
msg45861 - (view) Author: Cherniavsky Beni (cben) * Date: 2004-04-27 18:25
`glob.glob()` currently calls itself recursively to
build a list of matches of the dirname part of the
pattern and then filters by the basename part.  This is
effectively BFS.  ``glob.glob('*/*/*/*/*/foo')`` will
build a huge list of all directories 5 levels deep even
if only a handful of them contain a ``foo`` entry.  A
generator-based recusion would never have to store
these list at once by implementing DFS.
This patch converts the `glob` function to an `iglob`
recursive generator .  `glob()` now just returns
``list(iglob(pattern))``.
I also cleaned up the code a bit (reduced duplicate
`has_magic()` checks and created a second `glob0`
helper func so that the main loop need not be duplicated).

This patch assumes patch 941486 adding
`os.path.lexists()` was applied; if not the lexists
calls will have to be adjasted.

Tests and docs patches included.
msg45862 - (view) Author: Cherniavsky Beni (cben) * Date: 2004-08-20 11:25
Logged In: YES 
user_id=36166

Refreshed against current trunk (2.4a2+ 2004-08-20).
It's a forward patch -p0, at dist/src.  Again, it assumes
patch 941486  (glob-pathfix.diff version) had been applied;
if not s/lexists/exists/g but then neither version of 941486
will apply cleanly.
msg45863 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2005-01-08 13:13
Logged In: YES 
user_id=469548

Checked in on HEAD. Thanks for the patch!

Log message:

Checking in Doc/lib/libglob.tex;
/cvsroot/python/python/dist/src/Doc/lib/libglob.tex,v  <-- 
libglob.tex
new revision: 1.14; previous revision: 1.13
done
Checking in Lib/glob.py;
/cvsroot/python/python/dist/src/Lib/glob.py,v  <--  glob.py
new revision: 1.12; previous revision: 1.11
cvs diff: [13:13:17] waiting for jlgijsbers's lock in
/cvsroot/python/python/dist/src/Doc/lib
done
Checking in Lib/test/test_glob.py;
/cvsroot/python/python/dist/src/Lib/test/test_glob.py,v  <--
 test_glob.py
new revision: 1.9; previous revision: 1.8
done
History
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 40191
2004-04-27 18:25:06cbencreate