B
    µ‰\Œ  ã               @   s|   d dl Z d dlZd dlZd dlmZ dZye W n$ ek
rT   G dd„ deƒZY nX ddd„Z	d	d
„ Z
dd„ Zdd„ ZdS )é    N)ÚLooseVersionz0.23.4c               @   s   e Zd ZdS )ÚWindowsErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú-lib/python3.7/site-packages/skimage/_build.pyr      s   r   Ú c          	      s  t tjƒdkr tjd dkr dS y4ddlm} t|ƒtk rFtdt ƒ‚ddlm	} W nl t
k
rÀ   d	d
„ | D ƒ}x2‡ fdd
„|D ƒD ]}tj |¡s†tdt ƒ‚q†W tdtd |¡f ƒ Y nPX xL‡ fdd
„| D ƒD ]6}t|ƒsäqÖ| d¡rt|ƒ | dd¡}||ƒ qÖW dS )zŠUse Cython to convert the given files to C.

    Parameters
    ----------
    pyx_files : list of str
        The input .pyx files.

    é   é   ZcleanNr   )Ú__version__z)Cython >= %s needed to build scikit-image)Ú	cythonizec             S   s    g | ]}|  d d¡  dd¡‘qS )z.pyx.inz.cz.pyx)Úreplace)Ú.0Úfr   r   r   ú
<listcomp>&   s    zcython.<locals>.<listcomp>c                s   g | ]}t j ˆ |¡‘qS r   )ÚosÚpathÚjoin)r   r   )Úworking_pathr   r   r   '   s    z@Cython >= %s is required to build scikit-image from git checkoutz4Cython >= %s not found; falling back to pre-built %sú c                s   g | ]}t j ˆ |¡‘qS r   )r   r   r   )r   r   )r   r   r   r   /   s    z.pyx.inz.pyx)ÚlenÚsysÚargvÚCythonr   r   ÚCYTHON_VERSIONÚRuntimeErrorZCython.Buildr   ÚImportErrorr   r   ÚisfileÚprintr   Ú_changedÚendswithÚprocess_tempita_pyxr   )Z	pyx_filesr   r   r   Zc_filesÚcfileÚpyxfiler   )r   r   Úcython   s,    
r%   c             C   s2   t  d¡}x|  d¡}|sP | |¡ qW | ¡ S )NZmd5i   )ÚhashlibÚnewÚreadÚupdateZ	hexdigest)r   ÚmÚdr   r   r   Ú_md5sum<   s    

r,   c          
   C   s†   | d }yt |dƒ ¡ }W n tk
r2   d}Y nX t | dƒ4}t|ƒ}t |dƒ}| | d¡¡ W dQ R X W dQ R X || d¡kS )zICompare the hash of a Cython file to the cached hash value on disk.

    z.md5ÚrbÚ0Úwbzutf-8N)Úopenr(   ÚIOErrorr,   ÚwriteÚencode)ÚfilenameZfilename_cacheZ
md5_cachedr   Zmd5_newZcfr   r   r   r    G   s    
$r    c          	   C   s¶   y2yddl m} W n tk
r.   dd l}Y nX W n tk
rN   tdƒ‚Y nX |jj| t ¡ d}| 	¡ }|  
d¡s‚td|  ƒ‚tj | ¡d }t|dƒ}| |¡ W d Q R X d S )Nr   )ÚTempitaz5Building requires Tempita: pip install --user Tempita)Úencodingz.pyx.inzUnexpected extension of %s.Úw)r   r5   r   ÚtempitaÚ	ExceptionZTemplateZfrom_filenamer   ÚgetdefaultencodingZ
substituter!   Ú
ValueErrorr   r   Úsplitextr0   r2   )Zfromfiler8   ÚtemplateZ
pyxcontentr$   r   r   r   r   r"   [   s    
r"   )r	   )r   r   r&   Zdistutils.versionr   r   r   Ú	NameErrorr9   r%   r,   r    r"   r   r   r   r   Ú<module>   s   
,