Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load(cls, *args, _kernel=kernel, **kwargs):
# Our object here really just acts as a record for our JSIIAssembly, it doesn't
# offer any functionality itself, besides this class method that will trigger
# the loading of the given assembly in the JSII Kernel.
assembly = cls(*args, **kwargs)
# Actually load the assembly into the kernel, we're using the
# importlib.resources API here isntead of manually constructing the path, in
# the hopes that this will make JSII modules able to be used with zipimport
# instead of only on the FS.
with importlib_resources.path(
f"{assembly.module}._jsii", assembly.filename
) as assembly_path:
_kernel.load(assembly.name, assembly.version, os.fspath(assembly_path))
# Give our record of the assembly back to the caller.
return assembly