U
    R^                     @   s~   d dl Z d dlmZ d dlmZ d dlmZmZmZ d dl	m
Z
 d dlmZmZmZ e dZdZd	d
 ZG dd deZdS )    N)glob1)remove)existsisdirjoin)rmtree)Baseshell_commandcopy_test_filesZdhpythonzsetup.py|setup-3.pyc                    s    fdd} j |_ |S )zdistutils doesn't have sane command-line API - this decorator creates
    .pydistutils.cfg file to workaround it

    hint: if you think this is plain stupid, please don't read
    distutils/setuptools/distribute sources
    c                    s   t |d d}t|s|t|dddR}dddd	|d
 ddddd|d dddg}tdd | || W 5 Q R X |d |d d<  | ||f||S )NZhome_dirz.pydistutils.cfgwzutf-8)encodingz[clean]
zall=1
z[build]
zbuild-lib={}
	build_dirz
[install]
zforce=1
zinstall-layout=deb
zinstall-scripts=$base/bin
zinstall-lib={}
Zinstall_dirzprefix=/usr
z[easy_install]
zallow_hosts=None
zpydistutils config file:
%s ZENVHOME)r   r   openformatlogdebug
writelines)selfcontextargsZoargskwargsfpathfplinesfunc 7/usr/share/dh-python/dhpython/build/plugin_distutils.pywrapped_func(   s(    z,create_pydistutils_cfg.<locals>.wrapped_func)__name__)r   r    r   r   r   create_pydistutils_cfg    s    r"   c                       s   e Zd ZdZdddddddhZegZd	d	d
d
dZ fddZe	e
 fddZe	e
dd Ze	e
dd Ze	e
dd Ze	e
e  fddZ  ZS )BuildSystemzDistutils build systempythonpython3zpython{version}z
python-dbgzpython3-dbgzpython{version}-dbgZpypy   
   )z	setup.cfgzrequirements.txtzPKG-INFO
*.egg-infoc                    sB   t t| |}t| jkr2| jt d |d d< nd|d d< |S )Nr   r   setup_pyzsetup.py)superr#   detect
_setup_tplZDETECTED_REQUIRED_FILES)r   r   result	__class__r   r   r+   L   s
    
zBuildSystem.detectc                    sH   t t| || t|d d}t|o.t| t|d  rDdS dS )NdirbuildZinterpreterz%{interpreter} {setup_py} clean {args}r   )r*   r#   cleanr   r   r   r   binary)r   r   r   Zdpathr.   r   r   r2   T   s    zBuildSystem.cleanc                 C   s   dS )Nz&{interpreter} {setup_py} config {args}r   r   r   r   r   r   r   	configure^   s    zBuildSystem.configurec                 C   s   dS )Nz/{interpreter.binary_dv} {setup_py} build {args}r   r4   r   r   r   r1   c   s    zBuildSystem.buildc                 C   s>   t |d dD ]*}t|d |}t|r0t|nt| qdS )Nr   r(   zB{interpreter.binary_dv} {setup_py} install --root {destdir} {args})r   r   r   r   r   )r   r   r   fnamer   r   r   r   installh   s    zBuildSystem.installc              	      sb   | j jsPt|d |d }t|d&}| ddkrFW 5 Q R  dS W 5 Q R X tt| ||S )Nr0   r)   rbs
   test_suiter   z${interpreter} {setup_py} test {args})	ZcfgZcustom_testsr   r   readfindr*   r#   test)r   r   r   r   r   r.   r   r   r;   r   s    zBuildSystem.test)r!   
__module____qualname__ZDESCRIPTIONZSUPPORTED_INTERPRETERSr,   ZREQUIRED_FILESZOPTIONAL_FILESr+   r	   r"   r2   r5   r1   r7   r
   r;   __classcell__r   r   r.   r   r#   A   s<     r#   )Zloggingglobr   osr   os.pathr   r   r   Zshutilr   Zdhpython.build.baser   r	   r
   Z	getLoggerr   r,   r"   r#   r   r   r   r   <module>   s   
!