MCPcopy
hub / github.com/zappa/Zappa / execute_prebuild_script

Method execute_prebuild_script

zappa/cli.py:3355–3395  ·  view source on GitHub ↗

Parse and execute the prebuild_script from the zappa_settings.

(self)

Source from the content-addressed store, hash-verified

3353 return string
3354
3355 def execute_prebuild_script(self):
3356 """
3357 Parse and execute the prebuild_script from the zappa_settings.
3358 """
3359
3360 (pb_mod_path, pb_func) = self.prebuild_script.rsplit(".", 1)
3361
3362 try: # Prefer prebuild script in working directory
3363 if pb_mod_path.count(".") >= 1: # Prebuild script func is nested in a folder
3364 (mod_folder_path, mod_name) = pb_mod_path.rsplit(".", 1)
3365 mod_folder_path_fragments = mod_folder_path.split(".")
3366 working_dir = os.path.join(os.getcwd(), *mod_folder_path_fragments)
3367 else:
3368 mod_name = pb_mod_path
3369 working_dir = os.getcwd()
3370
3371 working_dir_importer = pkgutil.get_importer(working_dir)
3372 module_ = working_dir_importer.find_spec(mod_name).loader.load_module(mod_name)
3373
3374 except (ImportError, AttributeError):
3375 try: # Prebuild func might be in virtualenv
3376 module_ = importlib.import_module(pb_mod_path)
3377 except ImportError: # pragma: no cover
3378 raise ClickException(
3379 click.style("Failed ", fg="red")
3380 + "to "
3381 + click.style("import prebuild script ", bold=True)
3382 + 'module: "{pb_mod_path}"'.format(pb_mod_path=click.style(pb_mod_path, bold=True))
3383 )
3384
3385 if not hasattr(module_, pb_func): # pragma: no cover
3386 raise ClickException(
3387 click.style("Failed ", fg="red")
3388 + "to "
3389 + click.style("find prebuild script ", bold=True)
3390 + 'function: "{pb_func}" '.format(pb_func=click.style(pb_func, bold=True))
3391 + 'in module "{pb_mod_path}"'.format(pb_mod_path=pb_mod_path)
3392 )
3393
3394 prebuild_function = getattr(module_, pb_func)
3395 prebuild_function() # Call the function
3396
3397 def collision_warning(self, item):
3398 """

Callers 3

packageMethod · 0.95
deployMethod · 0.95
updateMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected