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

Fix for enhancement#1003: Google Code-in Task to add a command for di… #256

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions evalai/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .teams import teams
from .get_token import get_token
from .login import login
from .submission_error import submission_error


@click.version_option()
Expand Down Expand Up @@ -40,6 +41,7 @@ def main(ctx):
main.add_command(push)
main.add_command(set_token)
main.add_command(submission)
main.add_command(submission_error)
Copy link
Member

@krtkvrm krtkvrm Jan 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about you nest this under submission command:

$ evalai submission <ID> stderr

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As suggested I updated the changes. please review and let me know in google codein task page.

to test use:

evalai submission 48728 stderr

main.add_command(teams)
main.add_command(get_token)
main.add_command(login)
45 changes: 45 additions & 0 deletions evalai/submission_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os

import base64
import boto3
import click
import docker
import json
import requests
import shutil
import sys
import tempfile
import urllib.parse as urlparse
import uuid

from click import echo, style

from evalai.utils.common import notify_user
from evalai.utils.requests import make_request
from evalai.utils.submissions import (
display_submission_stderr,
convert_bytes_to,
)
from evalai.utils.urls import URLS
from evalai.utils.config import EVALAI_HOST_URLS, HOST_URL_FILE_PATH


class Submission(object):

def __init__(self, submission_id):
self.submission_id = submission_id


@click.group(invoke_without_command=True)
@click.argument("SUBMISSION_ID", type=int)
@click.pass_context
def submission_error(ctx, submission_id):
"""
Display submission Error using submission id.
"""
"""
Invoked by `evalai submission_error SUBMISSION_ID`.
"""
ctx.obj = Submission(submission_id=submission_id)
if ctx.invoked_subcommand is None:
display_submission_stderr(submission_id)
22 changes: 22 additions & 0 deletions evalai/utils/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,28 @@ def display_submission_result(submission_id):
)
)

def display_submission_stderr(submission_id):
"""
Function to display stderr file of a particular submission in Terminal output
"""
try:
response = submission_details_request(submission_id).json()
file_url = requests.get(response['stderr_file']).text
with open(file_url, "r") as fr:
try:
file_contents = fr.read()
print (file_contents)
fr.close()
except (OSError, IOError) as e:
echo(e)
except requests.exceptions.MissingSchema:
echo(
style(
"\nThe Submission is yet to be evaluated.\n",
bold=True,
fg="yellow",
)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why have you used requests.exceptions.MissingSchema.
Going by docs,MissingSchema is for The URL schema (e.g. http or https) is missing. exception.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vkartik97, I used this exception because as per your earlier note on my previous task “display stdout message in terminal” the stdout file is generated after the submission evaluation is completed. So if the submission id is not available means that it is supposed to be "yet to be evaluated". So I thought that would be right exception error. I just followed the same def function “display_submission_result” code from submissions.py for this one as well. Let me know if you don’t want this exception to be shown, then what exception you are suggesting. Thank you

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use other exception or use status data from the payload


def convert_bytes_to(byte, to, bsize=1024):
"""
Expand Down