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

added pretty logging and echo via pager GCI challenge #183

Open
wants to merge 3 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
2 changes: 1 addition & 1 deletion evalai/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ def get_host_url():
data = fr.read()
return str(data)
except (OSError, IOError) as e:
echo(e)
echo(style(e, bold=True, fg="red"))
46 changes: 23 additions & 23 deletions evalai/utils/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from bs4 import BeautifulSoup
from beautifultable import BeautifulTable
from click import echo, style
from click import echo, style, echo_via_pager
from datetime import datetime

from evalai.utils.auth import get_request_header, get_host_url
Expand Down Expand Up @@ -43,7 +43,7 @@ def pretty_print_challenge_data(challenges):
end_date = convert_UTC_date_to_local(challenge["end_date"])
values.extend([creator, start_date, end_date])
table.append_row(values)
echo(table)
echo_via_pager(table)


def display_challenges(url):
Expand All @@ -57,7 +57,7 @@ def display_challenges(url):
except requests.exceptions.HTTPError as err:
if response.status_code == 401:
validate_token(response.json())
echo(err)
echo(style(err, fg="red", bold=True))
sys.exit(1)
except requests.exceptions.RequestException:
echo(
Expand All @@ -76,7 +76,7 @@ def display_challenges(url):
if len(challenges) != 0:
pretty_print_challenge_data(challenges)
else:
echo("Sorry, no challenges found.")
echo(style("Sorry, no challenges found.", fg="red", bold=True,))


def display_all_challenge_list():
Expand Down Expand Up @@ -108,7 +108,7 @@ def display_ongoing_challenge_list():
except requests.exceptions.HTTPError as err:
if response.status_code == 401:
validate_token(response.json())
echo(err)
echo(style(err, fg="red", bold=True))
sys.exit(1)
except requests.exceptions.RequestException:
echo(
Expand Down Expand Up @@ -138,7 +138,7 @@ def display_ongoing_challenge_list():
if len(challenges) != 0:
pretty_print_challenge_data(challenges)
else:
echo("Sorry, no challenges found.")
echo(style("Sorry, no challenges found.", fg="red", bold=True,))


def display_future_challenge_list():
Expand All @@ -161,7 +161,7 @@ def get_participant_or_host_teams(url):
except requests.exceptions.HTTPError as err:
if response.status_code == 401:
validate_token(response.json())
echo(err)
echo(style(err, fg="red", bold=True))
sys.exit(1)
except requests.exceptions.RequestException:
echo(
Expand Down Expand Up @@ -192,7 +192,7 @@ def get_participant_or_host_team_challenges(url, teams):
except requests.exceptions.HTTPError as err:
if response.status_code == 401:
validate_token(response.json())
echo(err)
echo(style(err, fg="red", bold=True))
sys.exit(1)
except requests.exceptions.RequestException:
echo(
Expand Down Expand Up @@ -253,8 +253,8 @@ def display_participated_or_hosted_challenges(
filter(
lambda challenge: validate_date_format(
challenge["end_date"]
)
> datetime.now()
) >

Choose a reason for hiding this comment

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

@neelr flake8 is giving out this error

evalai-cli/evalai/utils/challenges.py:256:23: W504 line break after binary operator

We can find it here.

datetime.now()
and challenge["approved_by_admin"]
and challenge["published"],
challenges,
Expand Down Expand Up @@ -295,7 +295,7 @@ def pretty_print_challenge_details(challenge):
list(map(lambda item: clean_data(challenge[item]), attributes))
)
table.append_row(values)
echo(table)
echo_via_pager(table)


def display_challenge_details(challenge):
Expand Down Expand Up @@ -328,7 +328,7 @@ def display_challenge_details(challenge):
)
)
else:
echo(err)
echo(style(err, fg="red", bold=True))
sys.exit(1)
except requests.exceptions.RequestException:
echo(
Expand Down Expand Up @@ -363,7 +363,7 @@ def pretty_print_all_challenge_phases(phases):
description = clean_data(phase["description"])
values.append(description)
table.append_row(values)
echo(table)
echo_via_pager(table)


def display_challenge_phase_list(challenge_id):
Expand Down Expand Up @@ -402,7 +402,7 @@ def display_challenge_phase_list(challenge_id):
)
)
else:
echo(err)
echo(style(err, fg="red", bold=True))
sys.exit(1)
except requests.exceptions.RequestException:
echo(
Expand Down Expand Up @@ -478,7 +478,7 @@ def pretty_print_challenge_phase_data(phase):
is_active,
is_public,
)
echo(challenge_phase)
echo_via_pager(challenge_phase)


def display_challenge_phase_detail(challenge_id, phase_id, is_json):
Expand Down Expand Up @@ -507,7 +507,7 @@ def display_challenge_phase_detail(challenge_id, phase_id, is_json):
)
)
else:
echo(err)
echo(style(err, fg="red", bold=True))
sys.exit(1)
except requests.exceptions.RequestException:
echo(
Expand All @@ -525,7 +525,7 @@ def display_challenge_phase_detail(challenge_id, phase_id, is_json):
phase = response
if is_json:
phase_json = json.dumps(phase, indent=4, sort_keys=True)
echo(phase_json)
echo_via_pager(phase_json)
else:
pretty_print_challenge_phase_data(phase)

Expand All @@ -547,7 +547,7 @@ def pretty_print_challenge_phase_split_data(phase_splits):
if split["visibility"] == 3:
values = list(map(lambda item: split[item], attributes))
table.append_row(values)
echo(table)
echo(style(table, fg="blue"))


def display_challenge_phase_split_list(challenge_id):
Expand Down Expand Up @@ -575,7 +575,7 @@ def display_challenge_phase_split_list(challenge_id):
)
)
else:
echo(err)
echo(style(err, fg="red", bold=True))
sys.exit(1)
except requests.exceptions.RequestException:
echo(
Expand All @@ -592,7 +592,7 @@ def display_challenge_phase_split_list(challenge_id):
if len(phase_splits) != 0:
pretty_print_challenge_phase_split_data(phase_splits)
else:
echo("Sorry, no Challenge Phase Splits found.")
echo(style("Sorry, no Challenge Phase Splits found.", fg="red", bold=True))


def pretty_print_leaderboard_data(attributes, results):
Expand All @@ -614,7 +614,7 @@ def pretty_print_leaderboard_data(attributes, results):

leaderboard_row = [rank, name] + scores + [last_submitted]
leaderboard_table.append_row(leaderboard_row)
echo(leaderboard_table)
echo_via_pager(leaderboard_table)


def display_leaderboard(challenge_id, phase_split_id):
Expand All @@ -638,7 +638,7 @@ def display_leaderboard(challenge_id, phase_split_id):
)
)
else:
echo(err)
echo(style(err, fg="red", bold=True))
sys.exit(1)
except requests.exceptions.RequestException:
echo(
Expand All @@ -658,4 +658,4 @@ def display_leaderboard(challenge_id, phase_split_id):
attributes = results[0]["leaderboard__schema"]["labels"]
pretty_print_leaderboard_data(attributes, results)
else:
echo("Sorry, no Leaderboard results found.")
echo("Sorry, no Leaderboard results found.", bold=True, fg="red",)