B ;C`@sdZddlmZmZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z mZddlmZedddd d d gZd d ZeZedZGdddeZedkreedS)z The PythonInfo contains information about a concrete instance of a Python interpreter Note: this file is also used to query target interpreters, so can only use standard library methods )absolute_importprint_functionN) OrderedDict namedtuple)digits VersionInfomajorminormicro releaselevelserialcCs*ttdgtjddtjS)NPATHEXT) listrfromkeysosenvirongetlowersplitpathseprrM/opt/alt/python37/lib/python3.7/site-packages/virtualenv/discovery/py_info.py_get_path_extensionssrz\{\w+\}c@seZdZdZddZddZddZedd Ze d d Z e d d Z e ddZ e ddZ e ddZdejfddZdIddZe ddZe ddZe ddZd d!Zd"d#Zd$d%Ze d&d'Zed(d)Zd*d+ZdZdZedJd,d-ZedKd.d/Z d0d1Z!d2d3Z"edLd5d6Z#ed7d8Z$ed9d:Z%ed;d<Z&iZ'dMd=d>Z(d?d@Z)edAdBZ*dCdDZ+dEdFZ,dGdHZ-dS)N PythonInfoz-Contains information for a Python interpretercsdddd}tj_t_jdkrNtfddtjD_ttfddtjD_tj d krzd nd _ tj _ t j _ |ttd d_|ttd d_|ttdd_|ttdd_|ttdd_|tj_|j__ytdd}Wntk rZd}YnX|_fddtjD_t_ttjdd_dt !krd_"fddt #D_$i_%n:d_"fddt #D_$fdd&'D_%tt dtt dd}fddd|fgD_ t(}x@j$)D]2}x*t*+|D]}|,|dd qZWqJW|,d!fd"d|D_-jdkrtjj.d#krd$j-d%<fd&dj-'D}/d'|_0/d(|_1ttd)ttd*d_2d_3dS)+NcSst|tr|dS|S)Nzutf-8) isinstancebytesdecode)vrrru"szPythonInfo.__init__..ucSs|dkr dStj|S)N)rpathabspath)rrrrabs_path%sz%PythonInfo.__init__..abs_pathPyPyc3s|]}|VqdS)Nr).0i)rrr ,sz&PythonInfo.__init__..c3s|]}|VqdS)Nr)r$r%)rrrr&/sl@ prefix base_prefix real_prefixbase_exec_prefix exec_prefixvenvTFcsg|] }|qSrr)r$r%)rrr Hsz'PythonInfo.__init__..encodingcs&i|]}tj|ddd|qS)Fr.)expandscheme) sysconfigget_path)r$r%)rrr Nsz'PythonInfo.__init__..cs$i|]}tj|dd|qS)F)r1)r3r4)r$r%)rrrr5Uscsi|]\}}||qSrr)r$kr)rrrr5Vsget_makefile_filenameZ_get_makefile_filenamecs&i|]\}}|dk r||qS)Nr)r$r6r)rrrr5ZsZmakefile_filenamePYTHONFRAMEWORKcs$i|]}t|pd|qS)r )r3get_config_var)r$r%)rrrr5ispythonZimplementation_lowercs(i|] \}}|jrjn||qSr) startswithr) system_prefix)r$r6r)selfrrr5msstdlib platstdlibmaxsizeZmaxint)4sysplatformpython_implementationimplementationtupleZpypy_version_inforr version_inforC architectureversionrnamegetattrr)r*r+r,r- executableoriginal_executable_fast_get_system_executablesystem_executable __import__ ImportErrorZhas_venvr getfilesystemencodingfile_system_encodingstdoutstdout_encodingr3get_scheme_namesZsysconfig_schemeget_path_namessysconfig_pathsdistutils_install_distutils_installitemssetvalues _CONF_VAR_REfindalladdsysconfig_varsrsysconfig_pathZ system_stdlibZsystem_stdlib_platformmax_size _creators)r@r"ZhasmakefileZconfig_var_keyselementr6Zconfsr)r@rr__init__!sf        "  zPythonInfo.__init__cCsR|js|jdk rL|j|jkrL|jdkrHttdd}|dk rHtj|krH|SdS|jS)z>Try to get the system executable by just looking at propertiesN_base_executable)r+r*r)rMrDrNrO)r@Zbase_executablerrrrPss   z&PythonInfo._fast_get_system_executablecsZ|j|}|dkrV|j|j|j|jffdd|jD}|j||d t j }|S)Ncs"i|]\}}|krdn||qS)r r)r$r6r)prefixesrrr5sz+PythonInfo.install_path..) config_var) r[rr)r-r*r,rcr]rdlstriprsep)r@keyresultrlr)rkr install_paths  zPythonInfo.install_pathc stBtdyddlm}ddlm}Wntk rDiSXWdQRX|ddi}t t drndt _ ttd|j dd d WdQRXt j_fd d |D}|S) Nignorer)dist) SCHEME_KEYS script_argsz --no-user-cfg _frameworkinstallT)createcs.i|]&}td|ddtj|qS)z install_{}r8N)rMformatrmrrn)r$ro)r%rrr5sz1PythonInfo._distutils_install..)warningscatch_warnings simplefilter distutilsrsdistutils.command.installrtrS DistributionhasattrrDrvget_command_objrrnr)finalize_options)rsrtdrpr)r%rr\s"      zPythonInfo._distutils_installcCsddd|jddDS)N.css|]}t|VqdS)N)str)r$r%rrrr&sz)PythonInfo.version_str..r)joinrI)r@rrr version_strszPythonInfo.version_strcCsddd|jddDS)Nrcss|]}t|VqdS)N)r)r$r%rrrr&sz1PythonInfo.version_release_str..rr<)rrI)r@rrrversion_release_strszPythonInfo.version_release_strcCs|j}d|j|jS)Nz python{}.{})rIryrr )r@rIrrr python_nameszPythonInfo.python_namecCs |jdk S)N)r+)r@rrris_old_virtualenvszPythonInfo.is_old_virtualenvcCs|jdk o|jjdkS)Nr)r*rIr)r@rrris_venvszPythonInfo.is_venvNcCsP|j|}|dkr|j}n"dd|jD}|||}|jf|d|S)NcSsi|]\}}||qSrr)r$r6rrrrr5sz-PythonInfo.sysconfig_path../)rZrcr]updateryreplace)r@rorlrnpatternbaserrrrds  zPythonInfo.sysconfig_pathFcCs0|jdks|dkr*ddlm}|||_|jS)NTr)CreatorSelector)rfZvirtualenv.run.plugin.creatorsrZfor_interpreter)r@Zrefreshrrrrcreatorss  zPythonInfo.creatorscs^dfddjD}tj|sZtjjtj d}tj|rZ|}|S)Nincludecs(i|] \}}|jrjn||qSr)r>r)r?)r$r6r)r@rrr5sz-PythonInfo.system_include..headers) rdrcr]rr existsrr)dirnamerq)r@r fallbackr)r@rsystem_includes  zPythonInfo.system_includecCs|jp|jp|jS)N)r+r*r))r@rrrr?szPythonInfo.system_prefixcCs|jp|jp|jS)N)r+r,r-)r@rrrsystem_exec_prefixszPythonInfo.system_exec_prefixcCs t|}tjdkr|d}|S)Nr<zutf-8)reprrDrIr)r@contentrrr __unicode__s  zPythonInfo.__unicode__cCs d|jjdd|jDS)Nz{}({!r})cSs i|]\}}|ds||qS)_)r>)r$r6rrrrr5sz'PythonInfo.__repr__..)ry __class____name____dict__r])r@rrr__repr__szPythonInfo.__repr__cCsd|jjdddd|jf|jdk r6|j|jkr6dnd|jf|j|jkrZ|j|jkrZdnd|jfd|jfd |jfd t |j fd d |j |j ffD}|S) Nz{}({})z, css&|]\}}|dk rd||VqdS)Nz{}={})ry)r$r6rrrrr&sz%PythonInfo.__str__..specsystemoriginalexerErKZencoding_fs_ioz{}-{}) ryrrrrrQrNrOrErrKrUrW)r@rrrr__str__s"  zPythonInfo.__str__cCs$d|jddd|jD|jS)Nz{}{}-{}rcss|]}t|VqdS)N)r)r$r%rrrr&sz"PythonInfo.spec..)ryrGrrIrJ)r@rrrr szPythonInfo.speccCs"ddlm}|||jdS)Nr)clear)#virtualenv.discovery.cached_py_infor_cache_exe_discovery)clsapp_datarrrr clear_caches zPythonInfo.clear_cachecCs|jrz|jtj|jkrdS|jsztj|j}|j}tjdkrntj |\}}| |rn|dt | }||krzdS|r|j dk r|j |j krdS|jdk r|j|jkrdSxHt|jdd|j|j|jfD]$\}}|dk r|dk r||krdSqWdS)zWcheck if a given specification can be satisfied by the this python interpreter instanceTwin32NFrr)r rNrr!Zis_absbasenamerOrDrEsplitextendswithlenrGrrJziprIrr r )r@rZimpl_must_matchrZ spec_pathsuffixZourreqrrr satisfiess*  *zPythonInfo.satisfiescCs&|jdkr |jtj|ddd|_|jS)z This locates the current host interpreter information. This might be different than what we run into in case the host python has been upgraded from underneath us. NTF)raise_on_errorresolve_to_host)_currentfrom_exerDrN)rrrrrcurrent7s zPythonInfo.currentcCs&|jdkr |jtj|ddd|_|jS)z This locates the current host interpreter information. This might be different than what we run into in case the host python has been upgraded from underneath us. NT)rr)_current_systemrrDrN)rrrrrcurrent_systemAs zPythonInfo.current_systemcCstj|ddS)Nr<)indent)jsondumps_to_dict)r@rrr_to_jsonKszPythonInfo._to_jsoncs*fddtD}|d|d<|S)Ncs$i|]}|dkrt|nd|qS))rfN)rM)r$var)r@rrr5Psz'PythonInfo._to_dict..rI)vars_asdict)r@datar)r@rrOszPythonInfo._to_dictTc Csddlm}|dkrtjn|}|||||||d}t|tr|ry|||}Wn>tk r} z |rj| t d|j | d}Wdd} ~ XYnX|S)z8Given a path to an executable get the python informationr)rN)envr ignore_cachez-ignore %s due cannot resolve system due to %r) rrrrrr_resolve_to_system ExceptionlogginginforO) rrrrrrrrZproposed exceptionrrrrUs zPythonInfo.from_execCs"t|}|dd|DS)NcSsi|]\}}||qSrr)r$r6rrrrr5lsz)PythonInfo._from_json..)rloads _from_dictr])rpayloadrawrrr _from_jsonhs zPythonInfo._from_jsoncCs0tf|d|d<|}dd|D|_|S)NrIcSsi|]\}}||qSrr)r$r6rrrrr5rsz)PythonInfo._from_dict..)rr]r)rrrprrrrnszPythonInfo._from_dictc Cs|j}t}x|jdkr|jp(|jp(|j}||krt|dkrTtd||j|_Px0t | ddD]\}\}}t d|||qfWt dt|d||t d d||||<|j||dd}qW|j|jkr||j|}||_|S) Nr8z$%r links back to itself via prefixes)startz%d: prefix=%s, info=%rz prefixes are causing a circle {}|F)r)exact)rNrrQr+r*r)rrr enumerater]error RuntimeErrorryrkeys discover_exer) rrtargetZstart_executablerkr)atptrrrrus&    zPythonInfo._resolve_to_systemc Cs||f}||jkr6|r6td|||j||j|Std|||}||}g}|dkrhtjn|}xD|D]<} x6|D].} ||| | |||} | dk r|| |j|<| Sq|WqrW|dkr|r|||} tj |} | |j|<td| | | Sd d |tj |} t | dS)Nz)discover exe from cache %s - exact %s: %rzdiscover exe for %s in %sFzFno exact match found, chosen most similar of %s within base folders %szfailed to detect {} in {}r) rrdebug_find_possible_exe_names_find_possible_foldersrr _check_exe_select_most_likelyrrryr)r@rr)rrroZpossible_namesZpossible_folders discoveredfolderrLrZfoldersmsgrrrrs.          zPythonInfo.discover_exec Cstj||}tj|sdS|j||dd|d}|dkr>dSxdD]~} t|| } t|| } | | krD| dkrddd| Dddd| D} } |j} td| | | | |dkr| |PqDW|SdS) NF)rrr)rGrJrIrIrcss|]}t|VqdS)N)r)r$r%rrrr&sz(PythonInfo._check_exe..z2refused interpreter %s because %s differs %s != %s) rr rrrrMrNrrappend) r@rrrLrrrZexe_pathritemfoundZsearchedrNrrrrs&    * zPythonInfo._check_execs&fdd}t||dd}|d}|S)Ncs||jjk|jjjjk|jjjjk|jjk|jjjjk|jjjjk|jjjjkg}tddt t |D}|S)Ncss"|]\}}|rd|>ndVqdS)r8rNr)r$posmatchrrrr&szBPythonInfo._select_most_likely..sort_by..) rGrIrr rJr r r sumrreversed)rmatchespriority)rrrsort_bys  z/PythonInfo._select_most_likely..sort_byT)roreverser)sorted)rrrZsorted_discoveredZ most_likelyr)rrrs zPythonInfo._select_most_likelycCst}t}d|tj|j<d||j<d|tj|j<d||j<xJ|D]>}tj|}||j rN|t |j d}d|d ||<qNWd||<t dd|DS)Nz{}{}css|]}tj|r|VqdS)N)rr r)r$r%rrrr&sz4PythonInfo._find_possible_folders..) rrr realpathrNrOrrr>r)rryr)r@Z inside_folderZcandidate_folder executablesrrrelativerrrrs    z!PythonInfo._find_possible_foldersc Cst}x||D]p}xjdD]b}ddd|jd|D}x>d|jdgD]*}x$tD]}d||||}d||<qXWqNWqWqWt|S)N)rr<r8rrcss|]}t|VqdS)N)r)r$r%rrrr&sz6PythonInfo._find_possible_exe_names..z-{}r z{}{}{}{}) r_possible_baserrIryrJ EXTENSIONSrr)r@Zname_candidaterLrrKarchext candidaterrrrs  z#PythonInfo._find_possible_exe_namesccst}tjtj|jdt}d||<d||j<d|krF|d=d|d<xP|D]H}| }|Vddl m }|rT||kr|V| }||krT|VqTWdS)Nrr=)fs_is_case_sensitive) rrr rrrNrstriprrGrZvirtualenv.inforupper)r@Z possible_baserrrrrrrrrs"    zPythonInfo._possible_base)F)N)N)NTFTN)TN).r __module__ __qualname____doc__rirPrq staticmethodr\propertyrrrrrrrnrdrrr?rrrrr classmethodrrrrrrrrrrrrrrrrrrrrrrrrsRR                    r__main__)r __future__rrrrrrErerDr3rz collectionsrrstringrrrrcompiler`objectrrprintrrrrrs*  m