Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to verify challenge config file locally. #170

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions evalai/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
display_challenge_phase_detail,
display_challenge_phase_split_list,
display_leaderboard,
verify_config_file,
)
from evalai.utils.submissions import display_my_submission_details
from evalai.utils.teams import participate_in_a_challenge
Expand Down Expand Up @@ -80,6 +81,16 @@ def challenge(ctx, challenge):
display_challenge_details(challenge)


@challenges.command(context_settings={"ignore_unknown_options": True})
@click.option("--file", type=click.File("rb"), required=True, help="Challenge Zip file.")
@click.argument("team", type=int)
def verify_challenge_config(file, team):
"""
Verify Challenge config zip file locally. Add file path and host team id.
"""
verify_config_file(file, team)


@challenges.command()
def ongoing():
"""
Expand Down
59 changes: 59 additions & 0 deletions evalai/utils/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,65 @@
requests.packages.urllib3.disable_warnings()


def verify_config_file(file, team):
"""
Function to verify a challenge config file.
"""
url = "{}{}".format(get_host_url(), URLS.verify_challenge_config.value)
url = url.format(team)

headers = get_request_header()
file = {"zip_configuration": file}

try:
response = requests.post(url, headers=headers, files=file)
response.raise_for_status()
except requests.exceptions.HTTPError as err:
if response.status_code in EVALAI_ERROR_CODES:
validate_token(response.json())
echo(
style(
"\nError: {}.".format(response.json()["error"]),
fg="red",
bold=True,
)
)
else:
echo(err)
sys.exit(1)
except requests.exceptions.RequestException:
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.",
bold=True,
fg="red",
)
)
sys.exit(1)

response = response.json()
response = json.loads(response)
for results in response:
if results == "Success":
echo(
style(
"\n{}".format(response["Success"]),
fg="green",
bold=True,
)
)
else:
for m in response[results]:
echo(
style(
"\n{}: {}".format(results, m),
fg="red",
bold=False,
)
)


def pretty_print_challenge_data(challenges):
"""
Function to print the challenge data
Expand Down
1 change: 1 addition & 0 deletions evalai/utils/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


class URLS(Enum):
verify_challenge_config = "/api/challenges/challenge/challenge_host_team/{}/verify_challenge_config/"
login = "/api/auth/login"
challenge_list = "/api/challenges/challenge/all"
past_challenge_list = "/api/challenges/challenge/past"
Expand Down