Skip to content

Commit

Permalink
Merge branch 'master' into stable/0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhaoyilunnn committed Jul 26, 2023
2 parents 9c95f40 + e039948 commit 70004b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/quafu/users/_quafu_url.py

This file was deleted.

27 changes: 17 additions & 10 deletions src/quafu/users/userapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import requests

from .exceptions import UserError
from .exceptions import UserError, APITokenNotFound
from ..utils.platform import get_homedir


Expand All @@ -30,12 +30,19 @@ def __init__(self, api_token: str = None, token_dir: str = None):
self.token_dir = token_dir

if api_token is None:
self.api_token = self._load_account_token()
self._api_token = self._load_account_token()
else:
self.api_token = api_token
self._api_token = api_token

self.priority = 2

@property
def api_token(self):
if self._api_token is None:
raise APITokenNotFound(f"API token not set, neither found at dir: '{self.token_dir}'. "
"Please set up by providing api_token/token_dir when initializing User.")
return self._api_token

def save_apitoken(self, apitoken=None):
"""
Save api-token associate your Quafu account.
Expand All @@ -46,7 +53,7 @@ def save_apitoken(self, apitoken=None):
"in the future, please set api token by providing 'api_token' "
"or 'token_dir' when initialize User()."
)
self.api_token = apitoken
self._api_token = apitoken

file_dir = self.token_dir
if not os.path.exists(file_dir):
Expand All @@ -61,12 +68,12 @@ def _load_account_token(self):
TODO: expand to load more user information
"""
try:
f = open(self.token_dir + "api", "r")
token = f.readline().strip("\n")
except FileNotFoundError:
raise UserError(f"API token file not found at: '{self.token_dir}'. "
"Please set up by providing api_token/token_dir when initializing User.")
file_dir = self.token_dir + "api"
if not os.path.exists(file_dir):
return None
else:
f = open(file_dir, "r")
token = f.readline().strip()
return token

def _get_backends_info(self):
Expand Down

0 comments on commit 70004b8

Please sign in to comment.