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

Commit 8064612

Browse files
committed
support no_logging option for create, run_as, logs, artifactsGet
1 parent 2efd2fe commit 8064612

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

paperspace/jobs.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ def destroy(params):
107107
return method('jobs', 'destroy', params)
108108

109109

110-
def logs(params, tail=False, json=False):
110+
def logs(params, tail=False, no_logging=False):
111111
last_line = 0
112112
PSEOF = False
113-
json_res = []
113+
result = []
114114
MAX_BACKOFF = 30
115115
backoff = 0
116116

@@ -125,8 +125,8 @@ def logs(params, tail=False, json=False):
125125
res = r.json()
126126
except ValueError:
127127
res = []
128-
if json:
129-
json_res += res
128+
if no_logging:
129+
result += res
130130
else:
131131
for l in res:
132132
m = l['message']
@@ -154,9 +154,8 @@ def logs(params, tail=False, json=False):
154154
else:
155155
break
156156

157-
if json:
158-
print_json_pretty(json_res)
159-
return json_res
157+
if no_logging:
158+
return result
160159
return True
161160

162161

@@ -176,8 +175,10 @@ def waitfor(params):
176175
time.sleep(5)
177176

178177

179-
def create(params):
178+
def create(params, no_logging=False):
180179
job = method('jobs', 'createJob', params)
180+
if no_logging:
181+
return job
181182
if 'id' not in job:
182183
print_json_pretty(job)
183184
return job
@@ -207,14 +208,17 @@ def create(params):
207208
return job
208209

209210

210-
def artifactsGet(params):
211+
def artifactsGet(params, no_logging=False):
212+
result = []
211213
if 'dest' in params:
212214
dest = os.path.abspath(os.path.expanduser(params['dest']))
213215
if not os.path.exists(dest):
214216
os.makedirs(dest)
215217
else:
216218
if not os.path.isdir(dest):
217219
print('Destination path not is not directory: %s' % dest)
220+
if no_logging:
221+
return result
218222
return False
219223
del params['dest']
220224
else:
@@ -245,7 +249,8 @@ def artifactsGet(params):
245249
os.makedirs(dest_dir)
246250

247251
key = folder + '/' + file
248-
print('Downloading %s' % file)
252+
if not no_logging:
253+
print('Downloading %s' % file)
249254

250255
try:
251256
s3.Bucket(bucket).download_file(key, dest_file)
@@ -254,10 +259,16 @@ def artifactsGet(params):
254259
print("The s3 object does not exist: %s" % key)
255260
else:
256261
raise
262+
if no_logging:
263+
result.append({ 'file': file, 'destination': dest_file })
257264

265+
if no_logging:
266+
return result
258267
print('Download complete')
259268
return True
260269

270+
if no_logging:
271+
return result
261272
return False
262273

263274

@@ -269,7 +280,7 @@ def artifactsGet(params):
269280
# stream file uploads/downloads
270281

271282

272-
def runas_job(params={}):
283+
def runas_job(params={}, no_logging=False):
273284
if 'PAPERSPACE_JOB_RUNNER' in os.environ:
274285
return
275286

@@ -300,7 +311,7 @@ def runas_job(params={}):
300311
params['command'] = 'python3 ' + src_file
301312
params['workspace'] = src_path
302313

303-
create(params)
314+
create(params, no_logging)
304315
sys.exit(0)
305316

306317

0 commit comments

Comments
 (0)