Skip to content
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
13 changes: 10 additions & 3 deletions easybuild/tools/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
import glob
import os
import re
import sys
import importlib

from string import ascii_letters, digits

from easybuild.base import fancylogger
Expand Down Expand Up @@ -132,9 +133,15 @@ def import_available_modules(namespace):
:param namespace: The namespace to import modules from.
"""
modules = []
for path in sys.path:

cand_modpath_glob = os.path.sep.join([path] + namespace.split('.') + ['*.py'])
try:
mod = importlib.import_module(namespace)
except ImportError as err:
raise EasyBuildError("import_available_modules: Failed to import %s: %s", namespace, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the semantics of import_available_modules, since no hard error was being raised before when the specified namespace didn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what i can see import_available_modules is always used to import all sub-modules of a specific namespace similar to doing a from NAMESPACE import *.

In particular for #4451 the failure would be obfuscated as something EB requires missing

I did not see a use in framework where this is expected to fail the import with it not being a problem.

If we really wanted to preserve the original behavior we could add a strict parameter to the call that default to False and set it to true everywhere this is used


for path in mod.__path__:

cand_modpath_glob = os.path.sep.join([path] + ['*.py'])

# if sys.path entry being considered is the empty string
# (which corresponds to Python packages/modules in current working directory being considered),
Expand Down