???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................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=Olalso compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0]forcef2forcibly 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sy.t| j| _d| j  kodkn  st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 ng }x|ry| 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| |rtjj| S dS dS )zReturn 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   NrS   )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	||
sq|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     }