1
0
Fork 1
mirror of https://github.com/thatmattlove/hyperglass.git synced 2026-01-17 08:48:05 +00:00

Return an empty config if a file is missing and not required

This commit is contained in:
thatmattlove 2021-12-07 09:39:55 -07:00
parent aaad4d9350
commit 38e5d486b8

View file

@ -112,10 +112,16 @@ def load_python(path: Path, *, empty_allowed: bool) -> LoadedConfig:
def load_config(name: str, *, required: bool) -> LoadedConfig:
"""Load a configuration file."""
path = find_path(name, required=required)
if path.suffix == ".py":
if path is None and required is False:
return {}
elif path.suffix == ".py":
return load_python(path, empty_allowed=not required)
elif path.suffix.replace(".", "") in CONFIG_EXTENSIONS:
return load_dsl(path, empty_allowed=not required)
raise ConfigError(
"{p} has an unsupported file extension. Must be one of {e}",
p=path,