B
    td              	   @   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 ddlZG dd dZ	G dd de	Z
y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 )VersionzBackport 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   ]/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/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 )Nr   )r   r   )r   r   r   r   r   r	   __lt__0   s    
zVersion.__lt__c             C   s   |  |}|tkr|S |dkS )Nr   )r   r   )r   r   r   r   r   r	   __le__6   s    
zVersion.__le__c             C   s   |  |}|tkr|S |dkS )Nr   )r   r   )r   r   r   r   r   r	   __gt__<   s    
zVersion.__gt__c             C   s   |  |}|tkr|S |dkS )Nr   )r   r   )r   r   r   r   r   r	   __ge__B   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 )LooseVersionzBackport 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.
    z(\d+ | [a-z]+ | \.)Nc             C   s   |r|  | d S )N)r   )r   r   r   r   r	   r
   U   s    zLooseVersion.__init__c          	   C   sb   || _ dd | j|D }x:t|D ].\}}yt|||< W q& tk
rR   Y q&X q&W || _d S )Nc             S   s   g | ]}|r|d kr|qS ).r   ).0xr   r   r	   
<listcomp>^   s    z&LooseVersion.parse.<locals>.<listcomp>)r   component_resplit	enumerateint
ValueErrorversion)r   r   
componentsiobjr   r   r	   r   Y   s    
zLooseVersion.parsec             C   s   | j S )N)r   )r   r   r   r	   __str__h   s    zLooseVersion.__str__c             C   s   dt |  S )NzLooseVersion ('%s'))r   )r   r   r   r	   r   k   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   n   s    


zLooseVersion._cmp)N)r   r   r   r   recompileVERBOSEr    r
   r   r)   r   r   r   r   r   r	   r   I   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.13r+   )add_maybe_unlink_finalizer)r   debugformatr   osgetpidnpZmemmapr   __version__r5   Z_memmapping_reducerr8   )	filenamer3   r4   r5   r6   r7   unlink_on_gc_collectmmr8   r   r   r	   make_memmap   s    
rB   c             C   s   t dd S )NzL'joblib.backports.make_memmap' should not be used if numpy is not installed.)NotImplementedError)r?   r3   r4   r5   r6   r7   r@   r   r   r	   rB      s    nt)      )replacec          
   C   s   d}d}d}xp||k rzyt | | P W q tk
rv } z2t|ddtkrdt| ||7 }|d9 }n W dd}~X Y qX qW  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.
        r+   r   gMbP?winerrorN   )rG   	Exceptiongetattraccess_denied_errorstimesleep)srcdstZmax_sleep_timeZtotal_sleep_timeZ
sleep_timeexcr   r   r	   concurrency_safe_rename   s    



rR   )r0   r1   r   Nr2   F)r0   r1   r   Nr2   F)r   r;   r-   rM   os.pathr   multiprocessingr   	distutilsr   r   numpyr=   rB   ImportErrornamerL   rG   rR   r   r   r   r	   <module>   s(   03  

