Debugging tainted namespace on profile modules.
This commit is contained in:
parent
f76f5458da
commit
c1e8e6b58d
|
|
@ -76,7 +76,7 @@ class Script():
|
||||||
self.spec = None
|
self.spec = None
|
||||||
self.examples = None
|
self.examples = None
|
||||||
self.namespace = os.path.splitext(os.path.basename(self.path))[0]
|
self.namespace = os.path.splitext(os.path.basename(self.path))[0]
|
||||||
print(f"Script loaded with namespace: {self.namespace}")
|
print(f"Script {self} loaded with namespace: {self.namespace}")
|
||||||
|
|
||||||
def __enter__(self, *args, **kwargs):
|
def __enter__(self, *args, **kwargs):
|
||||||
self.execute()
|
self.execute()
|
||||||
|
|
@ -126,17 +126,18 @@ class Script():
|
||||||
raise ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}")
|
raise ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}")
|
||||||
|
|
||||||
def load_instructions(self, namespace=None):
|
def load_instructions(self, namespace=None):
|
||||||
print(f"Load instructions for {self} with namespace {namespace}")
|
if not namespace:
|
||||||
if namespace:
|
namespace = self.namespace
|
||||||
self.namespace = namespace
|
|
||||||
|
|
||||||
if '.py.py' in self.namespace:
|
if namespace in sys.modules:
|
||||||
raise KeyError("Debugging")
|
print(f"Found {self} in sys.modules, returning cached import.")
|
||||||
|
return self
|
||||||
|
|
||||||
self.spec = importlib.util.spec_from_file_location(self.namespace, self.path)
|
self.spec = importlib.util.spec_from_file_location(namespace, self.path)
|
||||||
imported = importlib.util.module_from_spec(self.spec)
|
imported = importlib.util.module_from_spec(self.spec)
|
||||||
sys.modules[self.namespace] = imported
|
sys.modules[namespace] = imported
|
||||||
|
|
||||||
|
print(f"Imported {self} into sys.modules. Returning fresh copy.")
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue