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

Remove usages of legacy importlib API. #2531

Closed
Closed
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
22 changes: 9 additions & 13 deletions hydra/core/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,16 @@ def _scan_all_plugins(
import_time = timer()

with warnings.catch_warnings(record=True) as recorded_warnings:
if sys.version_info < (3, 10):
m = importer.find_module(modname) # type: ignore
assert m is not None
loaded_mod = m.load_module(modname)
spec = importer.find_spec(modname, None)
assert spec is not None
if modname in sys.modules:
loaded_mod = sys.modules[modname]
else:
spec = importer.find_spec(modname)
assert spec is not None
if modname in sys.modules:
loaded_mod = sys.modules[modname]
else:
loaded_mod = importlib.util.module_from_spec(spec)
if loaded_mod is not None:
spec.loader.exec_module(loaded_mod)
sys.modules[modname] = loaded_mod
loaded_mod = importlib.util.module_from_spec(spec)
if loaded_mod is not None:
sys.modules[modname] = loaded_mod
assert spec.loader
spec.loader.exec_module(loaded_mod)
Jasha10 marked this conversation as resolved.
Show resolved Hide resolved

import_time = timer() - import_time
if len(recorded_warnings) > 0:
Expand Down