Skip to content

Commit

Permalink
Config warnings (#1006)
Browse files Browse the repository at this point in the history
* Fix docstring

* Warn when min/max config values are invalid

* Better retrieval of optional config values

* Less restrictive default max opponent rating

* CONFIG.get() not needed since defaults inserted

* Matchmaking handles creating challenges

* opponent_rating_difference has no default

* Specify which game challenges will be ignored
  • Loading branch information
MarkZH authored Aug 12, 2024
1 parent 1fb0822 commit 722d972
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def config_assert(assertion: bool, error_message: str) -> None:


def config_warn(assertion: bool, warning_message: str) -> None:
"""Raise an exception if an assertion is false."""
"""Print a warning message if an assertion is false."""
if not assertion:
logger.warning(warning_message)

Expand Down Expand Up @@ -297,6 +297,23 @@ def validate_config(CONFIG: CONFIG_DICT_TYPE) -> None:
config_assert(CONFIG["challenge"]["preference"] in ["none", "human", "bot"],
"challenge.preference should be `none`, `human`, or `bot`.")

min_max_template = ("challenge.max_{setting} < challenge.min_{setting} will result "
"in no {game_type} challenges being accepted.")
for setting in ["increment", "base", "days"]:
game_type = "correspondence" if setting == "days" else "real-time"
config_warn(CONFIG["challenge"][f"min_{setting}"] <= CONFIG["challenge"][f"max_{setting}"],
min_max_template.format(setting=setting, game_type=game_type))

matchmaking = CONFIG["matchmaking"]
matchmaking_enabled = matchmaking["allow_matchmaking"]

if matchmaking_enabled:
config_warn(matchmaking["opponent_min_rating"] <= matchmaking["opponent_max_rating"],
"matchmaking.opponent_max_rating < matchmaking.opponent_min_rating will result in "
"no challenges being created.")
config_warn(matchmaking.get("opponent_rating_difference", 0) >= 0,
"matchmaking.opponent_rating_difference < 0 will result in no challenges being created.")

pgn_directory = CONFIG["pgn_directory"]
in_docker = os.environ.get("LICHESS_BOT_DOCKER")
config_warn(not pgn_directory or not in_docker, "Games will be saved to '{}', please ensure this folder is in a mounted "
Expand All @@ -310,9 +327,6 @@ def validate_config(CONFIG: CONFIG_DICT_TYPE) -> None:
f"The `pgn_file_grouping` choice of `{config_pgn_choice}` is not valid. "
f"Please choose from {valid_pgn_grouping_options}.")

matchmaking = CONFIG.get("matchmaking") or {}
matchmaking_enabled = matchmaking.get("allow_matchmaking") or False

def has_valid_list(name: str) -> bool:
entries = matchmaking.get(name)
return isinstance(entries, list) and entries[0] is not None
Expand Down

0 comments on commit 722d972

Please sign in to comment.