From 9a6e0410352d1a2a52e9e0365c47d02bc0a7b886 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 1 Feb 2023 16:03:10 +0100 Subject: [PATCH] Make config values optional --- unimore_bda_6/config.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/unimore_bda_6/config.py b/unimore_bda_6/config.py index 5e5540d..eb93fc0 100644 --- a/unimore_bda_6/config.py +++ b/unimore_bda_6/config.py @@ -3,27 +3,34 @@ import cfig config = cfig.Configuration() -@config.required() -def MONGO_HOST(val: str) -> str: +@config.optional() +def MONGO_HOST(val: str | None) -> str: """ The hostname of the MongoDB database to connect to. """ - return val + return val or "127.0.0.1" -@config.required() -def MONGO_PORT(val: str) -> str: +@config.optional() +def MONGO_PORT(val: str | None) -> int: """ The port of the MongoDB database to connect to. """ - return val + if not val: + return 27017 + try: + return int(val) + except ValueError: + raise cfig.InvalidValueError("Not an int.") -@config.required() -def TRAINING_SET_SIZE(val: str) -> int: +@config.optional() +def TRAINING_SET_SIZE(val: str | None) -> int: """ The number of reviews from each category to fetch for the training set. """ + if not val: + return 1000 try: return int(val) except ValueError: