Enabling load_instructions() to set a temporary namespace, and then reverting it after the instructions are loaded. This is to temporarly override the namespace during import - enabling avoidance of triggering __name__ checks, and at the same time reverting back the namespace automatically to enable .execute() on the script (reusability of classes)
This commit is contained in:
parent
9ee6479701
commit
28606cde61
|
|
@ -135,11 +135,14 @@ class Script():
|
|||
imported = importlib.util.module_from_spec(self.spec)
|
||||
sys.modules[self.namespace] = imported
|
||||
|
||||
print(f"Imported {self} into sys.modules with namespace {self.namespace}.")
|
||||
print(f"Imported {self} into sys.modules with namespace {self.namespace}")
|
||||
|
||||
if '.py' not in self.namespace:
|
||||
raise KeyError(f"Debugging: {self.namespace}, {reset_namespace}, {self}")
|
||||
|
||||
if reset_namespace:
|
||||
self.namespace = original_namespace
|
||||
|
||||
|
||||
return self
|
||||
|
||||
def execute(self):
|
||||
|
|
|
|||
Loading…
Reference in New Issue