o
    fr                     @   sl  d Z ddlZddlZddlmZmZ g dZdhZdddd	d
ddddddddd
ddddddddd
dddddddddddddddddddddddZd d! Z	e	 duZ
e
ryed"d"d#d#d$d%d&d'd(d(d)d)d*d+d&d'd,d,d-d-d*d+d&d'd.O Zd'Zej d Zejd  d/ejd0  Zejd  ejd0  ZejejZejejZejejZejejZdadZd1Zd2Zd3Z d4d5 Z!ej"rej#e!ej"Z$ne!e% Z$ej&d6kre$' (d7re!ej)e$eeZ$d8ej*v re!ej*d8 Z$d9d: Z+e,ed;dZ-ej&d6krd<d= Z.e.e$Z$e.e-Z-d{d?d@Z/e/dAZ0e0r:dBD ]Z1ee1 Z1e1dC e1dD< dEe1dC< dFe1dG< q$dHdI Z2dJdK Z3dLdM Z4dNdO Z5dPdQ Z6dRdS Z7d|dTdUZ8dVdW Z9dXdY Z:dZd[ Z;d\d] Z<d^d_ Z=d}d`daZ>dbdc Z?ddde Z@dfdg ZAe7 ddAfdhdiZBe7 ddAfdjdkZCdldm ZDdndo ZEdpdq ZFdrds ZGdtdu ZHdvdw ZIdxdy ZJeKdzkreJ  dS dS )~z-Access to Python's configuration information.    N)pardirrealpath)get_config_h_filenameget_config_varget_config_varsget_makefile_filenameget_pathget_path_names	get_pathsget_platformget_python_versionget_scheme_namesparse_config_hMACOSX_DEPLOYMENT_TARGETz6{installed_base}/{platlibdir}/python{py_version_short}z0{platbase}/{platlibdir}/python{py_version_short}z1{base}/lib/python{py_version_short}/site-packagesz>{platbase}/{platlibdir}/python{py_version_short}/site-packagesz;{installed_base}/include/python{py_version_short}{abiflags}z?{installed_platbase}/include/python{py_version_short}{abiflags}z
{base}/binz{base})stdlib
platstdlibpurelibplatlibincludeplatincludescriptsdataz-{installed_base}/lib/python{py_version_short}z'{platbase}/lib/python{py_version_short}z {base}/lib/python3/dist-packagesz${platbase}/lib/python3/dist-packagesz7{base}/local/lib/python{py_version_short}/dist-packagesz;{platbase}/local/lib/python{py_version_short}/dist-packagesz{base}/local/binz{base}/localz{installed_base}/lib/pythonz{base}/lib/pythonz{installed_base}/include/pythonz{installed_base}/Libz
{base}/Libz{base}/Lib/site-packagesz{installed_base}/Includez{base}/Scripts)posix_prefix
deb_systemposix_local
posix_homentc                  C   s   t jdd } | r| S tjdkrd S dd }t jdkr(t jdp"d}||dS tjd	krCtjrC|dd
tjtjd  dtjd  S |ddS )NPYTHONUSERBASEvxworksc                  W   s   t jt jj|  S N)ospath
expanduserjoin)args r%    /usr/lib/python3.10/sysconfig.pyjoinusera   s   z_getuserbase.<locals>.joinuserr   APPDATA~PythondarwinLibraryr   .   z.local)r    environgetsysplatformname
_frameworkversion_info)env_baser'   baser%   r%   r&   _getuserbaseX   s   




r8   z({userbase}/Python{py_version_nodot_plat}z6{userbase}/Python{py_version_nodot_plat}/site-packagesz0{userbase}/Python{py_version_nodot_plat}/Includez0{userbase}/Python{py_version_nodot_plat}/Scriptsz
{userbase})r   r   r   r   r   r   r   z0{userbase}/{platlibdir}/python{py_version_short}z5{userbase}/lib/python{py_version_short}/site-packagesz+{userbase}/include/python{py_version_short}z{userbase}/binz{userbase}/lib/pythonz#{userbase}/lib/python/site-packages)nt_user
posix_userosx_framework_userr-   r.   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"   zt | W S  ty   |  Y S w r   )r   OSError)r!   r%   r%   r&   _safe_realpath   s
   
r=   r   )z\pcbuild\win32z\pcbuild\amd64_PYTHON_PROJECT_BASEc                 C   s,   dD ]}t jt j| d|r dS qdS )N)SetupzSetup.localModulesTF)r    r!   isfiler#   )dfnr%   r%   r&   _is_python_source_dir   s
   rD   _homec                 C   s0   | rt j| t jt jtdrtS | S )NPCbuild)r    r!   normcase
startswithr#   _PREFIX)rB   r%   r%   r&   _fix_pcbuild   s
   rJ   Fc                 C   s   | rt rtt S ttS r   )	_sys_homerD   _PROJECT_BASE)
check_homer%   r%   r&   is_python_build   s   rN   T)r   r   r   r   r   headersz{srcdir}/Includez{projectbase}/.r   c                 C   sh   z	| j di |W S  ty3 } zz| j di tjW W  Y d }~S  ty.   t| d w d }~ww )Nr%   )formatKeyErrorr    r/   AttributeError)s
local_varsvarr%   r%   r&   _subst_vars   s    rV   c                 C   s0   |   }| D ]\}}||v rq|| |< qd S r   )keysitems)target_dict
other_dicttarget_keyskeyvaluer%   r%   r&   _extend_dict   s   
r^   c                 C   sb   i }|d u ri }t |t  t|   D ]\}}tjdv r#tj|}tjt	||||< q|S )N)posixr   )
r^   r   _INSTALL_SCHEMESrX   r    r3   r!   r"   normpathrV   )schemevarsresr\   r]   r%   r%   r&   _expand_vars   s   
re   c                  C   sz   t jdkrddddS tjdkrtjrddddS tjtjks$ttdr'd} nt j	d	d
}|dv r5d} nd
} | dddS )Nr   r   r9   )prefixhomeuserr+   r   r;   real_prefixDEB_PYTHON_INSTALL_LAYOUTr   )debr   r   r:   )
r    r3   r1   r2   r4   base_prefixrf   hasattrr/   r0   )prefix_scheme	deb_buildr%   r%   r&   _get_preferred_schemes   s(   
rp   c                 C   s*   t  |  }|tvrt| d|d|S )Nz
 returned z., which is not a valid scheme on this platform)rp   r`   
ValueError)r\   rb   r%   r%   r&   get_preferred_scheme  s   
rr   c                   C   s   t dS )Nrf   )rr   r%   r%   r%   r&   get_default_scheme%  s   rs   c              	   C   sV  ddl }|du r
i }i }i }t| t dd}| }W d   n1 s&w   Y  |D ]S}|ds:| dkr;q-|t|}	|	r|		dd\}
}| }|
d	d}d
|v r^|||
< q-z|
tv rett|}W n ty{   |
d	d
||
< Y q-w |||
< q-t| }d}t|dkrt|D ]}|| }|t|}|t|}|r|r| | k r|n|}	n|r|n|}	|	dur{|		d}
d}|
|v rt||
 }n@|
|v rd}n9|
tjv rtj|
 }n.|
|v r|dr|dd |v rd}nd|
 |v rd}nt|d|
  }nd ||
< }|rz||	 d }|d|	  | | }d
|v r5|||< qz|tv r=tt|}W n tyR   | ||< Y nw |||< || |drz|dd |v rz|dd }||vrz|||< q|r|||< || qt|dks| D ]\}}t|tr| ||< q|| |S )zParse 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   Nsurrogateescape)encodingerrors# r.      z$$$)CFLAGSLDFLAGSCPPFLAGSTFPY_   )reopenr1   getfilesystemencoding	readlinesrH   stripmatch_variable_rxgroupreplace_ALWAYS_STRrq   intlistrW   lentuplesearch_findvar1_rx_findvar2_rxstartstrr    r/   endremoverX   
isinstanceupdate)filenamerc   keep_unresolvedr   donenotdoneflineslinemnvtmpv	variablesrenamed_variablesr3   r]   m1m2founditemafterkr%   r%   r&   _parse_makefile)  s   












D
r   c                  C   sh   t rtjtptdS ttdrdt tj	 } nd} ttj
dr*| dtj
j 7 } tjtd| dS )z Return the path of the Makefile.Makefileabiflagszconfig-config
_multiarch-r   )_PYTHON_BUILDr    r!   r#   rK   rL   rm   r1   _PY_VERSION_SHORTr   implementationr   r   )config_dir_namer%   r%   r&   r     s   
r   c                  C   s*   t tjdd} tjddtj d|  S )Nr   rx   _PYTHON_SYSCONFIGDATA_NAME_sysconfigdata__)getattrr1   r   r    r/   r0   r   )	multiarchr%   r%   r&   _get_sysconfigdata_name  s
   r   c               
   C   s  ddl } i }t }zt|| W n# ty3 } zd| }t|dr+| d|j d}t|d}~ww t }zt|dd}t|| W d   n1 sNw   Y  W n# tyw } zd| }t|dro| d|j d}t|d}~ww t	r|d	 |d
< t
 }dtjv rddl}||}	||	_|	tj|< dt  dt }
ttdr|
d7 }
tj|
dd tj|
|d }t|ddd}|d |d | j ||d W d   n1 sw   Y  tdddd}||
 W d   dS 1 sw   Y  dS )z;Generate the Python module containing build-time variables.r   Nz,invalid Python installation: unable to open strerrorz ()zutf-8)ru   LDSHARED	BLDSHAREDr+   z
build/lib.r   gettotalrefcountz-pydebugT)exist_okz.pywutf8zB# system configuration generated and used by the sysconfig module
zbuild_time_vars = )streamzpybuilddir.txt)pprintr   r   r<   rm   r   r   r   r   r   r   r1   r2   types
ModuleTypebuild_time_varsmodulesr   r   r    makedirsr!   r#   write)r   rc   makefileemsgconfig_hr   r3   r   module
pybuilddirdestfiler%   r%   r&   _generate_posix_vars  s\   









"r   c                 C   s0   t  }t|t t dgd}|j}| | dS )z7Initialize the module as appropriate for POSIX systems.r   r   N)r   
__import__globalslocalsr   r   )rc   r3   _tempr   r%   r%   r&   _init_posix  s   r   c                 C   sn   ddl }td| d< td| d< td| d< | d | d	< d
| d< t| d< tjttj	| d< d| d< dS )z+Initialize the module as appropriate for NTr   Nr   LIBDESTr   
BINLIBDESTr   	INCLUDEPY
EXT_SUFFIXz.exeEXEVERSIONBINDIRrx   TZPATH)
_impr   extension_suffixes_PY_VERSION_SHORT_NO_DOTr    r!   dirnamer=   r1   
executable)rc   r   r%   r%   r&   _init_non_posix  s   r   c           	      C   s   |du ri }ddl }|d}|d}	 |  }|s	 |S ||}|rH|dd\}}z|tv r4tt|}W n	 tyB   Y nw |||< n||}|rVd||d< q)zParse 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.
    Nr   z"#define ([A-Z][A-Za-z0-9_]+) (.*)
z&/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/
Tr.   ry   )r   compilereadliner   r   r   rq   r   )	fprc   r   	define_rxundef_rxr   r   r   r   r%   r%   r&   r     s2   




r   c                  C   sD   t rtjdkrtjtptd} n
tpt} ntdd} tj| dS )zReturn the path of pyconfig.h.r   PCr   r   z
pyconfig.h)r   r    r3   r!   r#   rK   rL   r   )inc_dirr%   r%   r&   r   9  s   


r   c                   C   s   t ttS )z,Return a tuple containing the schemes names.)r   sortedr`   r%   r%   r%   r&   r   E  s   r   c                   C      t S )z*Return a tuple containing the paths names.)_SCHEME_KEYSr%   r%   r%   r&   r	   J  s   r	   c                 C   s   |rt | |S t|  S )zReturn a mapping containing an install scheme.

    ``scheme`` is the install scheme name. If not provided, it will
    return the default scheme for the current platform.
    )re   r`   )rb   rc   expandr%   r%   r&   r
   O  s   
r
   c                 C   s   t ||||  S )z[Return a path corresponding to the scheme.

    ``scheme`` is the install scheme name.
    )r
   )r3   rb   rc   r   r%   r%   r&   r   [  s   r   c                  G   s  t du ri a tt d< tt d< tt d< tt d< tt d< tt d< tt d< tt d	< tt d
< tt d< t	j
t d< zt	jt d< W n tyG   dt d< Y nw zt	jddt d< W n ty`   dt d< Y nw tjdkrjtt  tjdkrstt  t d}|dur|t d< trt t d< td}|rd| t d< ndt d< t dt}tjdkrtrtjt }tj||}ntjt }t|t d< t	jdkrddl}|t  | rg }| D ]
}| t | q|S t S )an  With no arguments, return a dictionary of all configuration
    variables relevant for the current platform.

    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.
    Nrf   exec_prefix
py_versionpy_version_shortpy_version_nodotinstalled_baser7   installed_platbaseplatbaseprojectbase
platlibdirr   rx   r-   py_version_nodot_platr   r_   r   SOuserbase	MULTIARCH/multiarchsubdirsrcdirr+   r   )!_CONFIG_VARSrI   _EXEC_PREFIX_PY_VERSIONr   r   _BASE_PREFIX_BASE_EXEC_PREFIXrL   r1   r   r   rR   winverr   r    r3   r   r   r0   _HAS_USER_BASEr8   r   r   r!   r   r   r#   r=   r2   _osx_supportcustomize_config_varsappend)r$   r   r   r   r7   r  valsr3   r%   r%   r&   r   c  sh   







r   c                 C   s*   | dkrddl }|dtd t | S )zReturn 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_SUFFIXry   )warningswarnDeprecationWarningr   r0   )r3   r  r%   r%   r&   r     s   r   c                  C   s  t jdkr#dtj v rdS dtj v rdS dtj v r dS tjS t jdks-tt d	s0tjS d
t jv r:t jd
 S t  \} }}}}|  	dd} |	dd}|	dd}| dd dkrf|  d| S | dd dkr|d dkrd} t
|d d  d|dd  }ddd}|d|tj  7 }nH| dd dkrddlm} | S | dd d krd } ddl}|d!}||}	|	r|	 }n| dd d"krddl}
|
t | ||\} }}|  d| d| S )#a  Return a string that identifies the current platform.

    This is used mainly to distinguish platform-specific build directories and
    platform-specific built distributions.  Typically includes the OS name and
    version and the architecture (as supplied by 'os.uname()'), although the
    exact information included depends on the OS; on Linux, the kernel version
    isn't particularly important.

    Examples of returned values:
       linux-i586
       linux-alpha (?)
       solaris-2.6-sun4u

    Windows will return one of:
       win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
       win32 (all others - specifically, sys.platform is returned)

    For other non-POSIX platforms, currently just returns 'sys.platform'.

    r   amd64z	win-amd64z(arm)z	win-arm32z(arm64)z	win-arm64r_   uname_PYTHON_HOST_PLATFORMr   rx    r   r   N   linuxsunosr   5solarisr   r-   ry   32bit64bit)il    aix)aix_platform   cygwinz[\d.]+r+   )r    r3   r1   versionlowerr2   rm   r/   r  r   r   maxsize_aix_supportr  r   r   r   r   r  get_platform_osxr   )osnamehostreleaser  machinebitnessr  r   rel_rer   r  r%   r%   r&   r     sV   


"



r   c                   C   r   r   )r   r%   r%   r%   r&   r     s   r   c                 C   sd   ddl }	 |t| p|t| }|r.| \}}| d| ||d | |d  } n	 | S q)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   NTr.   )r   r   r   r   spanr0   r   )rS   rc   r   r   begr   r%   r%   r&   expand_makefile_vars  s   *r*  c                 C   sN   t t| D ]\}\}}|dkrt|  d td| d| d qd S )Nr   z: 	z = "")	enumerater   rX   print)titler   indexr\   r]   r%   r%   r&   _print_dict7  s
   r1  c                   C   sr   dt jv r
t  dS tdt  d tdt  d tdt  d t  tdt  t  tdt	  dS )	z*Display all information sysconfig detains.z--generate-posix-varsNzPlatform: "r,  zPython version: "zCurrent installation scheme: "Paths	Variables)
r1   argvr   r.  r   r   rs   r1  r
   r   r%   r%   r%   r&   _main>  s   
r5  __main__)F)NTr   )L__doc__r    r1   os.pathr   r   __all__r   r`   r8   r  r   r  splitr  r5   r   r   r!   ra   rf   rI   rl   r  r   r  base_exec_prefixr  r   
_USER_BASEr   r   r   r=   r   r   rL   getcwdr3   r  endswithr#   r/   rD   r   rK   rJ   rN   r   rb   rV   r^   re   rp   rr   rs   r   r   r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r*  r1  r5  __name__r%   r%   r%   r&   <module>   s(   >





	 

 ?
"YQ

