U
    Nvf                  	   @   s   d Z ddlZddlZddlZddlmZ ddlmZ G dd dZG dd deZ	zddl
ZdddZW n ek
r   dddZY nX ejdkrdZddlmZ dd ZnddlmZ dS )z,
Backports of fixes for joblib dependencies
    N)basename)utilc                   @   sJ   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )VersionBackport from deprecated distutils

    We maintain this backport to avoid introducing a new dependency on
    `packaging`.

    We might rexplore this choice in the future if all major Python projects
    introduce a dependency on packaging anyway.
    Nc                 C   s   |r|  | d S Nparseselfvstring r   4/tmp/pip-unpacked-wheel-dylwa62s/joblib/backports.py__init__   s    zVersion.__init__c                 C   s   d| j jt| f S )Nz	%s ('%s'))	__class____name__strr
   r   r   r   __repr__   s    zVersion.__repr__c                 C   s   |  |}|tkr|S |dkS Nr   _cmpNotImplementedr
   othercr   r   r   __eq__   s    
zVersion.__eq__c                 C   s   |  |}|tkr|S |dk S r   r   r   r   r   r   __lt__#   s    
zVersion.__lt__c                 C   s   |  |}|tkr|S |dkS r   r   r   r   r   r   __le__)   s    
zVersion.__le__c                 C   s   |  |}|tkr|S |dkS r   r   r   r   r   r   __gt__/   s    
zVersion.__gt__c                 C   s   |  |}|tkr|S |dkS r   r   r   r   r   r   __ge__5   s    
zVersion.__ge__)N)r   
__module____qualname____doc__r   r   r   r   r   r   r   r   r   r   r   r      s   	
r   c                   @   sH   e Zd ZdZedejZdddZdd Z	dd	 Z
d
d Zdd ZdS )LooseVersionr   z(\d+ | [a-z]+ | \.)Nc                 C   s   |r|  | d S r   r   r	   r   r   r   r   H   s    zLooseVersion.__init__c              	   C   s^   || _ dd | j|D }t|D ].\}}zt|||< W q$ tk
rP   Y q$X q$|| _d S )Nc                 S   s   g | ]}|r|d kr|qS ).r   ).0xr   r   r   
<listcomp>Q   s     z&LooseVersion.parse.<locals>.<listcomp>)r   component_resplit	enumerateint
ValueErrorversion)r
   r   
componentsiobjr   r   r   r   L   s    zLooseVersion.parsec                 C   s   | j S r   )r   r   r   r   r   __str__[   s    zLooseVersion.__str__c                 C   s   dt |  S )NzLooseVersion ('%s'))r   r   r   r   r   r   ^   s    zLooseVersion.__repr__c                 C   sV   t |trt|}nt |ts"tS | j|jkr2dS | j|jk rBdS | j|jkrRdS d S )Nr      )
isinstancer   r#   r   r-   )r
   r   r   r   r   r   a   s    


zLooseVersion._cmp)N)r   r    r!   r"   recompileVERBOSEr(   r   r   r1   r   r   r   r   r   r   r#   <   s   	
r#   uint8r+CFc           	      C   sb   t d|t| t  tj| |||||d}ttj	dk rF||_
|r^ddlm} || |S )ab  Custom memmap constructor compatible with numpy.memmap.

        This function:
        - is a backport the numpy memmap offset fix (See
          https://github.com/numpy/numpy/pull/8443 for more details.
          The numpy fix is available starting numpy 1.13)
        - adds ``unlink_on_gc_collect``, which specifies  explicitly whether
          the process re-constructing the memmap owns a reference to the
          underlying file. If set to True, it adds a finalizer to the
          newly-created memmap that sends a maybe_unlink request for the
          memmaped file to resource_tracker.
        z?[MEMMAP READ] creating a memmap (shape {}, filename {}, pid {}))dtypemodeoffsetshapeorderz1.13r3   )add_maybe_unlink_finalizer)r   debugformatr   osgetpidnpZmemmapr#   __version__r=   Z_memmapping_reducerr@   )	filenamer;   r<   r=   r>   r?   unlink_on_gc_collectmmr@   r   r   r   make_memmapr   s"       rJ   c                 C   s   t dd S )NzL'joblib.backports.make_memmap' should not be used if numpy is not installed.)NotImplementedError)rG   r;   r<   r=   r>   r?   rH   r   r   r   rJ      s    nt)      )replacec              
   C   s   d}d}d}||k rzzt | | W q|W q tk
rv } z2t|ddtkrdt| ||7 }|d9 }n W 5 d}~X Y qX q dS )zRenames ``src`` into ``dst`` overwriting ``dst`` if it exists.

        On Windows os.replace can yield permission errors if executed by two
        different processes.
        r3   r   gMbP?winerrorN   )rO   	Exceptiongetattraccess_denied_errorstimesleep)srcdstZmax_sleep_timeZtotal_sleep_timeZ
sleep_timeexcr   r   r   concurrency_safe_rename   s    


rZ   )r8   r9   r   Nr:   F)r8   r9   r   Nr:   F)r"   rC   r5   rU   os.pathr   multiprocessingr   r   r#   ZnumpyrE   rJ   ImportErrornamerT   rO   rZ   r   r   r   r   <module>   s2   03            

