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

Apply sort and filter of walk_packages consistently #39498

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/sage/misc/package_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ def iter_modules(path=None, prefix=''):
yielded[name] = 1
yield ModuleInfo(i, name, ispkg)

def iter_importer_modules(importer, prefix=''):
def _iter_importer_modules_helper(importer, prefix=''):
r"""
Yield :class:`ModuleInfo` for all modules of ``importer``.
Helper function for :func:`iter_importer_modules`.
"""
from importlib.machinery import FileFinder

Expand All @@ -391,11 +391,6 @@ def iter_importer_modules(importer, prefix=''):

for fn in filenames:
modname = inspect.getmodulename(fn)
if modname and (modname in ['__init__', 'all']
or modname.startswith('all__')
or modname in yielded):
continue

path = os.path.join(importer.path, fn)
ispkg = False

Expand All @@ -414,6 +409,18 @@ def iter_importer_modules(importer, prefix=''):
else:
yield from importer.iter_modules(prefix)

def iter_importer_modules(importer, prefix=''):
r"""
Yield :class:`ModuleInfo` for all modules of ``importer``.
"""
for name, ispkg in sorted(list(_iter_importer_modules_helper(importer, prefix))):
# we sort again for consistency of output ordering if importer is not
# a FileFinder (needed in doctest of :func:`sage.misc.dev_tools/load_submodules`)
modname = name.rsplit('.', 1)[-1]
if modname in ['__init__', 'all'] or modname.startswith('all__'):
continue
yield name, ispkg

def seen(p, m={}):
if p in m:
return True
Expand Down
Loading