o
    NZh8A                     @   sx   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 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)ClassVar   )Command)DistutilsFileErrorDistutilsOptionError)convert_pathc                   @   s  e Zd ZU dZg dZddgZeee  e	d< ddiZ
eeeef  e	d< dd	 Zd2ddZd2ddZdd Zdd Zd2d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d3d'ed
ee fd(d)Zd*d+ Zd2d,d-Zd2d.d/Zd2d0d1ZdS )4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   boolean_optionsr   negative_optc                 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   U/var/www/auris/lib/python3.10/site-packages/setuptools/_distutils/command/build_py.pyinitialize_options$   s   
zbuild_py.initialize_optionsreturnNc              	   C   s   |  ddd | jj| _| jj| _| jj| _i | _| jjr/| jj D ]\}}t|| j|< q#|  | _	t
| jts`zt| j| _d| j  krMdksPJ  J W d S  ttfy_   tdw d S )Nbuild)r   r   )r   r   r   r   zoptimize must be 0, 1, or 2)Zset_undefined_optionsdistributionpackagesr   r   r   itemsr   get_data_files
data_files
isinstancer   int
ValueErrorAssertionErrorr   )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   runG   s   zbuild_py.runc                    s   g }| j s|S | j D ]4}| |}tjj| jg|d  }d |r(t|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>w   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   r8   r   r#   e   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 | ]}| vrt j|r|qS r   )r<   r*   isfile)r6   fnfilesr   r   r:      s    z,build_py.find_data_files.<locals>.<listcomp>)	r   getglobr<   r*   r=   escaper   extend)r   r   rC   Zglobspatternfilelistr   rI   r   r@   {   s   
zbuild_py.find_data_filesc                 C   s\   | j D ](\}}}}|D ]}tj||}| tj| | jtj|||dd qqdS )z$Copy data files into build directoryFZpreserve_modeN)r$   r<   r*   r=   mkpathdirname	copy_file)r   Z_packagerC   rD   rE   filenametargetr   r   r   r/      s   zbuild_py.build_package_datac                 C   s   | d}| js|rtjj| S dS g }|rCz
| jd| }W n ty4   |d|d  |d= Y nw |d| tjj| S |s| jd}|durS|d| |r[tjj| 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).r3   rF   r   N)r>   r   r<   r*   r=   KeyErrorinsertrK   )r   r   r*   tailZpdirr   r   r   r;      s,   

zbuild_py.get_package_dirc                 C   sf   |dkr t j|std| dt j|s td| d|r1t j|d}t j|r1|S d S )NrF   zpackage directory 'z' does not existzsupposed package directory 'z ' exists, but is not a directoryz__init__.py)r<   r*   existsr   isdirr=   rG   )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 )Nz!file %s (for module %s) not foundFT)r<   r*   rG   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 ])}tj|}||kr@tj	tj
|d }||||f q| d|  q|S )Nz*.pyr   z
excluding )r^   rL   r<   r*   r=   rM   abspathr    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 }| j D ]]}|d}d|dd }|d }z|| \}}W n ty3   | |}d}Y nw |sL| ||}	|df||< |	rL||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.
        r3   r   rW   Fr4   __init__.py)
r   r>   r=   rX   r;   r^   rA   r<   r*   rb   )r   r!   rg   r`   r*   r   Zmodule_baser   checkedr]   ra   r   r   r   find_modules   s,   


zbuild_py.find_modulesc                 C   sN   g }| j r||   | jr%| 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   rN   rl   r!   r;   rh   )r   rg   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 )rW   r   )r6   r`   r   r   r   r:   0  s    z-build_py.get_source_files.<locals>.<listcomp>)rn   r   r   r   r   get_source_files/  s   zbuild_py.get_source_filesc                 C   s$   |gt | |d g }tjj| S )Nrj   )listr<   r*   r=   )r   rD   r   r`   Zoutfile_pathr   r   r   get_module_outfile2  s   zbuild_py.get_module_outfileTr,   c                 C   s   |   }g }|D ]8\}}}|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 )Nr3   rF   )optimizationr   c                 S   s,   g | ]\}}}}|D ]	}t j||q
qS r   )r<   r*   r=   )r6   r   rC   rD   rE   rU   r   r   r   r:   I  s    
z(build_py.get_outputs.<locals>.<listcomp>)rn   r>   rq   r   rA   r   	importlibutilcache_from_sourcer   r$   )r   r,   rg   Zoutputsr   r`   Z_module_filerU   r   r   r   r1   6  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 )Nr3   z:'package' must be a string (dot-separated), list, or tupleFrQ   )r%   strr>   rp   tuple	TypeErrorrq   r   r<   r*   rS   rR   rT   )r   r`   ra   r   outfiledirr   r   r   build_moduleQ  s   

zbuild_py.build_modulec                 C   s*   |   }|D ]\}}}| ||| qd S r5   )rl   r{   )r   rg   r   r`   ra   r   r   r   r-   a  s   zbuild_py.build_modulesc                 C   sP   | j D ]"}| |}| ||}|D ]\}}}||ksJ | ||| qqd S r5   )r!   r;   rh   r{   )r   r   r   rg   Zpackage_r`   ra   r   r   r   r.   j  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r-||d| j	|| j
d | jdkr@||| j| j	|| j
d d S d S )Nz%byte-compiling is disabled, skipping.r   )r0   rW   r   )r   r   prefixdry_run)sysdont_write_bytecodewarnrt   r0   r   r<   sepr   r   r}   r   )r   rJ   r0   r|   r   r   r   r0   ~  s(   



zbuild_py.byte_compile)r   N)T) __name__
__module____qualname__descriptionZuser_optionsr   r   rp   rv   __annotations__r   dictr   r+   r2   r#   r@   r/   r;   r^   rb   rh   rl   rn   ro   rq   boolr1   r{   r-   r.   r0   r   r   r   r   r	      s0   
 




'4

	r	   )__doc__rL   importlib.utilrs   r<   r~   Zdistutils._logr   typingr   corer   errorsr   r   rt   r   r	   r   r   r   r   <module>   s    