B
    v9aÍ   ã               @   sH   d dl Z d dlZd dlZd dlmZ d dlmZ dZG dd„ deƒZ	dS )é    N)ÚCommand)ÚDistutilsOptionErrorz.pyc               @   s„   e Zd ZdZdddddddgZd	d
dgZdd
iZdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!S )"Úinstall_libz7install all Python modules (extensions and pure Python))zinstall-dir=Údzdirectory to install to)z
build-dir=Úbz'build directory (where to install from))ÚforceÚfz-force installation (overwrite existing files))ÚcompileÚczcompile .py to .pyc [default])z
no-compileNzdon't compile .py files)z	optimize=ÚOzlalso compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0])z
skip-buildNzskip the build stepsr   r	   z
skip-buildz
no-compilec             C   s(   d | _ d | _d| _d | _d | _d | _d S )Nr   )Úinstall_dirÚ	build_dirr   r	   ÚoptimizeÚ
skip_build)Úself© r   ú!/usr/lib/python3.7/install_lib.pyÚinitialize_options3   s    zinstall_lib.initialize_optionsc          	   C   s†   |   ddddddd¡ | jd kr&d| _| jd kr6d	| _t| jtƒs‚yt| jƒ| _| jd
kr^t‚W n  ttfk
r€   tdƒ‚Y nX d S )NÚinstall)Ú	build_libr   )r   r   )r   r   )r	   r	   )r   r   )r   r   TF)r   é   é   zoptimize must be 0, 1, or 2)Zset_undefined_optionsr	   r   Ú
isinstanceÚintÚAssertionErrorÚ
ValueErrorr   )r   r   r   r   Úfinalize_options<   s$    


zinstall_lib.finalize_optionsc             C   s0   |   ¡  |  ¡ }|d k	r,| j ¡ r,|  |¡ d S )N)Úbuildr   ÚdistributionÚhas_pure_modulesÚbyte_compile)r   Úoutfilesr   r   r   ÚrunV   s    zinstall_lib.runc             C   s2   | j s.| j ¡ r|  d¡ | j ¡ r.|  d¡ d S )NÚbuild_pyÚ	build_ext)r   r   r   Zrun_commandÚhas_ext_modules)r   r   r   r   r   f   s
    


zinstall_lib.buildc             C   s8   t j | j¡r |  | j| j¡}n|  d| j ¡ d S |S )Nz3'%s' does not exist -- no Python modules to install)ÚosÚpathÚisdirr   Z	copy_treer   Úwarn)r   r!   r   r   r   r   m   s    
zinstall_lib.installc             C   sr   t jr|  d¡ d S ddlm} |  d¡j}| jrH||d| j|| j	d | j
dkrn||| j
| j|| j| j	d d S )Nz%byte-compiling is disabled, skipping.r   )r    r   )r   r   ÚprefixÚdry_run)r   r   r*   Úverboser+   )ÚsysÚdont_write_bytecoder)   Zdistutils.utilr    Úget_finalized_commandÚrootr	   r   r+   r   r,   )r   Úfilesr    Zinstall_rootr   r   r   r    v   s    


zinstall_lib.byte_compilec       
   	   C   sh   |sg S |   |¡}| ¡ }t||ƒ}t|ƒttjƒ }g }x(|D ] }	| tj ||	|d … ¡¡ q@W |S )N)	r/   Úget_outputsÚgetattrÚlenr&   ÚsepÚappendr'   Újoin)
r   Zhas_anyZ	build_cmdZ
cmd_optionZ
output_dirZbuild_filesr   Ú
prefix_lenZoutputsÚfiler   r   r   Ú_mutate_outputs   s    


 zinstall_lib._mutate_outputsc             C   sv   g }xl|D ]d}t j t j |¡¡d }|tkr0q
| jrL| tjj	|dd¡ | j
dkr
| tjj	|| j
d¡ q
W |S )Nr   Ú )Úoptimizationr   )r&   r'   ÚsplitextÚnormcaseÚPYTHON_SOURCE_EXTENSIONr	   r6   Ú	importlibÚutilÚcache_from_sourcer   )r   Zpy_filenamesZbytecode_filesZpy_fileZextr   r   r   Ú_bytecode_filenamesž   s    



zinstall_lib._bytecode_filenamesc             C   sR   |   | j ¡ dd| j¡}| jr*|  |¡}ng }|   | j ¡ dd| j¡}|| | S )Nr#   r   r$   )r:   r   r   r   r	   rC   r%   )r   Zpure_outputsZbytecode_outputsZext_outputsr   r   r   r2   ´   s    zinstall_lib.get_outputsc             C   sL   g }| j  ¡ r&|  d¡}| | ¡ ¡ | j  ¡ rH|  d¡}| | ¡ ¡ |S )Nr#   r$   )r   r   r/   Úextendr2   r%   )r   Zinputsr#   r$   r   r   r   Ú
get_inputsÉ   s    



zinstall_lib.get_inputsN)Ú__name__Ú
__module__Ú__qualname__ÚdescriptionZuser_optionsZboolean_optionsZnegative_optr   r   r"   r   r   r    r:   rC   r2   rE   r   r   r   r   r      s(   
		r   )
r&   Úimportlib.utilr@   r-   Zdistutils.corer   Zdistutils.errorsr   r?   r   r   r   r   r   Ú<module>   s   