From 5265331ff5b22dce228912d83298048beff8fb80 Mon Sep 17 00:00:00 2001 From: Denny Biasiolli Date: Wed, 20 Mar 2024 13:50:49 +0100 Subject: [PATCH] Provide a fix for the module importer, deprecated `find_module` in Python 3.12 --- zappa/cli.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/zappa/cli.py b/zappa/cli.py index a89f9816a..e9b35bb38 100755 --- a/zappa/cli.py +++ b/zappa/cli.py @@ -2141,7 +2141,10 @@ def callback(self, position): working_dir = os.getcwd() working_dir_importer = pkgutil.get_importer(working_dir) - module_ = working_dir_importer.find_module(mod_name).load_module(mod_name) + if self.runtime == "python3.12": + module_ = working_dir_importer.find_spec(mod_name).loader.load_module(mod_name) + else: + module_ = working_dir_importer.find_module(mod_name).load_module(mod_name) except (ImportError, AttributeError): try: # Callback func might be in virtualenv @@ -2844,7 +2847,10 @@ def execute_prebuild_script(self): working_dir = os.getcwd() working_dir_importer = pkgutil.get_importer(working_dir) - module_ = working_dir_importer.find_module(mod_name).load_module(mod_name) + if self.runtime == "python3.12": + module_ = working_dir_importer.find_spec(mod_name).loader.load_module(mod_name) + else: + module_ = working_dir_importer.find_module(mod_name).load_module(mod_name) except (ImportError, AttributeError): try: # Prebuild func might be in virtualenv