3
d                 @   s\   d Z ddlmZ ddlZddlZddlmZ ddlm	Z	 ddl
mZmZ G dd	 d	eZdS )
z<Defines functionality for pipelined execution of interfaces.    )deepcopyN   )config)DynamicTraitedSpec)loadpklsavepklc               @   s   e Zd ZdZdddZedd Zejdd Zedd	 Zed
d Z	edd Z
edd Zdd Zdd Zdd Zdd Zdd ZdddZedd ZdS ) 
EngineBasez{
    Defines common attributes and functions for workflows and nodes.

    Implements the more general view of a task.
    Nc             C   s0   d| _ d| _|| _| j| _|| _ttj| _dS )a  
        Initialize base parameters of a workflow or node.

        Parameters
        ----------
        name : string (mandatory)
            Name of this node. Name must be alphanumeric and not contain any
            special characters (e.g., '.', '@').
        base_dir : string
            base output directory (will be hashed before creations)
            default=None, which results in the use of mkdtemp

        N)_name
_hierarchyname_idbase_dirr   r   	_sections)selfr   r    r   =/tmp/pip-build-7vycvbft/nipype/nipype/pipeline/engine/base.py__init__   s    zEngineBase.__init__c             C   s   | j S )z-Set the unique name of this workflow element.)r	   )r   r   r   r   r   -   s    zEngineBase.namec             C   s*   | st jd| r td| || _d S )Nz^[\w-]+$z'[Workflow|Node] name "%s" is not valid.)rematch
ValueErrorr	   )r   r   r   r   r   r   2   s    c             C   s   | j rd| j | jf S | jS )z'Build the full name down the hierarchy.z%s.%s)r
   r   )r   r   r   r   fullname8   s    zEngineBase.fullnamec             C   s   t d S )N)NotImplementedError)r   r   r   r   inputs?   s    zEngineBase.inputsc             C   s   t d S )N)r   )r   r   r   r   outputsC   s    zEngineBase.outputsc             C   s    | j }| jrd| j| j f }|S )z&Get the name of the expanded iterable.z%s.%s)r   r
   )r   iternamer   r   r   r   G   s    zEngineBase.iternamec             C   s8   || j krtd| t| }||_ t|dr4||_|S )z
        Clone an EngineBase object.

        Parameters
        ----------

        name : string (mandatory)
            A clone of node or workflow must have a new name

        z,Cloning requires a new name, "%s" is in use.r   )r   r   r   hasattrr   )r   r   cloner   r   r   r   O   s    

zEngineBase.clonec             C   s   t | j|S )N)r   r   )r   	parameterr   r   r   _check_outputsb   s    zEngineBase._check_outputsc             C   s   t | jtrdS t| j|S )NT)
isinstancer   r   r   )r   r   r   r   r   _check_inputse   s    zEngineBase._check_inputsc             C   s   | j S )zConvert to string.)r   )r   r   r   r   __str__j   s    zEngineBase.__str__c             C   s   | j S )zGet Python representation.)r   )r   r   r   r   __repr__n   s    zEngineBase.__repr__c             C   s   |dkrd}t ||  dS )z&Store this workflow element to a file.Nz	temp.pklz)r   )r   filenamer   r   r   saver   s    zEngineBase.savec             C   s   t | S )z'Load this workflow element from a file.)r   )r#   r   r   r   loadx   s    zEngineBase.load)NN)N)__name__
__module____qualname____doc__r   propertyr   setterr   r   r   r   r   r   r    r!   r"   r$   staticmethodr%   r   r   r   r   r      s   

r   )r)   copyr   r   numpynp r   Zinterfaces.baser   Zutils.filemanipr   r   objectr   r   r   r   r   <module>   s   