1
Fork 0
mirror of https://github.com/Steffo99/unimore-bda-6.git synced 2024-11-29 03:04:18 +00:00

Make config values optional

This commit is contained in:
Steffo 2023-02-01 16:03:10 +01:00
parent f544850403
commit 9a6e041035
Signed by: steffo
GPG key ID: 2A24051445686895

View file

@ -3,27 +3,34 @@ import cfig
config = cfig.Configuration() config = cfig.Configuration()
@config.required() @config.optional()
def MONGO_HOST(val: str) -> str: def MONGO_HOST(val: str | None) -> str:
""" """
The hostname of the MongoDB database to connect to. The hostname of the MongoDB database to connect to.
""" """
return val return val or "127.0.0.1"
@config.required() @config.optional()
def MONGO_PORT(val: str) -> str: def MONGO_PORT(val: str | None) -> int:
""" """
The port of the MongoDB database to connect to. 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() @config.optional()
def TRAINING_SET_SIZE(val: str) -> int: def TRAINING_SET_SIZE(val: str | None) -> int:
""" """
The number of reviews from each category to fetch for the training set. The number of reviews from each category to fetch for the training set.
""" """
if not val:
return 1000
try: try:
return int(val) return int(val)
except ValueError: except ValueError: