From 38e5d486b8719d9b577cd5820eaaac4b781f7e34 Mon Sep 17 00:00:00 2001 From: thatmattlove Date: Tue, 7 Dec 2021 09:39:55 -0700 Subject: [PATCH] Return an empty config if a file is missing and not required --- hyperglass/configuration/load.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hyperglass/configuration/load.py b/hyperglass/configuration/load.py index 999e93c..f30dc5f 100644 --- a/hyperglass/configuration/load.py +++ b/hyperglass/configuration/load.py @@ -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,