Skip to content

challenge

Class describing a challenge

Challenge

CLI's interpretation of a challenge

get(self, key, ensure_exists=False, help_msg='')

Gets a key from config

Prints help_msg if ensure_exists is True and key not found

Parameters:

Name Type Description Default
key str

the config setting you are looking for

required
ensure_exists bool

should this die if key doesn't exist?

False
help_msg str

how to fix this issue

''

Returns:

Type Description
str

the value for the key

Source code in aicrowd/contexts/challenge.py
def get(self, key: str, ensure_exists: bool = False, help_msg: str = "") -> str:
    """
    Gets a key from config

    Prints help_msg if ensure_exists is True and key not found

    Args:
        key: the config setting you are looking for
        ensure_exists: should this die if key doesn't exist?
        help_msg: how to fix this issue

    Returns:
        the value for the key
    """
    if self.info is None:
        self.load()

    value = self.info.get(key)

    if value is None and ensure_exists:
        self.log.warning("Queried challenge config for %s but not found", key)
        raise CLIException(
            f"Challenge config property {key} not set", help_msg, CONFIG_NOT_SET
        )

    return value

load(self)

Check git config for CLI stuff

Source code in aicrowd/contexts/challenge.py
def load(self):
    """
    Check git config for CLI stuff
    """
    try:
        with Repo(".").config_reader() as git_conf:
            challenge_id = git_conf.get_value(
                ChallengeConstants.CONFIG_SECTION_NAME,
                ChallengeConstants.CONFIG_ID_KEY,
            )
            challenge_slug = git_conf.get_value(
                ChallengeConstants.CONFIG_SECTION_NAME,
                ChallengeConstants.CONFIG_SLUG_KEY,
            )

            self.info = {
                ChallengeConstants.CONFIG_ID_KEY: challenge_id,
                ChallengeConstants.CONFIG_SLUG_KEY: challenge_slug,
            }
            self.log.info("Read challenge config\n---\n%s\n---", self.info)
    except Exception as e:
        self.log.error("Error while reading the git config, %s", e)
        self.info = {}