a DOgRa @sdZddlZddlZddlmZmZgdZdhZdddd d d d d dddddddd d ddddddddd dddddddddddddd d!ddd"d"d#d#d$d!ddd%ZdZ ej dZ d&ej dd'Zd(ej dd'ZejejZejejZejejZejejZdadZd)d*ZejrDejeejZn ee Zej!d+kre"#d,reej$eeeZd-ej%vreej%d-Zd.d/Z&e'ed0dZ(ej!d+krd1d2Z)e)eZe)e(Z(dkd4d5Z*e*d6Z+e+rd7D]Z,d8ee,d9<d:ee,d;<qdd?Z.d@dAZ/dBdCZ0dDdEZ1dldFdGZ2dHdIZ3dJdKZ4dLdMZ5dNdOZ6dPdQZ7dmdRdSZ8dTdUZ9dVdWZ:dXdYZ;e0dd6fdZd[Zd`daZ?dbdcZ@dddeZAdfdgZBdhdiZCeDdjkreCdS)nz-Access to Python's configuration information.N)pardirrealpath) get_config_h_filenameget_config_varget_config_varsget_makefile_filenameget_pathget_path_names get_paths get_platformget_python_versionget_scheme_namesparse_config_hZMACOSX_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 platstdlibpurelibplatlibinclude platincludescriptsdataz{installed_base}/lib/pythonz{base}/lib/pythonz{installed_base}/include/pythonz{installed_base}/Libz {base}/Libz{base}/Lib/site-packagesz{installed_base}/Includez{base}/Scriptsz#{userbase}/Python{py_version_nodot}z1{userbase}/Python{py_version_nodot}/site-packagesz+{userbase}/Python{py_version_nodot}/Includez+{userbase}/Python{py_version_nodot}/Scriptsz {userbase})rrrrrrrz0{userbase}/{platlibdir}/python{py_version_short}z5{userbase}/lib/python{py_version_short}/site-packagesz>{userbase}/{platlibdir}/python{py_version_short}/site-packagesz+{userbase}/include/python{py_version_short}z{userbase}/binz{userbase}/lib/pythonz#{userbase}/lib/python/site-packagesz{userbase}/include) posix_prefix posix_homentZnt_userZ posix_userZosx_framework_user%d.%dz%d%dcCs&z t|WSty |YS0dSN)rOSError)pathr./opt/alt/python39/lib64/python3.9/sysconfig.py_safe_realpathgs  r!r)z\pcbuild\win32z\pcbuild\amd64Z_PYTHON_PROJECT_BASEcCs,dD]"}tjtj|d|rdSqdS)N)ZSetupz Setup.localZModulesTF)osrisfilejoin)dfnrrr _is_python_source_dir|sr'_homecCs0|r,tj|tjtjtdr,tS|S)NZPCbuild)r"rnormcase startswithr$_PREFIX)r%rrr _fix_pcbuilds r,FcCs|rtrttSttSr) _sys_homer' _PROJECT_BASE)Z check_homerrr is_python_buildsr/T)rrz{srcdir}/Includerz{projectbase}/.rc Csvz|jfi|WStypz|jfitjWYStyj}ztd|dWYd}~n d}~00Yn0dS)Nz{%s})formatKeyErrorr"environAttributeError)sZ local_varsvarrrr _subst_varss r6cCs0|}|D]\}}||vr"q|||<qdSr)keysitems)Z target_dictZ other_dictZ target_keyskeyvaluerrr _extend_dicts r;cCsbi}|duri}t|tt|D]4\}}tjdvrFtj|}tjt ||||<q(|S)N)posixr) r;r_INSTALL_SCHEMESr8r"namer expandusernormpathr6)schemevarsresr9r:rrr _expand_varss   rDcCstjdkrdStjS)Nr<r)r"r>rrrr _get_default_schemes rEcCsztjdd}|r|Sdd}tjdkrBtjdp6d}||dStjdkrptjrp|dd tjd tjdd S|dd S) NPYTHONUSERBASEcWstjtjj|Sr)r"rr?r$)argsrrr joinusersz_getuserbase..joinuserrAPPDATA~PythondarwinLibraryrrz.local)r"r2getr>sysplatform _framework version_info)env_baserHbaserrr _getuserbases   rUc Csrddl}|d}|d}|d}|dur2i}i}i}t|dd}|} Wdn1sd0Y| D]} | dsr| d krqr|| } | rr| d d \} } | } | d d }d |vr| || <qrz| t vrt t | } Wn$t y| d d || <Yqr0| || <qrt | }d}t|dkr8t|D]}||}||}||}|r|r||kr|n|} n|r|n|} | dur| d } d}| |vrt|| }n| |vrd}nx| tjvrtj| }n`| |vrD|dr|dd|vrd }n$d| |vr2d}nt|d| }n d || <}|r0|| d}|d| ||}d |vr|||<nz|t vrt t |}Wn t y|||<Yn 0|||<|||dr0|dd|vr0|dd}||vr0|||<n|||<||q@q*|D]"\}} t| tr@| ||<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. rNz"([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_]*)}surrogateescape)errors#rz$$$)ZCFLAGSZLDFLAGSZCPPFLAGSTFZPY_)recompileopen readlinesr*stripmatchgroupreplace _ALWAYS_STR ValueErrorintlistr7lentuplesearchstartstrr"r2endremover8 isinstanceupdate)filenamerBr]Z _variable_rxZ _findvar1_rxZ _findvar2_rxZdoneZnotdoneflineslinemnvZtmpvZ variablesZrenamed_variablesr>r:Zm1Zm2founditemZafterkrrr _parse_makefiles    &                             r|cCsdtrtjtptdSttdr0dttj f}nd}ttj drP|dtj j 7}tjt d|dS)z Return the path of the Makefile.ZMakefileabiflagsz config-%s%sZconfig _multiarchz-%sr) _PYTHON_BUILDr"rr$r-r.hasattrrO_PY_VERSION_SHORTr}implementationr~r)Zconfig_dir_namerrr rUs  rc Cs(tjddjtjtjttjdddS)NZ_PYTHON_SYSCONFIGDATA_NAMEz+_sysconfigdata_{abi}_{platform}_{multiarch}r~rY)ZabirPZ multiarch) r"r2rNr0rOr}rPgetattrrrrrr _get_sysconfigdata_namebs rc Csddl}i}t}zt||WnLtyl}z4d|}t|drP|d|j}t|WYd}~n d}~00t}z6t|}t||Wdn1s0YWnLty}z4d|}t|dr|d|j}t|WYd}~n d}~00t r |d|d<t }dt j vr>ddl }||} || _| t j|<d ttf} tt d r`| d 7} tj| d d tj| |d} t| ddd2}|d|d|j||dWdn1s0Ytdddd}|| Wdn1s0YdS)z;Generate the Python module containing build-time variables.rNz.invalid Python installation: unable to open %sstrerrorz (%s)ZLDSHAREDZ BLDSHAREDrLzbuild/lib.%s-%sZgettotalrefcountz-pydebugT)exist_okz.pywutf8)encodingzB# system configuration generated and used by the sysconfig module zbuild_time_vars = )streamzpybuilddir.txt)pprintrr|rrrrr_rrrrOrPtypes ModuleTypebuild_time_varsmodulesr rr"makedirsrr$write) rrBZmakefileemsgZconfig_hrsr>rmoduleZ pybuilddirZdestfilerrr _generate_posix_varsksL  ,        .rcCs0t}t|ttdgd}|j}||dS)z7Initialize the module as appropriate for POSIX systems.rrN)r __import__globalslocalsrrq)rBr>Z_temprrrr _init_posixsrcCsfddl}td|d<td|d<td|d<|d|d <d |d <t|d <tjttj |d <dS)z+Initialize the module as appropriate for NTrNrZLIBDESTrZ BINLIBDESTrZ INCLUDEPY EXT_SUFFIXz.exeZEXEZVERSIONZBINDIR) _imprextension_suffixes_PY_VERSION_SHORT_NO_DOTr"rdirnamer!rO executable)rBrrrr _init_non_posixs   rc Cs|dur i}ddl}|d}|d}|}|s6q||}|r|dd\}}z|tvrbtt|}Wnty~Yn0|||<q(||}|r(d||d<q(|S)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. Nrz"#define ([A-Z][A-Za-z0-9_]+) (.*) z&/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/ rZr)r]r^readlinerbrcrerfrg) fprBr]Z define_rxZundef_rxrurvrwrxrrr rs,       rcCsBtr,tjdkr"tjtptd}q4tp(t}ntd}tj|dS)zReturn the path of pyconfig.h.rZPCrz pyconfig.h)rr"r>rr$r-r.r)Zinc_dirrrr rs   rcCs tttS)z,Return a tuple containing the schemes names.)rjsortedr=rrrr r sr cCstS)z*Return a tuple containing the paths names.) _SCHEME_KEYSrrrr r sr cCs|rt||St|SdS)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. N)rDr=)rArBexpandrrr r s r cCst||||S)z[Return a path corresponding to the scheme. ``scheme`` is the install scheme name. )r )r>rArBrrrr rsrcGstdurViattd<ttd<ttd<ttd<ttd<ttd<ttd<ttd <ttd <ttd <t j td <zt j td <Wnt ydtd <Yn0t jdkrttdtd<t jdkrtttd}|dur|td<ttd<tdt}t jdkr,trt jt}t j||}nt jt}t|td<t jdkrVddl}|t|rg}|D]}|t|qd|StSdS)anWith 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. Nprefix exec_prefixZ py_versionZpy_version_shortZpy_version_nodotZinstalled_baserTZinstalled_platbaseZplatbaseZ projectbase platlibdirr}rYrZTZPATHr<rSOuserbasesrcdirrLr) _CONFIG_VARSr+ _EXEC_PREFIX _PY_VERSIONrr _BASE_PREFIX_BASE_EXEC_PREFIXr.rOrr}r3r"r>rrrNrUrrrrr$r!rP _osx_supportZcustomize_config_varsappend)rGrrrTrZvalsr>rrr rsT            rcCs*|dkrddl}|dtdt|S)zReturn the value of a single variable using the dictionary returned by 'get_config_vars()'. Equivalent to get_config_vars().get(name) rrNz SO is deprecated, use EXT_SUFFIXr)warningswarnDeprecationWarningrrN)r>rrrr r^src CstjdkrFdtjvrdSdtjvr.dSdtjvr@dStjStjdksZttd s`tjSd tjvrttjd St\}}}}}| d d }| d d}| d d}|dddkrd||fS|dddkr,|ddkrd}dt |dd|ddf}ddd}|d|tj 7}n|dddkrPdd l m }|S|dd!d"krd"}ddl}|d#}||} | r| }n2|dd!d$krddl} | t|||\}}}d%|||fS)&aReturn 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'. rZamd64z win-amd64z(arm)z win-arm32z(arm64)z win-arm64r<unameZ_PYTHON_HOST_PLATFORM/rY _-NZlinuxz%s-%sZsunosr5Zsolarisz%d.%sr\rZ32bitZ64bit)ilz.%sZaix) aix_platformcygwinz[\d.]+rLz%s-%s-%s)r"r>rOversionlowerrPrr2rrdrgmaxsizeZ _aix_supportrr]r^rbrcrZget_platform_osxr) ZosnameZhostreleasermachineZbitnessrr]Zrel_rervrrrr r jsR             r cCstSr)rrrrr r sr cCsFtt|D]0\}\}}|dkr0td|td||fqdS)Nrz%s: z %s = "%s") enumeraterr8print)titlerindexr9r:rrr _print_dicts rcCsfdtjvrtdStdttdttdtttdtttdt dS)z*Display all information sysconfig detains.z--generate-posix-varsNzPlatform: "%s"zPython version: "%s"z!Current installation scheme: "%s"ZPathsZ Variables) rOargvrrr r rErr rrrrr _mains  r__main__)F)N)N)E__doc__r"rOZos.pathrr__all__rer=rrsplitrrRrrrr@rr+ base_prefixrrrbase_exec_prefixrrZ _USER_BASEr!rrr.getcwdr>rendswithr$r2r'rr-r,r/rrAr6r;rDrErUr|rrrrrrrr r r rrrr r rr__name__rrrr s     ?              ? "  O Q