Source code for aerosandbox.tools.python.importing
importimportlibimportsys
[docs]deflazy_import(name):""" Allows you to lazily import a module. Usage: >>> asb = lazy_import("aerosandbox") # Runs instantly >>> asb.Airplane() # When this is called, ASB will be loaded. Args: name: The package name Returns: The module itself, to be loaded on first use. """spec=importlib.util.find_spec(name)loader=importlib.util.LazyLoader(spec.loader)spec.loader=loadermodule=importlib.util.module_from_spec(spec)sys.modules[name]=moduleloader.exec_module(module)returnmodule