Reverted reset_namespace idea. Didn't turn out as clean as I wanted it to.

This commit is contained in:
Anton Hvornum 2021-03-21 15:13:08 +01:00
parent 28606cde61
commit a9f177e722
No known key found for this signature in database
GPG Key ID: F1234C5BA67C59DF
2 changed files with 3 additions and 11 deletions

View File

@ -125,9 +125,7 @@ class Script():
else:
raise ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}")
def load_instructions(self, namespace=None, reset_namespace=False):
original_namespace = self.namespace
def load_instructions(self, namespace=None):
if namespace:
self.namespace = namespace
@ -137,12 +135,6 @@ class Script():
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):
@ -181,7 +173,7 @@ class Profile(Script):
# if __name__ == 'moduleName'
if '__name__' in source_data and '_prep_function' in source_data:
print(f"Checking if {self} has _prep_function by importing with namespace {self.namespace}.py")
with self.load_instructions(namespace=f"{self.namespace}.py", reset_namespace=True) as imported:
with self.load_instructions(namespace=f"{self.namespace}.py") as imported:
if hasattr(imported, '_prep_function'):
return True
return False

View File

@ -170,7 +170,7 @@ def ask_user_questions():
# Check the potentially selected profiles preperations to get early checks if some additional questions are needed.
if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_prep_function():
print(f"{archinstall.arguments['profile']} has prep-function, loading with namespace {archinstall.arguments['profile'].namespace}.py")
with archinstall.arguments['profile'].load_instructions(namespace=f"{archinstall.arguments['profile'].namespace}.py", reset_namespace=True) as imported:
with archinstall.arguments['profile'].load_instructions(namespace=f"{archinstall.arguments['profile'].namespace}.py") as imported:
if not imported._prep_function():
archinstall.log(
' * Profile\'s preparation requirements was not fulfilled.',