U
    *eV4                     @   s   d dl Z d dlZddlmZ ddlmZmZ ddlmZm	Z	 ddl
mZ ddlmZmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlmZ G dd deZdS )    N   )BuildableBindings)generateCodepy2c)ConfigurableOption)UserException)parseresolve)
output_apioutput_extract
output_pyi)Installable)copy_nonshared_sources)SIP_VERSIONc                       sx  e Zd ZdZededededededededededededed	eded
edededededededededededededededededededededddededdededddeded d!d"ed#ed$ded%ed&ded%ed d'd"ed(ed)dfZ fd*d+Z	 fd,d-Z
 fd.d/Zd0d1 Z fd2d3Zd4d5 Z fd6d7Z  ZS )8Bindingsz+ The encapsulation of a module's bindings. builder_settings)option_typedefine_macros
exceptionsextra_compile_argsextra_link_argsextra_objectsgenerate_extractsheadersinclude_dirsinternal	librarieslibrary_dirsrelease_gilstaticsip_filesource_suffixsourcestagsconcatenatez6concatenate the generated bindings into N source filesN)r   helpmetavardebugzbuild with debugging symbols)r   r'   disabled_featureszdisable the TAG feature tagZTAG
docstringsTz$disable the generation of docstrings)r   invertedr'   
pep484_pyiz+enable the generation of PEP 484 .pyi filesprotected_is_publicz9enable the protected/public hack (default on non-Windows)z6disable the protected/public hack (default on Windows)tracingzbuild with tracing supportc                    s$   t    || _|| _| | dS )z Initialise the bindings. N)super__init__projectnameZinitialise_options)selfr2   r3   kwargs	__class__ 0lib/python3.8/site-packages/sipbuild/bindings.pyr1   y   s    
zBindings.__init__c                    s&   | j dkr| jd | _ t | dS )zd Set default values for each non-user configurable option that
        hasn't been set yet.
        Nz.sip)r!   r3   r0   apply_nonuser_defaultsr4   Ztoolr6   r8   r9   r:      s    
zBindings.apply_nonuser_defaultsc                    s(   | j dkr| jjdk| _ t | dS )z@ Set default values for user options that haven't been set yet. Nwin32)r.   r2   Zpy_platformr0   apply_user_defaultsr;   r6   r8   r9   r=      s    
zBindings.apply_user_defaultsc                 C   s  | j }d}t| jt||j| j| j| j| j|j		\}}}t
|| t||}|j}|jpZ|j}t| |jj|d}	|	j| j | j|	_| j|	_| j|	_| j|	_| j|	_| j|	_|jr| js|d|	j t|t j!"|j#|	jd  | j$D ]}
t%||
 q| j&rh| jsh|d|	j t j!"|	j#|	jd }t'||| t(d|	) d}|j*+| |	j,+| t-||	j#| j.| j| j/| j0| j1| j| j| j2|j3\}}|r|	j4+| |	j4| j4 |	j5| |	j6+|	j# |j	rN|	j6+|j# | jsn|	7d	}t j!8| j}|D ].}t j!"||}t j!9|r|j*+| q|	j,+| n |	j5t:|j;d
d |	j# |	j6| j6 |	j5| j5 | jr|	j<+d |	j<+d |	j<| j< |	j=| j= |	j>| j> |	S )z Generate the bindings source code and optional additional extracts.
        and return a BuildableBindings instance containing the details of
        everything needed to build the bindings.
        zUTF-8)uses_limited_apizGenerating the {0} .api filez.apizGenerating the {0} .pyi filez.pyiZpyi)Ztarget_subdirZsip.r   ZSIP_PROTECTED_IS_PUBLICzprotected=public)?r2   r	   r!   r   Zabi_versionr$   r*   r.   Z_sip_include_dirsZ
sip_moduler
   r   moduleZuse_limited_apiZis_compositer   Z
fq_py_namer3   r   extendr)   r   r   r   r   r    Zapi_dirr   Zprogressformattargetr   ospathjoinZ	build_dirr   r   r-   r   r   Zget_install_subdirfilesappendZinstallablesr   r"   r/   r   r%   r+   py_debugr   r#   r   Zget_bindings_installabledirnameisfiler   splitr   r   r   )r4   r2   encodingspecmodulesZ	sip_filesZptr@   r>   	buildableZextract_refZpyi_pathinstallableheaderr#   Zsip_dirfnZsip_pathr8   r8   r9   generate   s    
   







      
	zBindings.generatec                    s   t   }|| j |S )z* Return the list of configurable options. )r0   get_optionsrA   _options)r4   Zoptionsr6   r8   r9   rU     s    
zBindings.get_optionsc                 C   s   dS )z Return True if the bindings are buildable.  This will not be called
        if the bindings have been explicitly enabled.
        Tr8   )r4   r8   r8   r9   is_buildable   s    zBindings.is_buildablec                    s  |t jkrdS | j t |  fdd| jD | _ fdd| jD | _ fdd| jD | _ fdd| jD | _ j	| j
 jd| _
 fdd| jD | _tj| j
std	| j
| jtjd
kr| jr jstd| jn jrtd| j| jsd| _dS )z; Verify that the configuration is complete and consistent. Nc                    s   g | ]}  |qS r8   project_path).0or2   r8   r9   
<listcomp>2  s   z1Bindings.verify_configuration.<locals>.<listcomp>c                    s   g | ]}  |qS r8   rX   )rZ   hr\   r8   r9   r]   4  s     c                    s   g | ]}  |qS r8   rX   rZ   dr\   r8   r9   r]   5  s   c                    s   g | ]}  |qS r8   rX   r_   r\   r8   r9   r]   7  s   )relative_toc                    s   g | ]}  |qS r8   rX   )rZ   sr\   r8   r9   r]   ;  s     z2the file '{0}' for the {1} bindings does not existr<   zXA debug version of Python must be used when building a debug version of the {0} bindingszXA debug version of the {0} bindings must be built when a debug version of Python is used)r   ZBUILD_TOOLSr2   r0   verify_configurationr   r   r   r   rY   r!   Zsip_files_dirr#   rD   rE   rK   r   rB   r3   sysplatformr)   rI   r"   r;   r6   r\   r9   rc   '  sR    



 zBindings.verify_configuration)__name__
__module____qualname____doc__r   listboolintrV   r1   r:   r=   rT   rU   rW   rc   __classcell__r8   r8   r6   r9   r   &   sd   















 O
 r   )rD   rd   rP   r   Zcode_generatorr   r   Zconfigurabler   r   r   r   	generatorr	   r
   Zgenerator.outputsr   r   r   rQ   r   r@   r   versionr   r   r8   r8   r8   r9   <module>   s   