3 υ_Ki@sdZddlZddlZddlZddlZddlmZmZy ddlZWne k r\ddl ZYnXdddddd d d d d dg Z ddZ ej rejje ej Zn e ejZejdkrdedEdjkre ejjeeZejdkodedFdjkr e ejjeeeZejdkr@dedGdjkr@e ejjeeeZddZeZdaddZejZejdZddZejjdZ ejdd Z!e de d!Z"ejj#ej$Z%ejj#ej&Z'da(dZ)d"d#Z*d$d%Z+d&d'Z,d(d)Z-d*d+Z.d,d-Z/dHd.d/Z0d0dZ1d1d2Z2d3d4Z3dId5dZ4d6dZ5d7d Z6d8d Z7e.dd9fd:d Z8e.dd9fd;dZ9dd ZdBdCZ?e@dDkre?dS)Jz-Access to Python's configuration information.N)pardirrealpathget_config_h_filenameget_config_varget_config_varsget_makefile_filenameget_pathget_path_names get_paths get_platformget_python_versionget_scheme_namesparse_config_hc Cs"yt|Stk r|SXdS)N)rOSError)pathr/usr/lib/python3.6/sysconfig.py_safe_realpath"srntZpcbuildz\pc\v z\pcbuild\amd64cCs.x(dD] }tjjtjjtd|rdSqWdS)N Setup.dist Setup.localModulesTF)rr)osrisfilejoin _PROJECT_BASE)fnrrris_python_build:s r Fc Cstsddlm}tjddd}||}|jd}|s>td|j}tj |WdQRXt rx(dD] }tj |d d tj |d d qfWdadS)N)finder.rz sysconfig.cfgzsysconfig.cfg exists posix_prefix posix_homeincludez{srcdir}/Include platincludez{projectbase}/.T)r%r&) _cfg_readZ resourcesr"__name__rsplitfindAssertionErrorZ as_stream_SCHEMESZreadfp _PYTHON_BUILDset)r"Zbackport_packageZ_finderZ_cfgfilesschemerrr_ensure_cfg_readDs     r3z \{([^{]*?)\}cst|jdr|jd}nt}|j}xD|D]<}|dkr>q0x,|D]$\}}|j||rZqD|j|||qDWq0W|jdxX|jD]L}t|j|fdd}x,|j|D]\}}|j||t j ||qWqWdS)Nglobalscs$|jd}|kr|S|jdS)Nr$r)group)matchobjname) variablesrr _replaceros z"_expand_globals.._replacer) r3Z has_sectionitemstuplesectionsZ has_optionr0Zremove_sectiondict _VAR_REPLsub)configr4r<ZsectionZoptionvaluer9r)r8r_expand_globalsYs$      rBr!csfdd}tj||S)zIn the string `path`, replace tokens like {some.thing} with the corresponding value from the map `local_vars`. If there is no corresponding value, leave the token unchanged. cs8|jd}|kr|S|tjkr.tj|S|jdS)Nr$r)r5renviron)r6r7) local_varsrrr9s    z_subst_vars.._replacer)r>r?)rrEr9r)rEr _subst_varss rFcCs4|j}x&|jD]\}}||kr$q|||<qWdS)N)keysr:) target_dict other_dict target_keyskeyrArrr _extend_dicts rLcCsdi}|dkri}t|txBtj|D]4\}}tjdkrFtjj|}tjjt ||||<q(W|S)Nposixr)rMr) rLrr.r:rr7r expandusernormpathrF)r2varsresrKrArrr _expand_varss   rRcsfdd}tj||S)Ncs$|jd}|kr|S|jdS)Nr$r)r5)r6r7)rPrrr9s zformat_value.._replacer)r>r?)rArPr9r)rPr format_values rScCstjdkrdStjS)NrMr%)rr7rrrr_get_default_schemes rTcCstjjdd}dd}tjdkrBtjjdp.d}|r8|S||dStjdkr|td }|r||r`|S|dd |d tjdd S|r|S|dd SdS)NPYTHONUSERBASEcWstjjtjj|S)N)rrrNr)argsrrrjoinusersz_getuserbase..joinuserrAPPDATA~PythondarwinPYTHONFRAMEWORKLibraryz%d.%dr!z.local)rrDgetr7sysplatformr version_info)env_baserWbase frameworkrrr _getuserbases"    recCs"tjd}tjd}tjd}|dkr*i}i}i}tj|ddd}|j}WdQRXx|D]} | jds\| jd krxq\|j| } | r\| jd d \} } | j} | j d d } d | kr| || <q\y t | } Wn$t k r| j d d || <Yq\X| || <q\Wt |j }d}xt|dkrxt|D]}||}|j|pJ|j|} | dk r| jd } d}| |kr|t|| }n| |krd}nx| tjkrtj| }n`| |kr|jdr|dd|krd }n$d| |krd}nt|d| }n d || <}|r|| jd}|d| j||}d |krF|||<n~y t |}Wn"t k rt|j||<Yn X|||<|j||jdr|dd|kr|dd}||kr|||<n|||<|j|q(WqWx.|jD]"\}} t| tr| j||<qW|j||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. 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_]*)}Nzutf-8surrogateescape)encodingerrors#r$r!z$$$CFLAGSLDFLAGSCPPFLAGSrTFPY_rC)rlrmrn)recompilecodecsopen readlines startswithstripmatchr5replaceint ValueErrorlistrGlenr;searchstrrrDendstartremover: isinstanceupdate)filenamerP _variable_rx _findvar1_rx _findvar2_rxdonenotdoneflineslinemnvtmpvr8renamed_variablesr7rAfounditemafterkrrr_parse_makefiles                             rcCsDtrtjjtdSttdr,dttjf}nd}tjjt d|dS)z Return the path of the Makefile.Makefileabiflagsz config-%s%sr@stdlib) r/rrrrhasattrr__PY_VERSION_SHORTrr)config_dir_namerrrrMs  cCst}yt||WnJtk r^}z.d|}t|drF|d|j}t|WYdd}~XnXt}y"t|}t||WdQRXWnJtk r}z.d|}t|dr|d|j}t|WYdd}~XnXtr|d|d<dS)z7Initialize the module as appropriate for POSIX systems.z.invalid Python installation: unable to open %sstrerrorz (%s)N BLDSHAREDLDSHARED) rrIOErrorrrrrsrr/)rPmakefileemsgconfig_hrrrr _init_posixXs&   rcCsVtd|d<td|d<td|d<d|d<d |d <t|d <tjjttj|d <d S)z+Initialize the module as appropriate for NTrLIBDEST platstdlib BINLIBDESTr' INCLUDEPYz.pydSOz.exeEXEVERSIONBINDIRN)r_PY_VERSION_SHORT_NO_DOTrrdirnamerr_ executable)rPrrr_init_non_posixts   rc Cs|dkr i}tjd}tjd}xx|j}|s0P|j|}|rz|jdd\}}y t|}Wntk rnYnX|||<q"|j|}|r"d||jd<q"W|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. Nz"#define ([A-Z][A-Za-z0-9_]+) (.*) z&/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/ r$r!r)rprqreadlinerwr5ryrz)fprP define_rxundef_rxrrrrrrrrs(      cCs:tr$tjdkrtjjtd}q,t}ntd}tjj|dS)zReturn the path of pyconfig.h.rPCr(z pyconfig.h)r/rr7rrrr)inc_dirrrrrs  cCstttjS)z,Return a tuple containing the schemes names.)r;sortedr.r<rrrrr scCs tjdS)z*Return a tuple containing the paths names.r%)r.Zoptionsrrrrr sTcCs&t|rt||Sttj|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)r3rRr=r.r:)r2rPexpandrrrr s cCst||||S)z[Return a path corresponding to the scheme. ``scheme`` is the install scheme name. )r )r7r2rPrrrrrscGstdkriattd<ttd<ttd<ttd<tdtdtd<ttd <ttd <ttd <ytjtd <Wntk rd td <YnXt j d#krt tt j dkrt ttj dkrttd<dtkrttd<nttdtd<tot j dkr\t}y t j}Wntk rd}YnXt jjtd r\||kr\t jj|td}t jj|td<tjdkrt jd}t|jdd}|dkrx:d$D]2}t|}tjdd|}tjdd|}|t|<qWndt jkrt jd}x8d%D]0}t|}tjdd|}|d|}|t|<qWtjdd } tjd | } | dk r| j d!} t jj!| sx,d&D]$}t|}tjd"d|}|t|<q^W|rg} x|D]} | j"tj| qW| StSdS)'ayWith 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 and Mac OS 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_prefix py_versionpy_version_shortrr!py_version_nodotrcplatbase projectbaserrjros2rMz2.6userbasesrcdirr[r#rrm BASECFLAGSrl PY_CFLAGSrz -arch\s+\w+\s z-isysroot [^ ]*Z ARCHFLAGSz-isysroot\s+(\S+)r$z-isysroot\s+\S+(\s|$))rr)rmrrlrr)rmrrlrr)rmrrlrr)# _CONFIG_VARS_PREFIX _EXEC_PREFIX _PY_VERSIONrrr_rAttributeErrorrr7rrversionrerr/getcwdrrisabsrrOr`unamerysplitrpr?rDr^r}r5existsappend)rVrccwdrZkernel_versionZ major_versionrKflagsZarchrlrZsdkvalsr7rrrrs                    cCs tj|S)zReturn the value of a single variable using the dictionary returned by 'get_config_vars()'. Equivalent to get_config_vars().get(name) )rr^)r7rrrrRscCs`tjdkrnd}tjj|}|d:kr(tjStjjd|}tj|t||j}|dkr\dS|dkrhdStjStjd ksttd  rtjStj \}}}}}|jj d d }|j d d}|j d d}|dddkrd||fS|dddkr(|ddkrRd}dt |dd|ddf}n*|dddkrFd||fS|dddkrfd|||fS|ddd krd }t j d!} | j|} | rR| j}n|ddd"krRt} | jd#} | } y td$}Wntk rYnJXzt jd%|j} Wd|jX| dk r4d&j| jdjd&dd} | s>| } | rR| }d'}| d&d(krd)tjd*d jkrd+}tjd*}t jd,|}ttt|}t|dkr|d}n^|d;krd+}nN|d|d=krd1}n.|d>krd3}n|d?krd4}ntd5|fn<|d-kr2tjd@krRd/}n |dAkrRtjdBkrNd2}nd.}d9|||fS)CaReturn 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; eg. for IRIX the architecture isn't particularly important (IRIX only runs on SGI hardware), but for Linux the kernel version isn't particularly important. Examples of returned values: linux-i586 linux-alpha (?) solaris-2.6-sun4u irix-5.3 irix64-6.2 Windows will return one of: win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc) win-ia64 (64bit Windows on Itanium) win32 (all others - specifically, sys.platform is returned) For other non-POSIX platforms, currently just returns 'sys.platform'. rz bit (r$)amd64z win-amd64itaniumzwin-ia64rMr/rjr_-Nlinuxz%s-%ssunosr5solarisz%d.%srCr!irixaixz%s-%s.%scygwinz[\d.]+r[MACOSX_DEPLOYMENT_TARGETz0/System/Library/CoreServices/SystemVersion.plistz=ProductUserVisibleVersion\s*(.*?)r#Zmacosxz10.4.z-archrlZfatz -arch\s+(\S+)i386ppcx86_64ZintelZfat3ppc64Zfat64Z universalz%Don't know machine value for archs=%r PowerPCPower_Macintoshz%s-%s-%s)rr)rr)rrr)rr)rrrrl)rrl) rr7r_rr,r`r|lowerrrrxryrprqrwr5rr^rsrr}readcloserrrvfindallr;rr0rzmaxsize)rijlookosnamehostreleasermachinerel_rerZcfgvarsZmacverZ macreleaserZcflagsZarchsrrrr [s     $                    cCstS)N)rrrrrr scCsJxDtt|jD]0\}\}}|dkr2td|td||fqWdS)Nrz%s: z %s = "%s") enumeraterr:print)titledataindexrKrArrr _print_dicts rcCsRtdttdttdtttdtttdtdS)z*Display all information sysconfig detains.zPlatform: "%s"zPython version: "%s"z!Current installation scheme: "%s"Paths VariablesN)rr r rTrr rrrrr_mains r__main__iii)N)N)A__doc__rrrrpr_Zos.pathrrZ configparser ImportErrorZ ConfigParser__all__rrrrrrr7rrr r/r)r3ZRawConfigParserr.rqr>rBrrrrrrOrrrrr _USER_BASErFrLrRrSrTrerrrrrrr r r rrrr r rrr*rrrrs   " #   v     #