509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3

  \C  ã               @   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T ddl	m
Z
mZ ddlmZ G dd	„ d	eƒZG d
d„ deeƒZdS )zHdistutils.command.build_py

Implements the Distutils 'build_py' command.é    N)Úglob)ÚCommand)Ú*)Úconvert_pathÚ	Mixin2to3)Úlogc               @   sÈ   e Zd ZdZd8d9d:d;d<gZ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%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd=d.d/„Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd	S )>Úbuild_pyz5"build" pure Python modules (copy to build directory)ú
build-lib=Údúdirectory to "build" (copy) toÚcompileÚcúcompile .py to .pycú
no-compileNú!don't compile .py files [default]ú	optimize=ÚOúlalso compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0]ÚforceÚfú2forcibly build everything (ignore file timestamps)c             C   s4   d | _ d | _d | _d | _d | _d| _d| _d | _d S )Nr   )Ú	build_libÚ
py_modulesÚpackageÚpackage_dataÚpackage_dirr   Úoptimizer   )Úself© r   ú2/usr/lib64/python3.6/distutils/command/build_py.pyÚinitialize_options    s    zbuild_py.initialize_optionsc             C   sÌ   | j dddƒ | jj| _| jj| _| jj| _i | _| jjrbx&| jjjƒ D ]\}}t|ƒ| j|< qHW | jƒ | _	t
| jtƒsÈy.t| jƒ| _d| j  košdkn  s¤t‚W n  ttfk
rÆ   tdƒ‚Y nX d S )	NZbuildr   r   r   é   zoptimize must be 0, 1, or 2)r   r   )r   r   )Zset_undefined_optionsÚdistributionÚpackagesr   r   r   Úitemsr   Úget_data_filesÚ
data_filesÚ
isinstancer   ÚintÚAssertionErrorÚ
ValueErrorZDistutilsOptionError)r   ÚnameÚpathr   r   r   Úfinalize_options*   s"    



"zbuild_py.finalize_optionsc             C   s:   | j r| jƒ  | jr$| jƒ  | jƒ  | j| jdd�ƒ d S )Nr   )Úinclude_bytecode)r   Úbuild_modulesr#   Úbuild_packagesÚbuild_package_dataÚbyte_compileÚget_outputs)r   r   r   r   ÚrunC   s    zbuild_py.runc                s†   g }| j s|S xr| j D ]h}| j|ƒ}tjj| jg|jdƒ Ž }d‰ |rRt|ƒd ‰ ‡ fdd„| j||ƒD ƒ}|j	||||fƒ qW |S )z?Generate list of '(package,src_dir,build_dir,filenames)' tuplesÚ.r   é   c                s   g | ]}|ˆ d … ‘qS )Nr   )Ú.0Úfile)Úplenr   r   ú
<listcomp>t   s    z+build_py.get_data_files.<locals>.<listcomp>)
r#   Úget_package_dirÚosr,   Újoinr   ÚsplitÚlenÚfind_data_filesÚappend)r   Údatar   Úsrc_dirÚ	build_dirÚ	filenamesr   )r9   r   r%   a   s    
zbuild_py.get_data_filesc                s`   | j jdg ƒ| j j|g ƒ }g ‰ x:|D ]2}ttjj|t|ƒƒƒ}ˆ j‡ fdd„|D ƒƒ q&W ˆ S )z6Return filenames for package's data files in 'src_dir'Ú c                s$   g | ]}|ˆ krt jj|ƒr|‘qS r   )r<   r,   Úisfile)r7   Úfn)Úfilesr   r   r:   ‚   s    
z,build_py.find_data_files.<locals>.<listcomp>)r   Úgetr   r<   r,   r=   r   Úextend)r   r   rC   ZglobsÚpatternZfilelistr   )rI   r   r@   y   s    
zbuild_py.find_data_filesc             C   sh   d}x^| j D ]T\}}}}xF|D ]>}tjj||ƒ}| jtjj|ƒƒ | jtjj||ƒ|dd� qW qW dS )z$Copy data files into build directoryNF)Úpreserve_mode)r&   r<   r,   r=   ÚmkpathÚdirnameÚ	copy_file)r   Zlastdirr   rC   rD   rE   ÚfilenameÚtargetr   r   r   r1   †   s    
zbuild_py.build_package_datac             C   sÄ   |j dƒ}| js&|r tjj|Ž S dS nšg }x”|rŠy| jdj|ƒ }W n* tk
rn   |jd|d ƒ |d= Y q,X |jd|ƒ tjj|Ž S q,W | jjdƒ}|dk	r¬|jd|ƒ |r¼tjj|Ž S dS dS )z½Return the directory, relative to the top of the source
           distribution, where package 'package' should be found
           (at least according to the 'package_dir' option, if any).r5   rF   r   r6   NéÿÿÿÿrS   )r>   r   r<   r,   r=   ÚKeyErrorÚinsertrJ   )r   r   r,   ÚtailZpdirr   r   r   r;   �   s(    
	zbuild_py.get_package_dirc             C   sj   |dkr8t jj|ƒs td| ƒ‚t jj|ƒs8td| ƒ‚|rft jj|dƒ}t jj|ƒrZ|S tjd|ƒ d S )NrF   z%package directory '%s' does not existz>supposed package directory '%s' exists, but is not a directoryz__init__.pyz!package init file '%s' not found z(or not a regular file)z8package init file '%s' not found (or not a regular file))	r<   r,   ÚexistsZDistutilsFileErrorÚisdirr=   rG   r   Úwarn)r   r   r   Úinit_pyr   r   r   Úcheck_package·   s    
zbuild_py.check_packagec             C   s&   t jj|ƒstjd||ƒ dS dS d S )Nz!file %s (for module %s) not foundFT)r<   r,   rG   r   rY   )r   ÚmoduleÚmodule_filer   r   r   Úcheck_moduleÒ   s    zbuild_py.check_modulec       	      C   s�   | j ||ƒ ttjj|dƒƒ}g }tjj| jjƒ}xX|D ]P}tjj|ƒ}||krztjjtjj	|ƒƒd }|j
|||fƒ q8| jd| ƒ q8W |S )Nz*.pyr   zexcluding %s)r[   r   r<   r,   r=   Úabspathr"   Zscript_nameÚsplitextÚbasenamerA   Zdebug_print)	r   r   r   Zmodule_filesÚmodulesZsetup_scriptr   Zabs_fr\   r   r   r   Úfind_package_modulesÙ   s    
zbuild_py.find_package_modulesc             C   sÔ   i }g }xÆ| j D ]¼}|jdƒ}dj|dd… ƒ}|d }y|| \}}W n" tk
rj   | j|ƒ}d}Y nX |sœ| j||ƒ}	|df||< |	rœ|j|d|	fƒ tjj||d ƒ}
| j	||
ƒs¼q|j|||
fƒ qW |S )aÈ  Finds individually-specified Python modules, ie. those listed by
        module name in 'self.py_modules'.  Returns a list of tuples (package,
        module_base, filename): 'package' is a tuple of the path through
        package-space to the module; 'module_base' is the bare (no
        packages, no dots) module name, and 'filename' is the path to the
        ".py" file (relative to the distribution root) that implements the
        module.
        r5   r   r6   Ú__init__z.pyrS   rS   )
r   r>   r=   rT   r;   r[   rA   r<   r,   r^   )r   r#   rb   r\   r,   r   Zmodule_baser   ZcheckedrZ   r]   r   r   r   Úfind_modulesè   s*    


zbuild_py.find_modulesc             C   sR   g }| j r|j| jƒ ƒ | jrNx.| jD ]$}| j|ƒ}| j||ƒ}|j|ƒ q&W |S )a4  Compute the list of all modules that will be built, whether
        they are specified one-module-at-a-time ('self.py_modules') or
        by whole packages ('self.packages').  Return a list of tuples
        (package, module, module_file), just like 'find_modules()' and
        'find_package_modules()' do.)r   rK   re   r#   r;   rc   )r   rb   r   r   Úmr   r   r   Úfind_all_modules  s    
zbuild_py.find_all_modulesc             C   s   dd„ | j ƒ D ƒS )Nc             S   s   g | ]}|d ‘qS )r6   rS   r   )r7   r\   r   r   r   r:   -  s    z-build_py.get_source_files.<locals>.<listcomp>)rg   )r   r   r   r   Úget_source_files,  s    zbuild_py.get_source_filesc             C   s$   |gt |ƒ |d g }tjj|Ž S )Nz.py)Úlistr<   r,   r=   )r   rD   r   r\   Zoutfile_pathr   r   r   Úget_module_outfile/  s    zbuild_py.get_module_outfiler6   c             C   sž   | j ƒ }g }xx|D ]p\}}}|jdƒ}| j| j||ƒ}|j|ƒ |r| jr`|jtjj|dd�ƒ | j	dkr|jtjj|| j	d�ƒ qW |dd„ | j
D ƒ7 }|S )Nr5   rF   )Úoptimizationr   c             S   s,   g | ]$\}}}}|D ]}t jj||ƒ‘qqS r   )r<   r,   r=   )r7   r   rC   rD   rE   rQ   r   r   r   r:   C  s   
z(build_py.get_outputs.<locals>.<listcomp>)rg   r>   rj   r   rA   r   Ú	importlibÚutilÚcache_from_sourcer   r&   )r   r.   rb   Zoutputsr   r\   r]   rQ   r   r   r   r3   3  s"    




zbuild_py.get_outputsc             C   sb   t |tƒr|jdƒ}nt |ttfƒs,tdƒ‚| j| j||ƒ}tj	j
|ƒ}| j|ƒ | j||dd�S )Nr5   z:'package' must be a string (dot-separated), list, or tupler   )rM   )r'   Ústrr>   ri   ÚtupleÚ	TypeErrorrj   r   r<   r,   rO   rN   rP   )r   r\   r]   r   ZoutfileÚdirr   r   r   Úbuild_moduleJ  s    

zbuild_py.build_modulec             C   s.   | j ƒ }x |D ]\}}}| j|||ƒ qW d S )N)re   rs   )r   rb   r   r\   r]   r   r   r   r/   Y  s    zbuild_py.build_modulesc             C   sX   xR| j D ]H}| j|ƒ}| j||ƒ}x,|D ]$\}}}||ks>t‚| j|||ƒ q(W qW d S )N)r#   r;   rc   r)   rs   )r   r   r   rb   Zpackage_r\   r]   r   r   r   r0   b  s    

zbuild_py.build_packagesc             C   s€   t jr| jdƒ d S ddlm} | j}|d tjkr>|tj }| jrZ||d| j	|| j
d� | jdkr|||| j| j	|| j
d� d S )Nz%byte-compiling is disabled, skipping.r   )r2   r6   )r   r   ÚprefixÚdry_runrS   )ÚsysÚdont_write_bytecoderY   Údistutils.utilr2   r   r<   Úsepr   r   ru   r   )r   rI   r2   rt   r   r   r   r2   v  s    


zbuild_py.byte_compile)r	   r
   r   )r   r   r   )r   Nr   )r   r   r   )r   r   r   )r6   )Ú__name__Ú
__module__Ú__qualname__ZdescriptionZuser_optionsZboolean_optionsZnegative_optr    r-   r4   r%   r@   r1   r;   r[   r^   rc   re   rg   rh   rj   r3   rs   r/   r0   r2   r   r   r   r   r      s8    

'4
	r   c               @   s   e Zd Zdd„ Zdd„ ZdS )Úbuild_py_2to3c             C   sL   g | _ | jr| jƒ  | jr*| jƒ  | jƒ  | j| j ƒ | j| jdd�ƒ d S )Nr   )r.   )	Úupdated_filesr   r/   r#   r0   r1   Zrun_2to3r2   r3   )r   r   r   r   r4   ‹  s    zbuild_py_2to3.runc             C   s,   t j| |||ƒ}|d r(| jj|d ƒ |S )Nr6   r   )r   rs   r~   rA   )r   r\   r]   r   Úresr   r   r   rs   ›  s    zbuild_py_2to3.build_moduleN)rz   r{   r|   r4   rs   r   r   r   r   r}   Š  s   r}   )Ú__doc__r<   Úimportlib.utilrl   rv   r   Zdistutils.corer   Zdistutils.errorsrx   r   r   Z	distutilsr   r   r}   r   r   r   r   Ú<module>   s     }