22from  os .path  import  dirname , realpath , join  as  opj 
33from  spurplus  import  connect_with_retries 
44from  .upload_scripts  import  upload_scripts 
5- from  ._helpers  import  attempt_load_config 
5+ from  ._helpers  import  attempt_load_config ,  parse_config 
66from  .cluster_scripts .config  import  job_config 
77
88
9- def  remote_submit (config_path = None , sync_changes = False , view_output = False ):
9+ def  remote_submit (config_path = None , sync_changes = False , await_output = False ):
1010    """ 
1111    main function that handles submitting jobs on the cluster from your local 
1212    machine 
@@ -16,7 +16,7 @@ def remote_submit(config_path=None, sync_changes=False, view_output=False):
1616    configs/template_config.txt, you can simply leave this empty 
1717    :param sync_changes: (bool, default: False) if True, upload any local 
1818    changes to cluster scripts before submitting jobs 
19-     :param view_output : (bool, default: False) if True, keep the connection with 
19+     :param await_output : (bool, default: False) if True, keep the connection with 
2020    the remote open until your submit script is finished creating jobs. 
2121    Otherwise, terminate the connection after callin the submit script and allow 
2222    job submission to happen in the background. 
@@ -25,18 +25,46 @@ def remote_submit(config_path=None, sync_changes=False, view_output=False):
2525    the ssh connection may fail before job submission is finished 
2626    :return: None (other than some hopefully some results, eventually!) 
2727    """ 
28-     config  =  attempt_load_config ()
28+     if  config_path  is  None :
29+         config  =  attempt_load_config ()
30+     else :
31+         config  =  parse_config (config_path )
32+ 
2933    hostname  =  config ['hostname' ]
3034    username  =  config ['username' ]
3135    password  =  config ['password' ]
36+     confirm_overwrite  =  config ['confirm_overwrite_on_upload' ]
3237
3338    modules  =  job_config ['modules' ]
34-     submit_cmd  =  job_config ['cmd_wrapper' ]
39+     env_type  =  job_config ['env_type' ]
40+     env_name  =  job_config ['env_name' ]
41+     submit_cmd_wrapper  =  job_config ['cmd_wrapper' ]
42+     # TODO: ability to handle custom-named submission script 
43+     submit_script_path  =  opj (job_config ['workingdir' ], 'submit.py' )
3544
45+     # pre-submission commands to be concatenated and run together in remote shell 
46+     remote_cmds  =  ['sh' , '-c' ]
47+     # command for loading module(s) 
48+     module_load_cmd  =  f'module load { modules }  
49+     # command activating virtual environment 
50+     if  env_type  ==  'conda' :
51+         activate_cmd  =  'source activate' 
52+     else :
53+         # TODO: add commands for venv & virtualenv activation 
54+         raise  ValueError ("Only conda environments are currently supported" )
55+     env_activate_cmd  =  f'{ activate_cmd } { env_name }  
56+     # command for calling submit script 
57+     submit_cmd  =  f'{ submit_cmd_wrapper } { submit_script_path }  
58+ 
59+     full_submission_cmd  =  ' && ' .join ([
60+         module_load_cmd ,
61+         env_activate_cmd ,
62+         submit_cmd 
63+     ])
64+ 
65+     remote_cmds .append (full_submission_cmd )
3666
37-     confirm_overwrite  =  config ['confirm_overwrite_on_upload' ]
3867
39-     script_dir  =  opj (dirname (realpath (__file__ )), 'cluster_scripts' )
4068
4169
4270    with  connect_with_retries (
@@ -45,10 +73,16 @@ def remote_submit(config_path=None, sync_changes=False, view_output=False):
4573            password = password 
4674    ) as  cluster :
4775        if  sync_changes :
76+             script_dir  =  opj (dirname (realpath (__file__ )), 'cluster_scripts' )
4877            upload_scripts (
4978                cluster ,
5079                script_dir ,
5180                job_config ,
5281                confirm_overwrite = confirm_overwrite 
5382            )
5483
84+         if  await_output :
85+             output  =  cluster .check_output (remote_cmds )
86+             print (output )
87+         else :
88+             cluster .run (remote_cmds )
0 commit comments