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

Commit e372495

Browse files
committed
add file existence checking for python script; simplify pipenv option
1 parent 03d4a7a commit e372495

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

paperspace/jobs.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,19 @@ def run(params={}, no_logging=False):
419419
if 'command' not in params:
420420
params['command'] = 'python' + python_ver + ' ' + src_file
421421

422+
if not os.path.exists(src_path):
423+
message = format('error: file not found: %s' % src_path)
424+
print(message)
425+
if 'no_logging' in params:
426+
return { 'error': True, 'message': message }
427+
sys.exit(1)
428+
elif os.path.isdir(src_path):
429+
message = format('error: specified file is a directory: %s' % src_path)
430+
print(message)
431+
if 'no_logging' in params:
432+
return { 'error': True, 'message': message }
433+
sys.exit(1)
434+
422435
params['extraFiles'] = []
423436
if 'workspace' not in params:
424437
params['workspace'] = src_path
@@ -439,19 +452,15 @@ def run(params={}, no_logging=False):
439452

440453
pipenv = params.pop('pipenv', None)
441454
if pipenv:
442-
if isinstance(pipenv, str):
443-
pipenv = pipenv.split(',')
444-
elif isinstance(pipenv, bool):
445-
pipenv = ['Pipfile', 'Pipfile.lock']
446-
for pipfile in pipenv:
455+
for pipfile in ['Pipfile', 'Pipfile.lock']:
447456
if os.path.exists(pipfile):
448457
params['extraFiles'].append(pipfile)
449458
uses_python_ver = ''
450459
if python_ver.startswith('3'):
451460
uses_python_ver == '--three '
452461
elif python_ver.startswith('2'):
453462
uses_python_ver == '--two '
454-
params['command'] = 'pipenv ' + uses_python_ver + 'install\npipenv graph\n' + params['command']
463+
params['command'] = 'pipenv ' + uses_python_ver + 'install\n' + params['command']
455464

456465
conda = params.pop('conda', None)
457466
if conda:

paperspace/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ def main():
7979
print('error: missing argument for %s' % opt)
8080
print('usage: %s' % run_usage(prog))
8181
sys.exit(1)
82-
elif param in ['init', 'pipenv', 'req']:
82+
elif param in ['init', 'req']:
8383
params[param] = True
8484
if args and not args[0].startswith('--') and not args[0].endswith('.py'):
8585
params[param] = args.pop(0)
8686
elif param in ['no_logging', 'nologging', 'noLogging', 'json']:
8787
params['no_logging'] = True
88+
elif param == 'pipenv':
89+
params[param] = True
8890
else:
8991
print('error: invalid option: %s' % opt)
9092
print('usage: %s' % run_usage(prog))
@@ -122,7 +124,7 @@ def apikey_usage(prog):
122124

123125

124126
def run_usage(prog):
125-
return format('%s run <python_script.py> [--python 2 | 3] [--init [<init.sh>]] [--conda <env>] [--pipenv [Pipfile,Pipfile.lock]] [--req [<requirements.txt>] |' % prog)
127+
return format('%s run <python_script.py> [--python 2 | 3] [--init [<init.sh>]] [--conda <env>] [--pipenv] [--req [<requirements.txt>]' % prog)
126128

127129

128130
def usage(prog):

0 commit comments

Comments
 (0)