Skip to content

Commit

Permalink
Un-classify from_file config loader
Browse files Browse the repository at this point in the history
  • Loading branch information
booxter committed Nov 22, 2024
1 parent aa31b8f commit 4f64184
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
21 changes: 10 additions & 11 deletions src/letsrolld/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ def __init__(self, name, **kwargs):
def __getattr__(self, key):
return None

@classmethod
def from_file(cls, filename):
try:
with open(filename) as f:
data = json.load(f)
for name, settings in data.items():
yield Config(name, **settings)
except FileNotFoundError:
raise
except json.JSONDecodeError as e:
raise ValueError(f"invalid JSON file: {e}")
def from_file(filename):
try:
with open(filename) as f:
data = json.load(f)
for name, settings in data.items():
yield Config(name, **settings)
except FileNotFoundError:
raise
except json.JSONDecodeError as e:
raise ValueError(f"invalid JSON file: {e}")
3 changes: 1 addition & 2 deletions src/letsrolld/webapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ def get(self, id):

def _get_report_config(id):
# TODO: store configs in db; convert id into actual name
sections = list(lconfig.Config.from_file(os.path.join("configs", "default.json")))
return sections
return list(lconfig.from_file(os.path.join("configs", "default.json")))


# TODO: support freeform text search filter
Expand Down

0 comments on commit 4f64184

Please sign in to comment.