a oeI@sdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z dej vZ ejejZejejZejejZejejZdejvrejejdZn&ejrejejejZneZd d Zeed dZ d d Z!ej"dkre ddZ#e#eZe#e Z ddZ$e$Z%dZ&ze%s:ej'Z&Wne(yPYn0ddZ)d;ddZ*e ddZ+ddZ,ddZ-ddZ.d d!Z/d"d#Z0d$d%Z1dd3d4Z;d5d6Zd9d:Z?dS)?aProvide 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: N)DistutilsPlatformError) py39compat) pass_noneZ__pypy__Z_PYTHON_PROJECT_BASEcs&t|dtfdddDS)z] Return True if the target directory appears to point to an un-installed Python. ZModulesc3s|]}|VqdSN)joinpathis_file).0fnmodules@C:\Program Files\Certbot\pkgs\setuptools\_distutils\sysconfig.py 2z(_is_python_source_dir..)ZSetupz Setup.local)pathlibPathranydr r r_is_python_source_dir,sr_homecCstj|tj|S)z, Return True if a is a parent of b. )ospathnormcase startswith)Zdir_aZdir_br r r _is_parent8srntcs$ttf}fdd|D}t|S)Nc3s&|]}ttj|dr|VqdS)ZPCbuildN)rrrjoin)r prefixrr rrEsz_fix_pcbuild..)PREFIX BASE_PREFIXnext)rprefixesZmatchedr rr _fix_pcbuildAs  r$cCstr ttSttSr) _sys_homer project_baser r r r _python_buildPsr'cCsdtjddS)zReturn 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 rget_python_versionfsr,cCs`|rtnt}|dur|n|}ztdtj}Wn tyRtdtjYn0||||S)aReturn 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'. NZ_get_python_inc_zFI don't know where Python installs its C header files on platform '%s')BASE_EXEC_PREFIXr!globalsrnameKeyErrorr) plat_specificrdefault_prefixZresolved_prefixgetterr r rget_python_incns   r4cCstj|r|SdS)z5 Replace path with None if it doesn't exist. N)rrexists)rr r r_extantsr6cCs:trtjdkrtj|dSt|p8tt||p8t |S)Ninclude) IS_PYPYr*r+rrr_get_python_inc_posix_pythonr6_get_python_inc_from_config_get_python_inc_posix_prefixr spec_prefixr1r r r_get_python_inc_posixs rAcCs2tsdS|rtptStjtdd}tj|S)z Assume the executable is in the build directory. The pyconfig.h file should be in the same directory. Since the build directory may not be the source directory, use "srcdir" from the makefile to find the "Include" directory. NZsrcdirZInclude) python_buildr%r&rrrget_config_varnormpath)r1Zincdirr r rr<s r<cCs|durtd|dSdS)aj If no prefix was explicitly specified, provide the include directory from the config vars. Useful when cross-compiling, since the config vars may come from the host platform Python installation, while the current Python executable is from the build platform installation. >>> monkeypatch = getfixture('monkeypatch') >>> gpifc = _get_python_inc_from_config >>> monkeypatch.setitem(gpifc.__globals__, 'get_config_var', str.lower) >>> gpifc(False, '/usr/bin/') >>> gpifc(False, '') >>> gpifc(False, None) 'includepy' >>> gpifc(True, None) 'confincludepy' NZCONFZ INCLUDEPY)rC)r1r@r r rr=sr=cCs*trdnd}|tt}tj|d|S)Npypypythonr:)r;r, build_flagsrrr)rimplementationZ python_dirr r rr>s r>cCs6tr(tj|dtjjtj|dStj|dS)Nr:PC)rBrrrpathsepr?r r r_get_python_inc_nts  rKcCs|r|Stj|dSdS)N site-packages)rrr) standard_lib libpython early_prefixrr r r _posix_libsrPcCstrBtjdkrB|durt}|r4tj|dtjdStj|dS|}|durl|r`|rZtp\t }n |rht pjt}tj dkr|s~|rt tdd}nd}trd nd }tj|||t }t||||Stj d kr|rtj|d Stj|d dSntd tj dS)aSReturn 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'. r7Nz lib-pythonrrLposix platlibdirlibrErFrZLibz?I don't know where Python installs its library on platform '%s')r;r*r+r rrrversionr-r! EXEC_PREFIXr/getattrr,rPr)r1rMrrOlibdirrHrNr r rget_python_libs6    rXc Cs|jdkrtjdkr8tds8ddl}|tdtd<tddd d d d d d\}}}}}}}} dtj vrtj d} d tj vr| |r| |t |d}| }dtj vrtj d}d tj vrtj d }dtj vrtj d} n|d} dtj vr|dtj d}d tj vr2|dtj d }|dtj d }dtj vrt| dtj d} |dtj d}|dtj d}d tj vrtj d }dtj vr|dtj d} n |d| } |d|} |j | | | d||||| ddtj vr|j ddr|j tj dd||_dS)zDo 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. ZunixdarwinZCUSTOMIZED_OSX_COMPILERrNTrueZCCZCXXCFLAGSZCCSHAREDZLDSHAREDZ SHLIB_SUFFIXZARZARFLAGSZCPPz -ELDFLAGS CPPFLAGS)Z preprocessorcompilerZ compiler_soZ compiler_cxxZ linker_soZ linker_exearchiverZRANLIBranlib)ra)Z compiler_typer*platformrC _osx_supportcustomize_compiler _config_varsget_config_varsrenvironrlenZset_executablesZ executablesgetZshared_lib_extension)r_rcZccZcxxZcflagsZccsharedZldsharedZ shlib_suffixarZar_flagsZnewccZcppr`Zcc_cmdr r rrds                      rdcCsDtr8tjdkr"tjtptd}ntp(t}tj|dStSdS)z2Return full pathname of installed pyconfig.h file.rrIz pyconfig.hN) rBrr/rrr%r& sysconfigget_config_h_filename)Zinc_dirr r rrljs  rlcCstS)zAReturn full pathname of installed Makefile from the Python build.)rkget_makefile_filenamer r r rrmvsrmcCstj||dS)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. )vars)rkparse_config_h)fpgr r rro{sroz"([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 Csddlm}||ddddd}|dur*i}i}i}|}|durDqt|}|r2|dd\}} | } | dd } d | vr| ||<q2z t| } Wn"t y| dd ||<Yq20| ||<q2d } |rpt |D]} || } t | pt | }|rf|d}d }||vr"t||}n||vr2d }nx|tjvrJtj|}n`|| vr| drx| dd| vrxd }n$d||vrd }nt|d|}n d ||<}|rl| |d}| d|||} d |vr| || <nxz t| } Wn t y| || <Yn 0| || <|| =| drl| dd| vrl| dd} | |vrl| || <q|| =qq||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. r)TextFilersurrogateescape)Zstrip_commentsZ skip_blanksZ join_lineserrorsNr)z$$r($)r[r\r^TFZPY_r8)Zdistutils.text_filerrreadline _variable_rxmatchgroupstripreplaceint ValueErrorlist _findvar1_rxsearch _findvar2_rxstrrrgrendstartcloseitems isinstanceupdate)r rqrrrpZdoneZnotdonelinemnvZtmpvZrenamed_variablesr/valuefounditemZafterkr r rparse_makefiles                        rcCsVt|pt|}|rR|\}}|d|||d||d}qqRq|S)aExpand 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'. rrN)rrrspanriry)srnrZbegrr r rexpand_makefile_varss  *rcGs4tdurtatt|r0dd|DStS)aWith 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. NcSsg|]}t|qSr )reri)r r/r r r #rz#get_config_vars..)rerkrfcopyrZadd_ext_suffix)argsr r rrfs   rfcCs*|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) ZSOrNz SO is deprecated, use EXT_SUFFIXr))warningswarnDeprecationWarningrfri)r/rr r rrC&srC)rN)rrN)N)N)@__doc__rrer*rkrrtrr(r _functoolsrbuiltin_module_namesr;rrDrr exec_prefixrU base_prefixr!base_exec_prefixr-rgabspathr& executabledirnamegetcwdrrVr%rr/r$r'rBrGZabiflagsAttributeErrorr,r4r6rAr<r=r>rKrPrXrdrlrmrocompilerwrrrrrerfrCr r r rsr               6\     l