Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add env loading #649

Closed
Prev Previous commit
Next Next commit
investigating the errors
stan-dot committed Oct 29, 2024
commit d3f0241149131cd4cd74ceb4190ebdd1a4ab59d4
13 changes: 6 additions & 7 deletions src/blueapi/cli/cli.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
from functools import wraps
from pathlib import Path
from pprint import pprint
from typing import Any, Dict, Optional, Union
from typing import Any

import click
from bluesky.callbacks.best_effort import BestEffortCallback
@@ -33,15 +33,15 @@
from .updates import CliEventRenderer


def load_cli_values(ctx_params: Dict[str, Any]) -> Dict[str, Any]:
def load_cli_values(ctx_params: dict[str, Any]) -> dict[str, Any]:
"""
Load CLI values from the given context parameters.
Args:
ctx_params (Dict[str, Any]): Dictionary containing CLI parameters.
ctx_params (dict[str, Any]): dictionary containing CLI parameters.
Returns:
Dict[str, Any]: A dictionary of CLI values for configuration.
dict[str, Any]: A dictionary of CLI values for configuration.
"""
cli_values = {
# CLI parameters for StompConfig
@@ -80,9 +80,7 @@ def load_cli_values(ctx_params: Dict[str, Any]) -> Dict[str, Any]:
},
# CLI parameters for ScratchConfig (optional)
"scratch": {
"root": Path(ctx_params.get("scratch_root"))
if ctx_params.get("scratch_root")
else None,
"root": ctx_params.get("scratch_root", None),
"repositories": [
{
"name": ctx_params.get("repo_name"),
@@ -123,6 +121,7 @@ def main(
for path in configs:
if path.exists():
config_loader.use_values_from_yaml(path)

else:
raise FileNotFoundError(f"Cannot find file: {path}")

5 changes: 3 additions & 2 deletions src/blueapi/config.py
Original file line number Diff line number Diff line change
@@ -131,7 +131,7 @@ def recursively_updated_map(
and isinstance(value, dict)
):
updated[key] = recursively_updated_map(updated[key], value)
else:
elif value is not None:
updated[key] = value
return updated

@@ -149,7 +149,7 @@ def use_values(self, values: Mapping[str, Any]) -> None:
"""
Use all values provided in the config, override any defaults.
"""
recursively_updated_map(self._values, values)
self._values = recursively_updated_map(self._values, values)

def use_values_from_yaml(self, path: Path) -> None:
"""
@@ -187,6 +187,7 @@ def load(self) -> C:
return self._adapter.validate_python(self._values)
except ValidationError as exc:
pretty_error_messages = pretty_print_errors(exc.errors())

raise InvalidConfigError(
f"Something is wrong with the configuration file:\n{pretty_error_messages}"
) from exc