4
4
import subprocess
5
5
from datetime import datetime
6
6
from nextflow .io import get_file_text , get_process_ids_to_paths , get_file_creation_time
7
- from nextflow .models import Execution , ProcessExecution
7
+ from nextflow .models import Execution , ProcessExecution , ExecutionSubmission
8
8
from nextflow .log import (
9
9
get_started_from_log ,
10
10
get_finished_from_log ,
17
17
18
18
def run (* args , ** kwargs ):
19
19
"""Runs a pipeline and returns the execution.
20
-
20
+
21
21
:param str pipeline_path: the absolute path to the pipeline .nf file.
22
22
:param str run_path: the location to run the pipeline in (if not current directory).
23
23
:param str output_path: the location to store the output in (if not run path).
@@ -41,7 +41,7 @@ def run(*args, **kwargs):
41
41
def run_and_poll (* args , ** kwargs ):
42
42
"""Runs a pipeline and polls it for updates. Yields the execution after each
43
43
update.
44
-
44
+
45
45
:param str pipeline_path: the absolute path to the pipeline .nf file.
46
46
:param str run_path: the location to run the pipeline in (if not current directory).
47
47
:param str output_path: the location to store the output in (if not run path).
@@ -70,6 +70,59 @@ def _run(
70
70
log_path = None , runner = None , io = None ,
71
71
version = None , configs = None , params = None , profiles = None , timezone = None ,
72
72
report = None , timeline = None , dag = None , trace = None , sleep = 1
73
+ ):
74
+ process , submission = submit_execution (
75
+ configs ,
76
+ dag ,
77
+ io ,
78
+ log_path ,
79
+ output_path ,
80
+ params ,
81
+ pipeline_path ,
82
+ profiles ,
83
+ report ,
84
+ resume ,
85
+ run_path ,
86
+ runner ,
87
+ timeline ,
88
+ timezone ,
89
+ trace ,
90
+ version
91
+ )
92
+ start = datetime .now ()
93
+
94
+ execution , log_start = None , 0
95
+ if resume : wait_for_log_creation (submission .log_path , start , io )
96
+ while True :
97
+ time .sleep (sleep )
98
+ execution , diff = get_execution (
99
+ submission .output_path , submission .log_path , submission .nextflow_command , execution , log_start , timezone , io
100
+ )
101
+ log_start += diff
102
+ if execution and poll : yield execution
103
+ process_finished = not process or process .poll () is not None
104
+ if execution and execution .return_code and process_finished :
105
+ if not poll : yield execution
106
+ break
107
+
108
+
109
+ def submit_execution (
110
+ configs ,
111
+ dag ,
112
+ io ,
113
+ log_path ,
114
+ output_path ,
115
+ params ,
116
+ pipeline_path ,
117
+ profiles ,
118
+ report ,
119
+ resume ,
120
+ run_path ,
121
+ runner ,
122
+ timeline ,
123
+ timezone ,
124
+ trace ,
125
+ version
73
126
):
74
127
if not run_path and not io : run_path = os .path .abspath ("." )
75
128
if not run_path and io : run_path = io .abspath ("." )
@@ -79,32 +132,22 @@ def _run(
79
132
run_path , output_path , log_path , pipeline_path , resume , version , configs ,
80
133
params , profiles , timezone , report , timeline , dag , trace , io
81
134
)
82
- start = datetime .now ()
83
135
if runner :
84
136
process = None
85
137
runner (nextflow_command )
86
138
else :
87
139
process = subprocess .Popen (
88
- nextflow_command , universal_newlines = True , shell = True
89
- )
90
- execution , log_start = None , 0
91
- if resume : wait_for_log_creation (log_path , start , io )
92
- while True :
93
- time .sleep (sleep )
94
- execution , diff = get_execution (
95
- output_path , log_path , nextflow_command , execution , log_start , timezone , io
140
+ nextflow_command , universal_newlines = True , shell = True
96
141
)
97
- log_start += diff
98
- if execution and poll : yield execution
99
- process_finished = not process or process .poll () is not None
100
- if execution and execution .return_code and process_finished :
101
- if not poll : yield execution
102
- break
142
+ submission = ExecutionSubmission (
143
+ pipeline_path , run_path , output_path , log_path , nextflow_command , timezone
144
+ )
145
+ return process , submission
103
146
104
147
105
148
def make_nextflow_command (run_path , output_path , log_path , pipeline_path , resume ,version , configs , params , profiles , timezone , report , timeline , dag , trace , io ):
106
149
"""Generates the `nextflow run` commmand.
107
-
150
+
108
151
:param str run_path: the location to run the pipeline in.
109
152
:param str output_path: the location to store the output in.
110
153
:param str log_path: the location to store the log in.
@@ -147,7 +190,7 @@ def make_nextflow_command(run_path, output_path, log_path, pipeline_path, resume
147
190
def make_nextflow_command_env_string (version , timezone , output_path , run_path ):
148
191
"""Creates the environment variable setting portion of the nextflow run
149
192
command string.
150
-
193
+
151
194
:param str version: the nextflow version to use.
152
195
:param str timezone: the timezone to use.
153
196
:param str output_path: the location to store the output in.
@@ -162,7 +205,7 @@ def make_nextflow_command_env_string(version, timezone, output_path, run_path):
162
205
163
206
def make_nextflow_command_log_string (log_path , run_path ):
164
207
"""Creates the log setting portion of the nextflow run command string.
165
-
208
+
166
209
:param str log_path: the location to store the log file in.
167
210
:rtype: ``str``"""
168
211
@@ -173,7 +216,7 @@ def make_nextflow_command_log_string(log_path, run_path):
173
216
def make_nextflow_command_config_string (configs ):
174
217
"""Creates the config setting portion of the nextflow run command string.
175
218
Absolute paths are recommended.
176
-
219
+
177
220
:param str version: the nextflow version to use.
178
221
:rtype: ``str``"""
179
222
@@ -183,7 +226,7 @@ def make_nextflow_command_config_string(configs):
183
226
184
227
def make_nextflow_command_resume_string (resume ):
185
228
"""Creates the resume setting portion of the nextflow run command string.
186
-
229
+
187
230
:param resume: whether to resume an existing execution.
188
231
:rtype: ``str``"""
189
232
@@ -203,7 +246,7 @@ def make_nextflow_command_params_string(params):
203
246
for key , value in params .items ():
204
247
if not value :
205
248
param_list .append (f"--{ key } =" )
206
- elif value [0 ] in "'\" " :
249
+ elif value [0 ] in "'\" " :
207
250
param_list .append (f"--{ key } ={ value } " )
208
251
else :
209
252
param_list .append (f"--{ key } ='{ value } '" )
@@ -212,7 +255,7 @@ def make_nextflow_command_params_string(params):
212
255
213
256
def make_nextflow_command_profiles_string (profiles ):
214
257
"""Creates the profile setting portion of the nextflow run command string.
215
-
258
+
216
259
:param list profiles: any profiles to be applied.
217
260
:rtype: ``str``"""
218
261
@@ -222,7 +265,7 @@ def make_nextflow_command_profiles_string(profiles):
222
265
223
266
def make_reports_string (output_path , report , timeline , dag , trace ):
224
267
"""Creates the report setting portion of the nextflow run command string.
225
-
268
+
226
269
:param str output_path: the location to store the output in.
227
270
:param str report: the filename to use for the execution report.
228
271
:param str timeline: the filename to use for the timeline report.
@@ -245,11 +288,11 @@ def make_reports_string(output_path, report, timeline, dag, trace):
245
288
246
289
def wait_for_log_creation (output_path , start , io ):
247
290
"""Waits for a log file for this execution to be created.
248
-
291
+
249
292
:param str output_path: the location to store the output in.
250
293
:param datetime start: the start time.
251
294
:param io: an optional custom io object to handle file operations."""
252
-
295
+
253
296
while True :
254
297
created = get_file_creation_time (os .path .join (output_path , ".nextflow.log" ), io = io )
255
298
if created and created > start : break
@@ -259,7 +302,7 @@ def wait_for_log_creation(output_path, start, io):
259
302
def get_execution (execution_path , log_path , nextflow_command , execution = None , log_start = 0 , timezone = None , io = None ):
260
303
"""Creates an execution object from a location. If you are polling, you can
261
304
pass in the previous execution to update it with new information.
262
-
305
+
263
306
:param str execution_path: the location of the execution.
264
307
:param str log_path: the location of the log.
265
308
:param str nextflow_command: the command used to run the pipeline.
@@ -322,8 +365,8 @@ def get_initial_process_executions(log, execution, io):
322
365
currently in the list, or uncompleted ones which can now be completed. Some
323
366
attributes are not yet filled in.
324
367
325
- The identifiers of the proccess executions seen are returned.
326
-
368
+ The identifiers of the process executions seen are returned.
369
+
327
370
:param str log: a section of the log file.
328
371
:param nextflow.models.Execution execution: the containing execution.
329
372
:param io: an optional custom io object to handle file operations.
@@ -350,7 +393,7 @@ def get_initial_process_executions(log, execution, io):
350
393
def create_process_execution_from_line (line , cached = False , io = None ):
351
394
"""Creates a process execution from a line of the log file in which its
352
395
submission (or previous caching) is reported.
353
-
396
+
354
397
:param str line: a line from the log file.
355
398
:param bool cached: whether the process is cached.
356
399
:param io: an optional custom io object to handle file operations.
@@ -375,7 +418,7 @@ def update_process_execution_from_line(process_executions, line):
375
418
"""Updates a process execution with information from a line of the log file
376
419
in which its completion is reported. The identifier of the process execution
377
420
is returned.
378
-
421
+
379
422
:param dict process_executions: a dictionary of process executions.
380
423
:param str line: a line from the log file.
381
424
:rtype: ``str``"""
@@ -393,7 +436,7 @@ def update_process_execution_from_line(process_executions, line):
393
436
def update_process_execution_from_path (process_execution , execution_path , timezone = None , io = None ):
394
437
"""Some attributes of a process execution need to be obtained from files on
395
438
disk. This function updates the process execution with these values.
396
-
439
+
397
440
:param nextflow.models.ProcessExecution process_execution: the process execution.
398
441
:param str execution_path: the location of the containing execution.
399
442
:param str timezone: the timezone to use for the log.
0 commit comments