From 465020af9db5961a4d5ce1d9a7ac5180c0e77eb4 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 4 Jan 2020 02:45:32 +0900 Subject: [PATCH 01/11] Add command to display the stdout.txt data in terminal --- evalai/submissions.py | 13 +++++++++++++ evalai/utils/submissions.py | 20 ++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/evalai/submissions.py b/evalai/submissions.py index ac8bccf62..8059e375a 100644 --- a/evalai/submissions.py +++ b/evalai/submissions.py @@ -17,6 +17,7 @@ from evalai.utils.common import notify_user from evalai.utils.requests import make_request from evalai.utils.submissions import ( + display_submission_stdout, display_submission_details, display_submission_result, convert_bytes_to, @@ -63,6 +64,18 @@ def result(ctx): display_submission_result(ctx.submission_id) +@submission.command() +@click.pass_obj +def stdout(ctx): + """ + Display stdout file of the submission + """ + """ + Invoked by `evalai submission SUBMISSION_ID stdout`. + """ + display_submission_stdout(ctx.submission_id) + + @click.command() @click.argument("IMAGE", nargs=1) @click.option( diff --git a/evalai/utils/submissions.py b/evalai/utils/submissions.py index 19d9fc3e4..604023c5b 100644 --- a/evalai/utils/submissions.py +++ b/evalai/utils/submissions.py @@ -14,7 +14,6 @@ convert_UTC_date_to_local, ) - requests.packages.urllib3.disable_warnings() @@ -142,7 +141,7 @@ def pretty_print_my_submissions_data(submissions, start_date, end_date): def display_my_submission_details( - challenge_id, phase_id, start_date, end_date + challenge_id, phase_id, start_date, end_date ): """ Function to display the details of a particular submission. @@ -281,6 +280,23 @@ def display_submission_result(submission_id): ) +def display_submission_stdout(submission_id): + """ + Function to display stdout file of a particular submission + """ + try: + response = submission_details_request(submission_id).json() + echo(requests.get(response['stdout_file']).text) + except requests.exceptions.MissingSchema: + echo( + style( + "\nThe Submission does not have stdout file.\n", + bold=True, + fg="red", + ) + ) + + def convert_bytes_to(byte, to, bsize=1024): """ Convert bytes to KB, MB, GB etc. From 233d4145c2f1ba8d1fba53751eac8ee27679b789 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 4 Jan 2020 02:49:48 +0900 Subject: [PATCH 02/11] Reorder imports --- evalai/submissions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evalai/submissions.py b/evalai/submissions.py index 8059e375a..a10b03f25 100644 --- a/evalai/submissions.py +++ b/evalai/submissions.py @@ -17,10 +17,10 @@ from evalai.utils.common import notify_user from evalai.utils.requests import make_request from evalai.utils.submissions import ( - display_submission_stdout, + convert_bytes_to, display_submission_details, display_submission_result, - convert_bytes_to, + display_submission_stdout, ) from evalai.utils.urls import URLS from evalai.utils.config import ( From b15c83172af66183ea8ff4182811248d11248b39 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 4 Jan 2020 03:22:34 +0900 Subject: [PATCH 03/11] Add a test case --- tests/data/submission_response.py | 2 +- tests/test_submissions.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/data/submission_response.py b/tests/data/submission_response.py index e9ee30474..f9d93673e 100644 --- a/tests/data/submission_response.py +++ b/tests/data/submission_response.py @@ -117,7 +117,7 @@ "publication_url": null, "status": "submitted", "stderr_file": null, - "stdout_file": null, + "stdout_file": "https://example.com", "submission_result_file": "http://testserver/media/submission_files/submission_9/result.json", "submitted_at": "2018-06-08T09:24:09.866590Z", "when_made_public": null diff --git a/tests/test_submissions.py b/tests/test_submissions.py index 02f65fc76..e9fd7ab99 100644 --- a/tests/test_submissions.py +++ b/tests/test_submissions.py @@ -38,6 +38,13 @@ def setup(self): status=200, ) + responses.add( + responses.GET, + self.submission["stdout_file"], + body="Test Submission Stdout File", + status=200, + ) + @responses.activate def test_display_submission_details(self): team_title = "\n{}".format(self.submission["participant_team_name"]) @@ -100,6 +107,14 @@ def test_display_submission_result(self): response = result.output.strip() assert response == expected + @responses.activate + def test_display_submission_stdout(self): + expected = "Test Submission Stdout File" + runner = CliRunner() + result = runner.invoke(submission, ["9", "stdout"]) + response = result.output.strip() + assert response == expected + class TestMakeSubmission(BaseTestClass): def setup(self): From 65d75d019716f1270304b0e1d714e8c814c46f9a Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 4 Jan 2020 03:25:43 +0900 Subject: [PATCH 04/11] Delete unreachable lines --- evalai/utils/submissions.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/evalai/utils/submissions.py b/evalai/utils/submissions.py index 604023c5b..d07b77a35 100644 --- a/evalai/utils/submissions.py +++ b/evalai/utils/submissions.py @@ -284,17 +284,8 @@ def display_submission_stdout(submission_id): """ Function to display stdout file of a particular submission """ - try: - response = submission_details_request(submission_id).json() - echo(requests.get(response['stdout_file']).text) - except requests.exceptions.MissingSchema: - echo( - style( - "\nThe Submission does not have stdout file.\n", - bold=True, - fg="red", - ) - ) + response = submission_details_request(submission_id).json() + echo(requests.get(response['stdout_file']).text) def convert_bytes_to(byte, to, bsize=1024): From 282f6ffa306cf5a724da2e78c15d82d1dc73a335 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 4 Jan 2020 03:43:28 +0900 Subject: [PATCH 05/11] Revert unintended changes --- evalai/utils/submissions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/evalai/utils/submissions.py b/evalai/utils/submissions.py index d07b77a35..782ff95b9 100644 --- a/evalai/utils/submissions.py +++ b/evalai/utils/submissions.py @@ -14,6 +14,7 @@ convert_UTC_date_to_local, ) + requests.packages.urllib3.disable_warnings() @@ -141,7 +142,7 @@ def pretty_print_my_submissions_data(submissions, start_date, end_date): def display_my_submission_details( - challenge_id, phase_id, start_date, end_date + challenge_id, phase_id, start_date, end_date ): """ Function to display the details of a particular submission. From 979d7b4c75a5dbbcbd7515f512bac91955b1f653 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 4 Jan 2020 03:50:44 +0900 Subject: [PATCH 06/11] Improve the test value of stdout_file --- tests/data/submission_response.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data/submission_response.py b/tests/data/submission_response.py index f9d93673e..43f0b3e64 100644 --- a/tests/data/submission_response.py +++ b/tests/data/submission_response.py @@ -117,7 +117,7 @@ "publication_url": null, "status": "submitted", "stderr_file": null, - "stdout_file": "https://example.com", + "stdout_file": "http://testserver/media/submission_files/submission_9/stdout.txt", "submission_result_file": "http://testserver/media/submission_files/submission_9/result.json", "submitted_at": "2018-06-08T09:24:09.866590Z", "when_made_public": null From 2064ff1dd38806d43217e240b1d9c142f15c8da3 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Mon, 6 Jan 2020 21:22:51 +0900 Subject: [PATCH 07/11] Add error handling codes --- evalai/utils/submissions.py | 13 +++++++++-- tests/data/submission_response.py | 25 ++++++++++++++++++++- tests/test_submissions.py | 36 +++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/evalai/utils/submissions.py b/evalai/utils/submissions.py index 782ff95b9..0ee201a14 100644 --- a/evalai/utils/submissions.py +++ b/evalai/utils/submissions.py @@ -285,8 +285,17 @@ def display_submission_stdout(submission_id): """ Function to display stdout file of a particular submission """ - response = submission_details_request(submission_id).json() - echo(requests.get(response['stdout_file']).text) + try: + response = submission_details_request(submission_id).json() + echo(requests.get(response['stdout_file']).text) + except requests.exceptions.MissingSchema: + echo( + style( + "\nThe Submission does not have stdout file.", + bold=True, + fg="red", + ) + ) def convert_bytes_to(byte, to, bsize=1024): diff --git a/tests/data/submission_response.py b/tests/data/submission_response.py index 43f0b3e64..935797d82 100644 --- a/tests/data/submission_response.py +++ b/tests/data/submission_response.py @@ -117,12 +117,35 @@ "publication_url": null, "status": "submitted", "stderr_file": null, - "stdout_file": "http://testserver/media/submission_files/submission_9/stdout.txt", + "stdout_file": null, "submission_result_file": "http://testserver/media/submission_files/submission_9/result.json", "submitted_at": "2018-06-08T09:24:09.866590Z", "when_made_public": null }""" +submission_result_with_stdout_and_stderr_file = """ + { + "challenge_phase": 7, + "created_by": 4, + "execution_time": "None", + "id": 10, + "input_file": "http://testserver/media/submission_files/submission_10/2224fb89-6828-\ + 47f4-b170-1279290ad900.json", + "is_public": false, + "method_description": null, + "method_name": null, + "participant_team": 3, + "participant_team_name": "Host_83644_Team", + "project_url": null, + "publication_url": null, + "status": "submitted", + "stderr_file": "http://testserver/media/submission_files/submission_10/stderr.txt", + "stdout_file": "http://testserver/media/submission_files/submission_10/stdout.txt", + "submission_result_file": "http://testserver/media/submission_files/submission_10/result.json", + "submitted_at": "2018-06-08T09:24:09.866590Z", + "when_made_public": null + }""" + aws_credentials = """ { "success": { diff --git a/tests/test_submissions.py b/tests/test_submissions.py index e9fd7ab99..9d0d377c7 100644 --- a/tests/test_submissions.py +++ b/tests/test_submissions.py @@ -107,10 +107,46 @@ def test_display_submission_result(self): response = result.output.strip() assert response == expected + +class TestDisplaySubmissionStdout(BaseTestClass): + def setup(self): + self.submission_with_stdout = json.loads(submission_response.submission_result_with_stdout_and_stderr_file) + self.submission_without_stdout = json.loads(submission_response.submission_result) + + url = "{}{}" + responses.add( + responses.GET, + url.format(API_HOST_URL, URLS.get_submission.value).format("10"), + json=self.submission_with_stdout, + status=200 + ) + + responses.add( + responses.GET, + self.submission_with_stdout["stdout_file"], + body="Test Submission Stdout File", + status=200, + ) + + responses.add( + responses.GET, + url.format(API_HOST_URL, URLS.get_submission.value).format("9"), + json=self.submission_without_stdout, + status=200 + ) + @responses.activate def test_display_submission_stdout(self): expected = "Test Submission Stdout File" runner = CliRunner() + result = runner.invoke(submission, ["10", "stdout"]) + response = result.output.strip() + assert response == expected + + @responses.activate + def test_display_submission_stdout_when_submission_does_not_have_stdout_file(self): + expected = "The Submission does not have stdout file." + runner = CliRunner() result = runner.invoke(submission, ["9", "stdout"]) response = result.output.strip() assert response == expected From 43afb6ad4b493aef7515906b99146bd95280887e Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Mon, 6 Jan 2020 21:28:50 +0900 Subject: [PATCH 08/11] Remove unneeded lines --- tests/test_submissions.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/test_submissions.py b/tests/test_submissions.py index 9d0d377c7..03eb891a1 100644 --- a/tests/test_submissions.py +++ b/tests/test_submissions.py @@ -38,13 +38,6 @@ def setup(self): status=200, ) - responses.add( - responses.GET, - self.submission["stdout_file"], - body="Test Submission Stdout File", - status=200, - ) - @responses.activate def test_display_submission_details(self): team_title = "\n{}".format(self.submission["participant_team_name"]) From 8107d55fd64e1bf1ea41436c04cab8a91580a803 Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Tue, 7 Jan 2020 14:05:51 +0900 Subject: [PATCH 09/11] Add an example of this command to documentation --- docs/index.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/index.html b/docs/index.html index 656bbbd46..5c5df7171 100644 --- a/docs/index.html +++ b/docs/index.html @@ -351,7 +351,19 @@

View status of a submission with ID 78 + <
+
+

View stdout file of a submission with ID 78

+
+
+
Run this command
+
+ evalai submission 78 stdout + + +
+
/div>

Get all the phase splits of the challenge 1 with phase 4

From 99b55b2566a2e243908fad08266746dbb1725dce Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 11 Jan 2020 17:22:18 +0900 Subject: [PATCH 10/11] Fix html typo --- docs/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.html b/docs/index.html index 5c5df7171..47333d4b1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -351,7 +351,7 @@

View status of a submission with ID 78

- <
+

View stdout file of a submission with ID 78

From a6d45abf99db58cb2f8e3538ee5820f2823eadaa Mon Sep 17 00:00:00 2001 From: Takitsuse Nagisa Date: Sat, 11 Jan 2020 17:33:45 +0900 Subject: [PATCH 11/11] Add trailing commas --- tests/test_submissions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_submissions.py b/tests/test_submissions.py index 03eb891a1..ee3936ce9 100644 --- a/tests/test_submissions.py +++ b/tests/test_submissions.py @@ -111,7 +111,7 @@ def setup(self): responses.GET, url.format(API_HOST_URL, URLS.get_submission.value).format("10"), json=self.submission_with_stdout, - status=200 + status=200, ) responses.add( @@ -125,7 +125,7 @@ def setup(self): responses.GET, url.format(API_HOST_URL, URLS.get_submission.value).format("9"), json=self.submission_without_stdout, - status=200 + status=200, ) @responses.activate