Skip to content

Commit

Permalink
Setting up sensor.community
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHodson committed Feb 15, 2024
1 parent b29cc59 commit 32ae6a7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/ionbeam/core/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def parse_sub_config(yaml_file: Path, globals, schema=SubConfig):
with open(yaml_file) as f:
config_dict = yaml.load(f, Loader=SafeLineLoader)

print("config_dict", config_dict)
# Parse the yaml file using python dataclasses as a template
config = parse_config_from_dict(schema, config_dict, filepath=yaml_file)

Expand Down
42 changes: 23 additions & 19 deletions src/ionbeam/core/config_parser_machinery.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def parse_list(context, key, list_type, value):
f"you must specifiy what type it contains i.e {list_type.__name__}[int].",
) from None

if value is None: return []
contained_type = args[0]
return [parse_field(context, f"element {i}", contained_type, v) for i, v in enumerate(value)]

Expand Down Expand Up @@ -216,31 +217,34 @@ def parse_field(context, key, _type, value):
can just call the type to construct the object from a string.
"""
# print(_type, value)
if is_dataclass(_type):
# possibly use a subclass instead of the base class
datacls = determine_matching_dataclass(context, key, _type, value)
# print(key, _type, value, datacls)
return dataclass_from_dict(context, datacls, value)
try:
# print(_type, value)
if is_dataclass(_type):
# possibly use a subclass instead of the base class
datacls = determine_matching_dataclass(context, key, _type, value)
# print(key, _type, value, datacls)
return dataclass_from_dict(context, datacls, value)

if is_union(_type):
return parse_union(context, key, _type, value)
if is_union(_type):
return parse_union(context, key, _type, value)

if is_list(_type):
return parse_list(context, key, _type, value)
if is_list(_type):
return parse_list(context, key, _type, value)

if is_literal(_type):
return parse_literal(context, key, _type, value)
if is_literal(_type):
return parse_literal(context, key, _type, value)

if is_dict(_type):
return parse_dict(context, key, _type, value)
if is_dict(_type):
return parse_dict(context, key, _type, value)

try:
result = _type(value)
except Exception as e:
raise ConfigLineError(context, key, _type, value, str(e)) from None
try:
result = _type(value)
except Exception as e:
raise ConfigLineError(context, key, _type, value, str(e)) from None

return result
return result
except Exception as e:
raise ConfigError(f"While parsing {key=}, {_type=}, {value=}, got exception \n\t\t{e}")


@dataclass
Expand Down
1 change: 1 addition & 0 deletions src/ionbeam/sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from .meteotracker.source import MeteoTrackerSource
from .cima.source import CIMASource
from .sensor_community import SensorCommunitySource
from .multi_file import MultiFileSource
from .watch_directory import WatchDirectorySource

Expand Down

0 comments on commit 32ae6a7

Please sign in to comment.