U
    ËAš`/U  ã                   @   sÊ  d Z ddl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	m
Z
 ej ej¡Zej ej¡Zej ej¡Zej ej¡Zdejkržej ejd ¡Zn&ejr¼ej ej ej¡¡Zne ¡ Zdd„ Zeed	dƒZejd
krúdd„ ZeeƒZeeƒZdd„ Z e ƒ Z!dZ"ze!sej#Z"W n e$k
r2   Y nX dd„ Z%d-dd„Z&d.dd„Z'dd„ Z(dd„ Z)dd„ Z*d/dd„Z+e ,d¡Z-e ,d¡Z.e ,d ¡Z/d0d!d"„Z0d#d$„ Z1da2d%d&„ Z3d'd(„ Z4d)d*„ Z5d+d,„ Z6dS )1a  Provide access to Python's configuration information.  The specific
configuration variables available depend heavily on the platform and
configuration.  The values may be retrieved using
get_config_var(name), and the list of variables is available via
get_config_vars().keys().  Additional convenience functions are also
available.

Written by:   Fred L. Drake, Jr.
Email:        <fdrake@acm.org>
é    Né   )ÚDistutilsPlatformError)Úget_platformÚget_host_platformZ_PYTHON_PROJECT_BASEc                 C   s,   dD ]"}t j t j | d|¡¡r dS qdS )N)ZSetupzSetup.localZModulesTF)ÚosÚpathÚisfileÚjoin)ÚdÚfn© r   ú)/usr/lib/python3.8/distutils/sysconfig.pyÚ_is_python_source_dir,   s    r   Z_homeÚntc                 C   s0   | r,t j | ¡ t j t j td¡¡¡r,tS | S )NZPCbuild)r   r   ÚnormcaseÚ
startswithr	   ÚPREFIX)r
   r   r   r   Ú_fix_pcbuild5   s
    ÿr   c                   C   s   t rtt ƒS ttƒS )N)Ú	_sys_homer   Úproject_baser   r   r   r   Ú_python_build=   s    r   Ú c                   C   s   dt jdd…  S )z–Return a string containing the major and minor Python version,
    leaving off the patchlevel.  Sample return values could be '1.5'
    or '2.2'.
    z%d.%dNé   )ÚsysÚversion_infor   r   r   r   Úget_python_versionQ   s    r   c                 C   sÖ   |dkr| rt pt}tjdkr„trL| r.tp,tS tj t	dƒd¡}tj 
|¡S dtƒ  t }tst| rtddl}| d¡S tj |d|¡S tjd	krÄtr¶tj |d¡tjj tj |d
¡ S tj |d¡S tdtj ƒ‚dS )a¤  Return the directory containing installed Python header files.

    If 'plat_specific' is false (the default), this is the path to the
    non-platform-specific header files, i.e. Python.h and so on;
    otherwise, this is the path to platform-specific header files
    (namely pyconfig.h).

    If 'prefix' is supplied, use it instead of sys.base_prefix or
    sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
    NÚposixÚsrcdirZIncludeÚpythonr   ZplatincludeZincluder   ÚPCzFI don't know where Python installs its C header files on platform '%s')ÚBASE_EXEC_PREFIXÚBASE_PREFIXr   ÚnameÚpython_buildr   r   r   r	   Úget_config_varÚnormpathr   Úbuild_flagsÚ	sysconfigZget_pathÚpathsepr   )Úplat_specificÚprefixZincdirZ
python_dirr'   r   r   r   Úget_python_incY   s0    


ÿÿÿr+   c                 C   sô   | pt j |¡dk}|dkr<|r0| r*tp,t}n| r8tp:t}t jdkr´t j |ddt	ƒ  ¡}|rd|S |r¤dt j
kr¤dt j
kr¤dtjkr¤tjtjkr¤t j |dd	d
¡S t j |d¡S n<t jdkrâ|rÐt j |d¡S t j |dd¡S ntdt j ƒ‚dS )aS  Return the directory containing the Python library (standard or
    site additions).

    If 'plat_specific' is true, return the directory containing
    platform-specific modules, i.e. any module from a non-pure-Python
    module distribution; otherwise, return the platform-shared library
    directory.  If 'standard_lib' is true, return the directory
    containing standard Python library modules; otherwise, return the
    directory for site-specific modules.

    If 'prefix' is supplied, use it instead of sys.base_prefix or
    sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
    )z/usrz
/usr/localNr   Zlibr   ZPYTHONUSERBASEZVIRTUAL_ENVZreal_prefixZpython3zdist-packageszsite-packagesr   ZLibz?I don't know where Python installs its library on platform '%s')r   r   r%   r    r!   ÚEXEC_PREFIXr   r"   r	   r   Úenvironr   Ú__dict__r*   Úbase_prefixr   )r)   Ústandard_libr*   Zis_default_prefixZ	libpythonr   r   r   Úget_python_lib„   s@    
 ÿÿþý
ü
ÿÿr1   c                 C   sš  | j dkr–tjdkr8tdƒs8ddl}| t¡ dtd< tddd	d
dddddddƒ\}}}}}}}}	}
}}dtj	kr´tj	d }tjdkr°dtj	kr°| 
|¡r°||t|ƒd…  }|}dtj	krÈtj	d }t ||gd¡rü| dd¡}| dd¡}| dd¡}dtj	krtj	d }dtj	kr*tj	d }n|d }dtj	krR|d tj	d  }n|rd|d | }d	tj	kr–|d tj	d	  }|d tj	d	  }n|r´|d | }|d | }dtj	krø|d tj	d  }|d tj	d  }|d tj	d  }n*|
r"|d |
 }|d |
 }|d |
 }dtj	kr8tj	d }dtj	krX|d tj	d  }n|d |	 }|d | }| j|||d | ||||d || _dS )zÄDo any platform-specific customization of a CCompiler instance.

    Mainly needed on Unix, so we can plug in the information that
    varies across Unices and is stored in Python's Makefile.
    ZunixÚdarwinZCUSTOMIZED_OSX_COMPILERr   NÚTrueZCCZCXXÚCFLAGSZCCSHAREDZLDSHAREDZSHLIB_SUFFIXZARZARFLAGSZCONFIGURE_CPPFLAGSZCONFIGURE_CFLAGSZCONFIGURE_LDFLAGSz	*-4.[0-8]z-fstack-protector-strongz-fstack-protectorZCPPz -EÚLDFLAGSú ÚCPPFLAGS)ZpreprocessorÚcompilerZcompiler_soZcompiler_cxxZ	linker_soZ
linker_exeÚarchiver)Zcompiler_typer   Úplatformr$   Ú_osx_supportÚcustomize_compilerÚ_config_varsÚget_config_varsr   r-   r   ÚlenÚfnmatchÚfilterÚreplaceZset_executablesZshared_lib_extension)r8   r;   ZccZcxxZcflagsZccsharedZldsharedZshlib_suffixZarZar_flagsZconfigure_cppflagsZconfigure_cflagsZconfigure_ldflagsZnewccZcppr9   Zcc_cmdr   r   r   r<   ²   s”    

      þþ  


ÿþ




ù	r<   c                  C   sD   t r,tjdkr"tj tptd¡} q6tp(t} n
tdd} tj | d¡S )z2Return full pathname of installed pyconfig.h file.r   r   r   ©r)   z
pyconfig.h)r#   r   r"   r   r	   r   r   r+   )Zinc_dirr   r   r   Úget_config_h_filename
  s    


rD   c                  C   s\   t rtj tptd¡S tddd} d tƒ t	¡}t
tjdƒrL|dtjj 7 }tj | |d¡S )zAReturn full pathname of installed Makefile from the Python build.ZMakefiler   r   ©r)   r0   zconfig-{}{}Ú
_multiarchz-%s)r#   r   r   r	   r   r   r1   Úformatr   r&   Úhasattrr   ÚimplementationrF   )Zlib_dirZconfig_filer   r   r   Úget_makefile_filename  s    rJ   c                 C   sš   |dkri }t  d¡}t  d¡}|  ¡ }|s.q–| |¡}|rx| dd¡\}}zt|ƒ}W n tk
rl   Y nX |||< q | |¡}|r d|| d¡< q |S )zÌParse a config.h-style file.

    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    Nz"#define ([A-Z][A-Za-z0-9_]+) (.*)
z&/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/
r   r   r   )ÚreÚcompileÚreadlineÚmatchÚgroupÚintÚ
ValueError)ÚfpÚgZ	define_rxZundef_rxÚlineÚmÚnÚvr   r   r   Úparse_config_h"  s&    


  

rX   z"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)z\$\(([A-Za-z][A-Za-z0-9_]*)\)z\${([A-Za-z][A-Za-z0-9_]*)}c              	   C   s¶  ddl m} || ddddd}|dkr*i }i }i }| ¡ }|dkrDqÄt |¡}|r2| dd¡\}}	|	 ¡ }	|	 dd	¡}
d
|
krˆ|	||< q2zt|	ƒ}	W n$ t	k
r¸   |	 dd
¡||< Y q2X |	||< q2d}|rtt
|ƒD ]˜}|| }t |¡pöt |¡}|rj| d¡}d}||kr$t|| ƒ}nˆ||kr4d}nx|tjkrLtj| }n`||kr | d¡rz|dd… |krzd	}n$d| |krŽd}nt|d|  ƒ}nd	 ||< }|rp|| ¡ d… }|d| ¡ … | | }d
|krî|||< nzzt|ƒ}W n" t	k
r   | ¡ ||< Y n
X |||< ||= | d¡rp|dd… |krp|dd… }||krp|||< qÖ||= qÖqÈ| ¡  | ¡ D ]"\}}	t|	tƒr„|	 ¡ ||< q„| |¡ |S )zÌParse a Makefile-style file.

    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    r   )ÚTextFiler   Úsurrogateescape)Zstrip_commentsZskip_blanksZ
join_linesÚerrorsNr   z$$r   ú$)r4   r5   r7   TFZPY_é   )Zdistutils.text_filerY   rM   Ú_variable_rxrN   rO   ÚstriprB   rP   rQ   ÚlistÚ_findvar1_rxÚsearchÚ_findvar2_rxÚstrr   r-   r   ÚendÚstartÚcloseÚitemsÚ
isinstanceÚupdate)r   rS   rY   rR   ZdoneZnotdonerT   rU   rV   rW   ZtmpvZrenamed_variablesr"   ÚvalueÚfoundÚitemZafterÚkr   r   r   Úparse_makefileE  s„    








 ÿ



ro   c                 C   sV   t  | ¡pt | ¡}|rR| ¡ \}}| d|… | | d¡¡ | |d…  } q qRq | S )a¨  Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
    'string' according to 'vars' (a dictionary mapping variable names to
    values).  Variables not present in 'vars' are silently expanded to the
    empty string.  The variable values in 'vars' should not contain further
    variable expansions; if 'vars' is the output of 'parse_makefile()',
    you're fine.  Returns a variable-expanded version of 's'.
    r   r   N)ra   rb   rc   ÚspanÚgetrO   )ÚsÚvarsrU   Zbegre   r   r   r   Úexpand_makefile_vars¯  s    *rt   c               	   C   sR   t j ddjtjttjddƒd¡} t| t	ƒ t
ƒ dgdƒ}|j}i at |¡ dS )	z7Initialize the module as appropriate for POSIX systems.Z_PYTHON_SYSCONFIGDATA_NAMEz _sysconfigdata_{abi}_{multiarch}rF   r   )ZabiZ	multiarchÚbuild_time_varsr   N)r   r-   rq   rG   r   ÚabiflagsÚgetattrrI   Ú
__import__ÚglobalsÚlocalsru   r=   rj   )r"   Z_tempru   r   r   r   Ú_init_posixÊ  s    þÿr{   c                  C   s~   i } t ddd| d< t ddd| d< tdd| d< t ¡ d | d< d	| d
< tƒ  dd¡| d< tj tj 	t
j¡¡| d< | adS )z+Initialize the module as appropriate for NTr   r   rE   ZLIBDESTZ
BINLIBDESTrC   Z	INCLUDEPYÚ
EXT_SUFFIXz.exeZEXEÚ.r   ZVERSIONZBINDIRN)r1   r+   Ú_impÚextension_suffixesr   rB   r   r   ÚdirnameÚabspathr   Ú
executabler=   )rS   r   r   r   Ú_init_ntÙ  s    rƒ   c                  G   s\  t dkr*tƒ  dtj ¡}|r(|ƒ  ni a tt d< tt d< t  d¡}|dk	rV|t d< t  dt¡}tjdkrœtrŽtj	 
tƒ ¡}tj	 ||¡}ntj	 
tƒ ¡}tj	 tj	 |¡¡t d< trtjdkrt}tj	 t d ¡s|t ¡ krtj	 |t d ¡}tj	 |¡t d< tjd	kr*d
dl}| t ¡ | rTg }| D ]}| t  |¡¡ q8|S t S dS )aß  With no arguments, return a dictionary of all configuration
    variables relevant for the current platform.  Generally this includes
    everything needed to build extensions and install both pure modules and
    extensions.  On Unix, this means every variable defined in Python's
    installed Makefile; on Windows it's a much smaller set.

    With arguments, return a list of values that result from looking up
    each argument in the configuration variable dictionary.
    NZ_init_r*   Úexec_prefixr|   ÚSOr   r   r2   r   )r=   ry   rq   r   r"   r   r,   r   r#   r   r€   rJ   r	   r   r%   ÚisabsÚgetcwdr   r:   r;   Zcustomize_config_varsÚappend)ÚargsÚfuncr…   r   Úbaser;   Zvalsr"   r   r   r   r>   ì  sB    



ÿ
r>   c                 C   s*   | dkrddl }| dtd¡ tƒ  | ¡S )z“Return the value of a single variable using the dictionary
    returned by 'get_config_vars()'.  Equivalent to
    get_config_vars().get(name)
    r…   r   Nz SO is deprecated, use EXT_SUFFIXr   )ÚwarningsÚwarnÚDeprecationWarningr>   rq   )r"   rŒ   r   r   r   r$   6  s    r$   )r   N)r   r   N)N)N)7Ú__doc__r~   r   rK   r   r@   r[   r   Úutilr   r   r   r%   r*   r   r„   r,   r/   r!   Úbase_exec_prefixr    r-   r   r   r‚   r€   r‡   r   rw   r   r"   r   r   r#   r&   rv   ÚAttributeErrorr   r+   r1   r<   rD   rJ   rX   rL   r^   ra   rc   ro   rt   r=   r{   rƒ   r>   r$   r   r   r   r   Ú<module>   s^   



+
.X




jJ