Skip to content

Commit

Permalink
Remove usages of legacy importlib API.
Browse files Browse the repository at this point in the history
The Python >= 3.10 compatible usages of importlib added in
277ff54 can be safely applied to any
version of Python >= 3.5 which covers the full range that Hydra
supports.

Getting rid of the old decrecated API, asides from cleaning up, will
keep Hydra compatible with PyInstaller if PyInstaller doesn't get cold
feet and revert its dropping of support for the legacy API
(pyinstaller/pyinstaller#7344).
  • Loading branch information
bwoodsend committed Mar 20, 2023
1 parent 4802c40 commit 0f7031b
Showing 1 changed file with 9 additions and 13 deletions.
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)

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

0 comments on commit 0f7031b

Please sign in to comment.