U
    aÊ¹j¨@  ã                   @   sl   d Z ddl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
mZmZ ddlmZ G dd	„ d	e	ƒZdS )
zHdistutils.command.build_py

Implements the Distutils 'build_py' command.é    N)Úlogé   )ÚCommand)ÚDistutilsFileErrorÚDistutilsOptionError)Úconvert_pathc                   @   sÈ   e Zd ZdZddd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d2d'd(„Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1S )3Úbuild_pyz5"build" pure Python modules (copy to build directory))z
build-lib=Údzdirectory to "build" (copy) to)ÚcompileÚczcompile .py to .pyc)ú
no-compileNz!don't compile .py files [default])z	optimize=ÚOzlalso compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0])ÚforceÚfz2forcibly build everything (ignore file timestamps)r
   r   r   c                 C   s4   d | _ d | _d | _d | _d | _d| _d| _d | _d S )NFr   )Ú	build_libÚ
py_modulesÚpackageÚpackage_dataÚpackage_dirr
   Úoptimizer   ©Úself© r   úe/var/www/html/bwave/python/venv/lib/python3.8/site-packages/setuptools/_distutils/command/build_py.pyÚinitialize_options#   s    zbuild_py.initialize_optionsc              	   C   sÆ   |   ddd¡ | jj| _| jj| _| jj| _i | _| jjr^| jj ¡ D ]\}}t|ƒ| j|< qF|  ¡ | _	t
| jtƒsÂz,t| jƒ| _d| j  kr˜dksžn t‚W n  ttfk
rÀ   tdƒ‚Y nX d S )NÚbuild)r   r   )r   r   r   r   zoptimize must be 0, 1, or 2)Úset_undefined_optionsÚdistributionÚpackagesr   r   r   Úitemsr   Úget_data_filesÚ
data_filesÚ
isinstancer   ÚintÚAssertionErrorÚ
ValueErrorr   )r   ÚnameÚpathr   r   r   Úfinalize_options-   s&      ÿ



 zbuild_py.finalize_optionsc                 C   s:   | j r|  ¡  | jr$|  ¡  |  ¡  |  | jdd�¡ d S )NF)Úinclude_bytecode)r   Úbuild_modulesr   Úbuild_packagesÚbuild_package_dataÚbyte_compileÚget_outputsr   r   r   r   ÚrunF   s    zbuild_py.runc                    s‚   g }| j s|S | j D ]h}|  |¡}tjj| jg| d¡ Ž }d‰ |rPt|ƒd ‰ ‡ fdd„|  ||¡D ƒ}| 	||||f¡ q|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>v   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   r5   r   r    d   s    

zbuild_py.get_data_filesc                    sd   | j  dg ¡| j  |g ¡ }g ‰ |D ]:}t tj t |¡t|ƒ¡¡}ˆ  ‡ fdd„|D ƒ¡ q$ˆ S )z6Return filenames for package's data files in 'src_dir'Ú c                    s$   g | ]}|ˆ krt j |¡r|‘qS r   )r9   r'   Úisfile)r3   Úfn©Úfilesr   r   r7   „   s      z,build_py.find_data_files.<locals>.<listcomp>)	r   ÚgetÚglobr9   r'   r:   Úescaper   Úextend)r   r   r@   ZglobsÚpatternÚfilelistr   rF   r   r=   z   s    ÿÿ
zbuild_py.find_data_filesc                 C   s\   | j D ]P\}}}}|D ]>}tj ||¡}|  tj |¡¡ | jtj ||¡|dd� qqdS )z$Copy data files into build directoryF©Úpreserve_modeN)r!   r9   r'   r:   ÚmkpathÚdirnameÚ	copy_file)r   Z_packager@   rA   rB   ÚfilenameÚtargetr   r   r   r,   ‰   s      ÿzbuild_py.build_package_datac                 C   sÀ   |  d¡}| js&|r tjj|Ž S dS n–g }|rˆz| jd |¡ }W n* tk
rl   | d|d ¡ |d= Y q*X | d|¡ tjj|Ž S q*| j d¡}|dk	r¨| 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).r0   rC   r   éÿÿÿÿN)r;   r   r9   r'   r:   ÚKeyErrorÚinsertrH   )r   r   r'   ÚtailZpdirr   r   r   r8   “   s(    
	zbuild_py.get_package_dirc                 C   sf   |dkr@t j |¡s$td|› d�ƒ‚t j |¡s@td|› d�ƒ‚|rbt j |d¡}t j |¡rb|S d S )NrC   zpackage directory 'z' does not existzsupposed package directory 'z ' exists, but is not a directoryz__init__.py)r9   r'   Úexistsr   Úisdirr:   rD   )r   r   r   Úinit_pyr   r   r   Úcheck_packageº   s    
ÿ
ÿzbuild_py.check_packagec                 C   s&   t j |¡st d||¡ dS dS d S )Nz!file %s (for module %s) not foundFT)r9   r'   rD   r   Úwarning)r   ÚmoduleÚmodule_filer   r   r   Úcheck_moduleÔ   s    zbuild_py.check_modulec           	      C   s–   |   ||¡ t tj t |¡d¡¡}g }tj | jj¡}|D ]R}tj |¡}||kr€tj 	tj 
|¡¡d }| |||f¡ q>|  d|› �¡ q>|S )Nz*.pyr   z
excluding )r\   rI   r9   r'   r:   rJ   Úabspathr   Úscript_nameÚsplitextÚbasenamer>   Ú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 }| j D ]¼}| d¡}d |dd… ¡}|d }z|| \}}W n" tk
rh   |  |¡}d}Y nX |sš|  ||¡}	|df||< |	rš| |d|	f¡ tj ||d ¡}
|  	||
¡sºq| |||
f¡ q|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.
        r0   r   rU   Fr1   Ú__init__ú.py)
r   r;   r:   rV   r8   r\   r>   r9   r'   r`   )r   r   rf   r^   r'   r   Zmodule_baser   Úcheckedr[   r_   r   r   r   Úfind_modulesê   s*    



zbuild_py.find_modulesc                 C   sN   g }| j r| |  ¡ ¡ | jrJ| jD ]$}|  |¡}|  ||¡}| |¡ q$|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   rk   r   r8   rg   )r   rf   r   r   Úmr   r   r   Úfind_all_modules  s    

zbuild_py.find_all_modulesc                 C   s   dd„ |   ¡ D ƒS )Nc                 S   s   g | ]}|d  ‘qS )rU   r   )r3   r^   r   r   r   r7   /  s     z-build_py.get_source_files.<locals>.<listcomp>)rm   r   r   r   r   Úget_source_files.  s    zbuild_py.get_source_filesc                 C   s$   |gt |ƒ |d g }tjj|Ž S )Nri   )Úlistr9   r'   r:   )r   rA   r   r^   Zoutfile_pathr   r   r   Úget_module_outfile1  s    zbuild_py.get_module_outfileTc                 C   sš   |   ¡ }g }|D ]p\}}}| d¡}|  | j||¡}| |¡ |r| jr^| tjj|dd�¡ | j	dkr| tjj|| j	d�¡ q|dd„ | j
D ƒ7 }|S )Nr0   rC   )Úoptimizationr   c                 S   s,   g | ]$\}}}}|D ]}t j ||¡‘qqS r   )r9   r'   r:   )r3   r   r@   rA   rB   rS   r   r   r   r7   H  s   
 þz(build_py.get_outputs.<locals>.<listcomp>)rm   r;   rp   r   r>   r
   Ú	importlibÚutilÚcache_from_sourcer   r!   )r   r)   rf   Úoutputsr   r^   Z_module_filerS   r   r   r   r.   5  s,    

ÿ
 ÿÿþzbuild_py.get_outputsc                 C   sb   t |tƒr| d¡}nt |ttfƒs,tdƒ‚|  | j||¡}tj	 
|¡}|  |¡ | j||dd�S )Nr0   z:'package' must be a string (dot-separated), list, or tupleFrN   )r"   Ústrr;   ro   ÚtupleÚ	TypeErrorrp   r   r9   r'   rQ   rP   rR   )r   r^   r_   r   ÚoutfileÚdirr   r   r   Úbuild_moduleP  s    
ÿ
zbuild_py.build_modulec                 C   s*   |   ¡ }|D ]\}}}|  |||¡ qd S r2   )rk   r{   )r   rf   r   r^   r_   r   r   r   r*   `  s    zbuild_py.build_modulesc                 C   sP   | j D ]D}|  |¡}|  ||¡}|D ]$\}}}||ks:t‚|  |||¡ q$qd S r2   )r   r8   rg   r$   r{   )r   r   r   rf   Zpackage_r^   r_   r   r   r   r+   i  s    


zbuild_py.build_packagesc                 C   s€   t jr|  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   )r-   rU   r   )r   r   ÚprefixÚdry_run)ÚsysÚdont_write_bytecodeÚwarnrs   r-   r   r9   Úsepr
   r   r}   r   )r   rG   r-   r|   r   r   r   r-   }  s.    

    ÿ
ûzbuild_py.byte_compileN)T)Ú__name__Ú
__module__Ú__qualname__ÚdescriptionÚuser_optionsÚboolean_optionsÚnegative_optr   r(   r/   r    r=   r,   r8   r\   r`   rg   rk   rm   rn   rp   r.   r{   r*   r+   r-   r   r   r   r   r      s8   ö

'4
	r   )Ú__doc__rI   Zimportlib.utilrr   r9   r~   Zdistutils._logr   Úcorer   Úerrorsr   r   rs   r   r   r   r   r   r   Ú<module>   s   