Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 8d10191

Browse files
committed
move apikey function
1 parent fb04682 commit 8d10191

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

paperspace/login.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import requests
77
from six.moves import input
88

9-
from . import config
10-
from .method import *
9+
from .config import *
10+
from .method import requests_exception_to_error_obj, response_error_check, status_code_to_error_obj
1111

1212

1313
def is_error_or_missing_keys_print(res, *required_keys):

paperspace/method.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
import requests
1010
import subprocess
1111

12-
from . import config
13-
from . import login
12+
from .config import *
1413

1514
def zip_to_tmp(files, ignore_files=[]):
1615
file = files[0]
@@ -48,7 +47,7 @@ def method(category, method, params):
4847
if 'apiKey' in params:
4948
config.PAPERSPACE_API_KEY = params.pop('apiKey')
5049
elif not config.PAPERSPACE_API_KEY:
51-
config.PAPERSPACE_API_KEY = login.apikey()
50+
config.PAPERSPACE_API_KEY = get_apikey()
5251
params.pop('tail', None)
5352
no_logging = params.pop('no_logging', None)
5453
workspace_files = params.pop('extraFiles', [])
@@ -168,3 +167,13 @@ def status_code_to_error_obj(status_code):
168167
if status_code in requests.status_codes._codes:
169168
message = requests.status_codes._codes[status_code][0]
170169
return { 'error': True, 'message': message, 'status': status_code }
170+
171+
172+
def get_apikey():
173+
paperspace_dir = os.path.expanduser('~/.paperspace')
174+
config_path = os.path.join(paperspace_dir, 'config.json')
175+
if os.path.exists(config_path):
176+
config_data = json.load(open(config_path))
177+
if config_data and 'apiKey' in config_data:
178+
return config_data['apiKey']
179+
return ''

0 commit comments

Comments
 (0)