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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 4 additions & 22 deletions evalai/get_token.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
import click
import os

from click import echo, style
from click import echo

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


@click.group(invoke_without_command=True)
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("Current token is {0}".format(token))
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