Skip to content

Commit b7da8f2

Browse files
author
Release Manager
committed
gh-39498: Apply sort and filter of walk_packages consistently Previously, the sorting and filtering is only applied in case of FileFinder. This makes it consistently applied. Needed to make tests in #39369 pass. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #39498 Reported by: user202729 Reviewer(s): Tobias Diez
2 parents 3500f61 + 4b24524 commit b7da8f2

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/sage/misc/package_dir.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ def iter_modules(path=None, prefix=''):
402402
yielded[name] = 1
403403
yield ModuleInfo(i, name, ispkg)
404404

405-
def iter_importer_modules(importer, prefix=''):
405+
def _iter_importer_modules_helper(importer, prefix=''):
406406
r"""
407-
Yield :class:`ModuleInfo` for all modules of ``importer``.
407+
Helper function for :func:`iter_importer_modules`.
408408
"""
409409
from importlib.machinery import FileFinder
410410

@@ -423,11 +423,6 @@ def iter_importer_modules(importer, prefix=''):
423423

424424
for fn in filenames:
425425
modname = inspect.getmodulename(fn)
426-
if modname and (modname in ['__init__', 'all']
427-
or modname.startswith('all__')
428-
or modname in yielded):
429-
continue
430-
431426
path = os.path.join(importer.path, fn)
432427
ispkg = False
433428

@@ -446,6 +441,18 @@ def iter_importer_modules(importer, prefix=''):
446441
else:
447442
yield from importer.iter_modules(prefix)
448443

444+
def iter_importer_modules(importer, prefix=''):
445+
r"""
446+
Yield :class:`ModuleInfo` for all modules of ``importer``.
447+
"""
448+
for name, ispkg in sorted(list(_iter_importer_modules_helper(importer, prefix))):
449+
# we sort again for consistency of output ordering if importer is not
450+
# a FileFinder (needed in doctest of :func:`sage.misc.dev_tools/load_submodules`)
451+
modname = name.rsplit('.', 1)[-1]
452+
if modname in ['__init__', 'all'] or modname.startswith('all__'):
453+
continue
454+
yield name, ispkg
455+
449456
def seen(p, m={}):
450457
if p in m:
451458
return True

0 commit comments

Comments
 (0)