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 replication of code in get_token command #259

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
21 changes: 3 additions & 18 deletions evalai/get_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from click import echo, style

from evalai.utils.auth import get_user_auth_token
from evalai.utils.config import AUTH_TOKEN_PATH
import json

Expand All @@ -12,21 +13,5 @@ def get_token():
"""
Get the EvalAI token.
"""
if not os.path.exists(AUTH_TOKEN_PATH):
echo(
style(
"\nThe authentication token json file doesn't exist at the required path. "
"Please download the file from the Profile section of the EvalAI webapp and "
"place it at ~/.evalai/token.json or use evalai -t <token> to add it.\n\n",
bold=True,
fg="red",
)
)
else:
with open(AUTH_TOKEN_PATH, "r") as fr:
try:
data = fr.read()
tokendata = json.loads(data)
echo("Current token is {}".format(tokendata["token"]))
except (OSError, IOError) as e:
echo(e)
token = get_user_auth_token()
echo(f"Current token is {token}")
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 please change this to echo("Current token is {0}".format(token)) to maintain consistency in codebase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! 👍

2 changes: 1 addition & 1 deletion evalai/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_user_auth_token():
style(
"\nThe authentication token json file doesn't exists at the required path. "
"Please download the file from the Profile section of the EvalAI webapp and "
"place it at ~/.evalai/token.json\n",
"place it at ~/.evalai/token.json or use evalai set_token <token> to add it.\n",
bold=True,
fg="red",
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_get_user_auth_token_when_file_does_not_exist(self):
expected = (
"\nThe authentication token json file doesn't exists at the required path. "
"Please download the file from the Profile section of the EvalAI webapp and "
"place it at ~/.evalai/token.json\n\n"
"place it at ~/.evalai/token.json or use evalai set_token <token> to add it.\n\n"
)
runner = CliRunner()
result = runner.invoke(challenges)
Expand Down