@@ -23,6 +23,7 @@ def zip_to_tmp(files, ignore_files=[]):
2323 files_added = set ()
2424 with outZipFile :
2525 for file in files :
26+ file = os .path .abspath (os .path .expanduser (file ))
2627 if os .path .isdir (file ):
2728 for dirpath , dirnames , filenames in os .walk (file ):
2829 dirnames [:] = [d for d in dirnames if d not in ignore_files ]
@@ -77,7 +78,7 @@ def method(category, method, params):
7778 if method == 'createJob' and 'workspace' in params :
7879
7980 workspace = params .get ('workspace' , None )
80- ignore_files .extend (['.git' , '.gitignore' ])
81+ ignore_files .extend (['.git' , '.gitignore' , '__pycache__' ])
8182 if workspace :
8283 if workspace != 'none' :
8384 workspace_files .insert (0 , workspace )
@@ -89,15 +90,15 @@ def method(category, method, params):
8990 file_path = os .path .expanduser (file )
9091 if not os .path .exists (file_path ):
9192 message = format ('error: file or directory not found: %s' % file_path )
92- print (message )
9393 if no_logging :
9494 return { 'error' : True , 'message' : message }
95+ print (message )
9596 sys .exit (1 )
9697 elif file_path == '/' :
9798 message = 'error: cannot zip root directory'
98- print (message )
9999 if no_logging :
100100 return { 'error' : True , 'message' : message }
101+ print (message )
101102 sys .exit (1 )
102103
103104 if len (workspace_files ) == 1 and (file_path .endswith ('.zip' ) or file_path .endswith ('.gz' )):
@@ -157,7 +158,7 @@ def logs(params, tail=False, no_logging=False):
157158 elif not config .PAPERSPACE_API_KEY :
158159 config .PAPERSPACE_API_KEY = apikey ()
159160 tail = params .pop ('tail' , False ) or tail
160- no_logging = params .pop ('no_logging' , False ) or no_logging
161+ no_logging = no_logging or params .pop ('no_logging' , False )
161162
162163 last_line = 0
163164 PSEOF = False
@@ -267,7 +268,7 @@ def create(params, no_logging=False, extra_files=[]):
267268
268269 if job ['state' ] != 'Error' and job ['state' ] != 'Cancelled' :
269270 print ('Awaiting logs...' )
270- if logs ({'jobId' : jobId }, tail = True ):
271+ if logs ({'jobId' : jobId }, tail = True , no_logging = no_logging ):
271272 job = method ('jobs' , 'getJob' , {'jobId' : jobId })
272273 else :
273274 job = waitfor ({'jobId' : jobId , 'state' : 'Stopped' })
@@ -416,8 +417,17 @@ def run(params={}, no_logging=False):
416417 python_ver = params .pop ('python' , str (sys .version_info [0 ])) # defaults locally running version
417418 # TODO validate python version; handle no version, specific version
418419
420+ run_as_module_opt = ''
421+ if params .pop ('module' , None ):
422+ run_as_module_opt = '-m '
423+
424+ script_args = params .pop ('script_args' , None )
425+ args = ''
426+ if script_args :
427+ args = ' ' + ' ' .join (script_args )
428+
419429 if 'command' not in params :
420- params ['command' ] = 'python' + python_ver + ' ' + src_file
430+ params ['command' ] = 'python' + python_ver + ' ' + run_as_module_opt + src_file + args
421431
422432 if not os .path .exists (src_path ):
423433 message = format ('error: file not found: %s' % src_path )
@@ -472,7 +482,11 @@ def run(params={}, no_logging=False):
472482 init = 'init.sh'
473483 if os .path .exists (init ):
474484 params ['extraFiles' ].append (init )
475- params ['command' ] = '. ' + os .path .basename (init ) + '\n ' + params ['command' ]
485+ params ['command' ] = 'source ' + os .path .basename (init ) + '\n ' + params ['command' ]
486+
487+ if params .pop ('dryrun' , None ):
488+ print (params ['command' ])
489+ sys .exit (1 )
476490
477491 res = create (params , no_logging )
478492 if run_this :
0 commit comments