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,7 +135,10 @@ class Script():
|
||||||
imported = importlib.util.module_from_spec(self.spec)
|
imported = importlib.util.module_from_spec(self.spec)
|
||||||
sys.modules[self.namespace] = imported
|
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:
|
if reset_namespace:
|
||||||
self.namespace = original_namespace
|
self.namespace = original_namespace
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue