Auto-update: Thu Aug 8 21:28:32 PDT 2024

This commit is contained in:
sanj 2024-08-08 21:28:32 -07:00
parent 69a657910d
commit c9c36b4c42

View file

@ -244,14 +244,18 @@ class DirConfig(BaseModel):
config_data['HOME'] = str(Path.home())
print(f"HOME was not in config, set to default: {config_data['HOME']}")
instance = cls.create_dynamic_model(**config_data)
resolved_data = instance.resolve_placeholders(config_data)
# Create a temporary instance to resolve placeholders
temp_instance = cls.create_dynamic_model(**config_data)
resolved_data = temp_instance.resolve_placeholders(config_data)
# Create the final instance with resolved data
return cls.create_dynamic_model(**resolved_data)
except Exception as e:
print(f"Error loading configuration: {str(e)}")
raise
@classmethod
def _resolve_path(cls, path: Union[str, Path], default_dir: str) -> Path:
base_path = Path(__file__).parent.parent
@ -286,6 +290,10 @@ class DirConfig(BaseModel):
for match in matches:
if match == 'HOME':
replacement = str(self.HOME)
elif match == 'BASE':
replacement = str(Path(__file__).parent.parent)
elif match == 'DATA':
replacement = str(Path(__file__).parent.parent / "data")
elif hasattr(self, match):
replacement = str(getattr(self, match))
else:
@ -295,6 +303,7 @@ class DirConfig(BaseModel):
return Path(value).expanduser()
@classmethod
def create_dynamic_model(cls, **data):
DynamicModel = create_model(