Skip to content

Commit 103817a

Browse files
nritscheketiltrout
authored andcommitted
feat(config): support endpoints grouped by dirs
1 parent b61cb07 commit 103817a

1 file changed

Lines changed: 32 additions & 19 deletions

File tree

coco/config.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -279,22 +279,35 @@ def _load_endpoint_config(config):
279279

280280
endpoint_dir = Path(config["endpoint_dir"])
281281

282-
for endpoint_file in endpoint_dir.iterdir():
283-
# Only accept files ending in .conf as endpoint configs.
284-
# Endpoint config files starting with an underscore (_) are disabled.
285-
if endpoint_file.suffix == ".conf" and not endpoint_file.name.startswith("_"):
286-
logger.debug(f"Loading endpoint config {endpoint_file}.")
287-
288-
# Remove .conf from the config file name to get the name of the endpoint
289-
name = endpoint_file.stem
290-
291-
with endpoint_file.open("r") as fh:
292-
try:
293-
conf = yaml.safe_load(fh)
294-
except yaml.YAMLError as exc:
295-
logger.error(f"Failure reading YAML file {endpoint_file}: {exc}")
296-
297-
conf["name"] = name
298-
299-
# TODO: validate the endpoint config in here
300-
config["endpoints"].append(conf)
282+
def iterate_endpoint_dir(dir):
283+
for dir_entry in dir.iterdir():
284+
285+
def load_endpoint(_file):
286+
# Only accept files ending in .conf as endpoint configs.
287+
# Endpoint config files starting with an underscore (_) are disabled.
288+
if _file.suffix == ".conf" and not _file.name.startswith("_"):
289+
logger.debug(f"Loading endpoint config {_file}.")
290+
291+
# Remove .conf from the config file name to get the name of the endpoint
292+
name = _file.stem
293+
294+
with _file.open("r") as fh:
295+
try:
296+
conf = yaml.safe_load(fh)
297+
except yaml.YAMLError as exc:
298+
logger.error(f"Failure reading YAML file {_file}: {exc}")
299+
300+
conf["name"] = name
301+
# The last part of the relative path is '.'
302+
conf["path"] = list(_file.relative_to(endpoint_dir).parents)[:-1]
303+
logger.error(f"Loaded endpoint {name} with parents: {conf['path']}")
304+
305+
# TODO: validate the endpoint config in here
306+
config["endpoints"].append(conf)
307+
308+
if dir_entry.is_dir():
309+
iterate_endpoint_dir(dir_entry)
310+
else:
311+
load_endpoint(dir_entry)
312+
313+
iterate_endpoint_dir(endpoint_dir)

0 commit comments

Comments
 (0)