From 092e8d14ad3b19baa69215f453592052b37172d5 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Mon, 19 Dec 2022 06:49:38 +0100 Subject: [PATCH] Core: Make apworlds function mostly before Python 3.10 --- setup.py | 1 + worlds/__init__.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index e60753d2..3b3ea562 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,7 @@ import setuptools from Launcher import components, icon_paths from Utils import version_tuple, is_windows, is_linux +# On Python < 3.10 LogicMixin is not currently supported. apworlds: set = { "Subnautica", "Factorio", diff --git a/worlds/__init__.py b/worlds/__init__.py index f0a56d4b..34dece0e 100644 --- a/worlds/__init__.py +++ b/worlds/__init__.py @@ -52,14 +52,20 @@ world_sources.sort() for world_source in world_sources: if world_source.is_zip: importer = zipimport.zipimporter(os.path.join(folder, world_source.path)) - spec = importer.find_spec(world_source.path.split(".", 1)[0]) - mod = importlib.util.module_from_spec(spec) + if hasattr(importer, "find_spec"): # new in Python 3.10 + spec = importer.find_spec(world_source.path.split(".", 1)[0]) + mod = importlib.util.module_from_spec(spec) + else: # TODO: remove with 3.8 support + mod = importer.load_module(world_source.path.split(".", 1)[0]) + mod.__package__ = f"worlds.{mod.__package__}" mod.__name__ = f"worlds.{mod.__name__}" sys.modules[mod.__name__] = mod with warnings.catch_warnings(): warnings.filterwarnings("ignore", message="__package__ != __spec__.parent") - importer.exec_module(mod) + # Found no equivalent for < 3.10 + if hasattr(importer, "exec_module"): + importer.exec_module(mod) else: importlib.import_module(f".{world_source.path}", "worlds")