3
d
                 @   sH   d Z ddlZddlmZmZmZmZmZ ddlm	Z	 G dd deZ
dS )	z Local serial workflow execution
    N   )
PluginBaseloggerreport_crashreport_nodes_not_runstr2bool   )topological_sortc               @   s   e Zd ZdZdddZdS )LinearPluginzExecute workflow in seriesFc          !   C   s  ddl }y
|j}W n tk
r,   |j}Y nX t||jsBtdtjd t	j
 }g }g }t|d d }	g }
t|\}}x|D ]}d}zy,||krw| jr| j|d |j|d	 W nr tk
r* } zTd
}t|}dd |||D }|j|||d |j| |
j| |	rP W Y dd}~X nX W d| jrD| j|| X qW t	j| t| |
r|
d d }}t|trt|}t|
dkrtt|
 d| }}||dS )zExecutes a pre-defined pipeline in a serial order.

        Parameters
        ----------

        graph : networkx digraph
            defines order of execution
        r   Nz'Input must be a networkx digraph objectzRunning serially.Z	executionstop_on_first_crashendstart)
updatehash	exceptionc             S   s   g | ]}|qS  r   ).0sr   r   @/tmp/pip-build-7vycvbft/nipype/nipype/pipeline/plugins/linear.py
<listcomp>6   s    z$LinearPlugin.run.<locals>.<listcomp>)nodeZ
dependents	crashfiler   z raised. Re-raising first.)Znetworkxdfs_preorderAttributeErrorZdfs_preorder_nodes
isinstanceZDiGraph
ValueErrorr   infoosgetcwdr   r	   Z_status_callbackrun	Exceptionr   appendextendchdirr   strRuntimeErrorlen)selfgraphconfigr   Znxr   Zold_wdZnotrunZdonotrunr   errorsZnodes_r   Z	endstatusexcr   Zsubnodeserrorcauser   r   r   r      sX    	





zLinearPlugin.runN)F)__name__
__module____qualname____doc__r   r   r   r   r   r
      s   r
   )r1   r   baser   r   r   r   r   Zengine.utilsr	   r
   r   r   r   r   <module>   s   