o $"bV[@sdZddlmZmZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z mZddlmZedgdZdd ZeZed ZGd d d eZed kr`eedSdS)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 VersionInfo)majorminormicro releaselevelserialcCs*ttdgtjddtjS)NPATHEXT) listrfromkeysosenvirongetlowersplitpathseprr>/usr/lib/python3/dist-packages/virtualenv/discovery/py_info.py_get_path_extensionss*rz\{\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-ZedJd.d/Z d0d1Z!d2d3Z"edKd5d6Z#ed7d8Z$ed9d:Z%ed;d<Z&iZ'dLd=d>Z(d?d@Z)edAdBZ*dCdDZ+dEdFZ,dGdHZ-dS)M PythonInfoz-Contains information for a Python interpretercsdddd}tj_t_jdkr'tfddtjD_ttfddtjD_tj d kr=d nd _ tj _ t j _ |ttd d_|ttd d_|ttdd_|ttdd_|ttdd_|tj_|j__ztdd}Wn tyd}Ynw|_fddtjD_t_ttjdd_dt !vrd_"fddt #D_$i_%nd_"fddt #D_$fdd&'D_%tt dtt dd}fddd|ffD_ t(}j$)D]}t*+|D]}|,|dd q(q!|,d!fd"d|D_-jdkrZtjj.d#krZd$j-d%<fd&dj-'D}/d'|_0/d(|_1ttd)ttd*d_2d_3dS)+NcSst|tr |dS|S)Nutf-8) isinstancebytesdecodevrrru"zPythonInfo.__init__..ucSs|durdStj|SN)rpathabspathrrrrabs_path%r"z%PythonInfo.__init__..abs_pathPyPyc3|]}|VqdSr#r.0ir!rr ,z&PythonInfo.__init__..c3r(r#rr)r,rrr-/r.l@ prefix base_prefix real_prefixbase_exec_prefix exec_prefixvenvTFcsg|]}|qSrrr)r,rr Hsz'PythonInfo.__init__..encodingc s&i|]}|tj|dddqS)Fr6)expandscheme sysconfigget_pathr)r,rr Nsz'PythonInfo.__init__..cs$i|]}|tj|ddqS)F)r9r;r)r,rrr>U$csi|] \}}||qSrrr*kr r,rrr>Vsget_makefile_filename_get_makefile_filenamecs&i|]\}}|dur||qSr#rr@r,rrr>Zs  makefile_filenamePYTHONFRAMEWORKcs$i|]}|t|pdqSr )r<get_config_varr)r,rrr>ir?pythonimplementation_lowerc(i|]\}}||jrjn|qSr startswithr1 system_prefixr@selfrrr>m(stdlib platstdlibmaxsizemaxint)4sysplatformpython_implementationimplementationtuplepypy_version_inforr version_inforV architectureversionrnamegetattrr1r2r3r4r5 executableoriginal_executable_fast_get_system_executablesystem_executable __import__ ImportErrorhas_venvr$getfilesystemencodingfile_system_encodingstdoutstdout_encodingr<get_scheme_namessysconfig_schemeget_path_namessysconfig_pathsdistutils_install_distutils_installitemssetvalues _CONF_VAR_REfindalladdsysconfig_varsrsysconfig_path system_stdlibsystem_stdlib_platformmax_size _creators)rRr&hasmakefileconfig_var_keyselementrAconfsr)rRr!r__init__!sp             zPythonInfo.__init__cCsR|js|jdur&|j|jkr&|jdur$ttdd}|dur$tj|kr$|SdS|jS)z>Try to get the system executable by just looking at propertiesN_base_executable)r3r2r1rbrXrcrd)rRbase_executablerrrress   z&PythonInfo._fast_get_system_executablecsZ|j|}|dur+|j|j|j|jffdd|jD}|j||d t j }|S)Ncs"i|] \}}||vr dn|qSrHrr@prefixesrrr>s"z+PythonInfo.install_path..) config_var) rrrr1r5r2r4rzrtr{lstriprsep)rRkeyresultrrrr install_paths zPythonInfo.install_pathc st.tdzddlm}ddlm}Wnty*iYWdSwWdn1s5wY|ddi}t t drIdt _ ttd|j dd d Wdn1sdwYt j_fd d |D}|S) Nignorer)dist) SCHEME_KEYS script_argsz --no-user-cfg _frameworkinstallT)createcs.i|]}|td|ddtjqS)z install_{}rEN)rbformatrrr)r*rr+rrr>s.z1PythonInfo._distutils_install..)warningscatch_warnings simplefilter distutilsrdistutils.command.installrrh DistributionhasattrrXrget_command_objrrr1finalize_options)rrdrrrrrss,       zPythonInfo._distutils_installcCddd|jddDS)N.cs|]}t|VqdSr#strr)rrrr-r.z)PythonInfo.version_str..rjoinr^rQrrr version_strzPythonInfo.version_strcCr)Nrcsrr#rr)rrrr-r.z1PythonInfo.version_release_str..rrJrrQrrrversion_release_strrzPythonInfo.version_release_strcCs|j}d|j|jS)Nz python{}.{})r^rrr )rRr^rrr python_nameszPythonInfo.python_namecCs |jduSr#)r3rQrrris_old_virtualenvs zPythonInfo.is_old_virtualenvcCs|jduo |jjdkS)Nr)r2r^rrQrrris_venvszPythonInfo.is_venvNcCsT|j|}|dur |j}ndd|jD}|||}|jdi|d|S)NcSi|]\}}||qSrrr@rrrr>z-PythonInfo.sysconfig_path../r)rqrzrtupdaterreplace)rRrrrpatternbaserrrr{s  zPythonInfo.sysconfig_pathFcCs0|jdus |durddlm}|||_|jS)NTr)CreatorSelector)rvirtualenv.run.plugin.creatorsrfor_interpreter)rRrefreshrrrrcreatorss  zPythonInfo.creatorscs^dfddjD}tj|s-tjjtj d}tj|r-|}|S)NincludecrMrrNr@rQrrr>rSz-PythonInfo.system_include..headers) r{rzrtrr$existsrr1dirnamer)rRr$fallbackrrQrsystem_includes  zPythonInfo.system_includecC|jp|jp|jSr#)r3r2r1rQrrrrPzPythonInfo.system_prefixcCrr#)r3r4r5rQrrrsystem_exec_prefixrzPythonInfo.system_exec_prefixcCs t|}tjdkr|d}|S)NrJr)reprrXr^rrRcontentrrr __unicode__s  zPythonInfo.__unicode__cCs d|jjdd|jDS)Nz{}({!r})cSs i|] \}}|ds||qS)_)rOr@rrrr>s z'PythonInfo.__repr__..)r __class____name____dict__rtrQrrr__repr__szPythonInfo.__repr__cCsd|jjdddd|jf|jdur|j|jkrdnd|jf|j|jkr-|j|jkr-dnd|jfd|jfd |jfd t |j fd d |j |j ffD}|S) Nz{}({})z, css(|]\}}|durd||VqdS)Nz{}={})rr@rrrr-s z%PythonInfo.__str__..specsystemoriginalexerYr`encoding_fs_ioz{}-{}) rrrrrrfrcrdrYrr`rkrmrrrr__str__s.    zPythonInfo.__str__cCs$d|jddd|jD|jS)Nz{}{}-{}rcsrr#rr)rrrr-r.z"PythonInfo.spec..)rr[rr^r_rQrrrr s$zPythonInfo.speccCs"ddlm}|||jdS)Nr)clear)#virtualenv.discovery.cached_py_infor_cache_exe_discovery)clsapp_datarrrr clear_caches zPythonInfo.clear_cachecCs|jr=|jtj|jkrdS|js=tj|j}|j}tjdkr7tj |\}}| |r7|dt | }||kr=dS|rP|j durP|j |j krPdS|jdur]|j|jkr]dSt|jdd|j|j|jfD]\}}|dur|dur||krdSqmdS)zWcheck if a given specification can be satisfied by the this python interpreter instanceTwin32NFrr)r$rcrr%is_absbasenamerdrXrYsplitextendswithlenr[rr_zipr^rr r )rRrimpl_must_matchr spec_pathsuffixourreqrrr satisfiess,  (zPythonInfo.satisfiescCs&|jdur|jtj|ddd|_|jS) 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. NTFraise_on_errorresolve_to_host)_currentfrom_exerXrcrrrrrcurrent7 zPythonInfo.currentcCs&|jdur|jtj|ddd|_|jS)rNTr)_current_systemrrXrcrrrrcurrent_systemArzPythonInfo.current_systemcCstj|ddS)NrJ)indent)jsondumps_to_dictrQrrr_to_jsonKrzPythonInfo._to_jsoncs*fddtD}|d|d<|S)Ncs$i|]}||dvrt|ndqS))rN)rb)r*varrQrrr>Pr?z'PythonInfo._to_dict..r^)vars_asdict)rRdatarrQrrOszPythonInfo._to_dictTc Csddlm}|dur tjn|}|||||||d}t|trK|rKz |||}W|StyJ} z|r5| t d|j | d}WYd} ~ |Sd} ~ ww|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 Exceptionlogginginford) rrrrrrrrproposed exceptionrrrrUs zPythonInfo.from_execCs"t|}|dd|DS)NcSrrrr@rrrr>lrz)PythonInfo._from_json..)rloads _from_dictrt)rpayloadrawrrr _from_jsonhs zPythonInfo._from_jsoncCs4tdi|d|d<|}dd|D|_|S)Nr^cSrrrr@rrrr>rrz)PythonInfo._from_dict..r)rrtr)rrrrrrrnszPythonInfo._from_dictc Cs|j}t}|jduri|jp|jp|j}||vrXt|dkr)td||j|_n@t | ddD]\}\}}t d|||q1t dt|d||t d d||||<|j||dd}|jdus |j|jkrv||j|}||_|S) NrEz$%r links back to itself via prefixes)startz%d: prefix=%s, info=%rz prefixes are causing a circle {}|F)r1exact)rcrrfr3r2r1rrr enumeraterterror RuntimeErrorrrkeys discover_exer) rrtargetstart_executablerr1atptrrrrus(    zPythonInfo._resolve_to_systemc Cs||f}||jvr|rtd|||j||j|Std|||}||}g}|dur4tjn|}|D] } |D]} ||| | |||} | durW| |j|<| Sq.z2refused interpreter %s because %s differs %s != %s) rr$rrrrbrcrrappend) rRrrrar rrexe_pathritemfoundsearchedrcrrrrs(   *  zPythonInfo._check_execs&fdd}t||dd}|d}|S)Ncs||jjk|jjjjk|jjjjk|jjk|jjjjk|jjjjk|jjjjkg}tddt t |D}|S)Ncss$|] \}}|r d|>ndVqdS)rErNr)r*posmatchrrrr-s"zBPythonInfo._select_most_likely..sort_by..) r[r^rr r_r r r sumr reversed)rmatchespriorityrrrsort_bys   z/PythonInfo._select_most_likely..sort_byT)rreverser)sorted)rrr-sorted_discovered most_likelyrr,rrs zPythonInfo._select_most_likelycCst}t}d|tj|j<d||j<d|tj|j<d||j<|D]}tj|}||j rE|t |j d}d|d ||<q&d||<t dd|DS)Nz{}{}css |] }tj|r|VqdSr#)rr$rr)rrrr-sz4PythonInfo._find_possible_folders..) rrr$realpathrcrdrrrOr1rrr)rR inside_foldercandidate_folder executablesrrrelativerrrrs     z!PythonInfo._find_possible_foldersc Cst}|D]2}dD]-}ddd|jd|D}d|jdfD]}tD]}d||||}d||<q(q$q qt|S)N)rrJrErrcsrr#rr)rrrr-r.z6PythonInfo._find_possible_exe_names..z-{}r z{}{}{}{}) r_possible_baserr^rr_ EXTENSIONSrr)rRname_candidaterarr`archext candidaterrrrs   z#PythonInfo._find_possible_exe_namesccst}tjtj|jdt}d||<d||j<d|vr$|d=d|d<|D]$}| }|Vddl m }|rN||krC|V| }||krN|Vq*dS)NrrK)fs_is_case_sensitive) rrr$rrrcrstriprr[rvirtualenv.infor=upper)rR possible_baserrrr=r@rrrr7s(   zPythonInfo._possible_base)Fr#)NTFTN)TN).r __module__ __qualname____doc__rrer staticmethodrspropertyrrrrrrrr{rrrPrrrrr classmethodrrrrrrrrrrrrrrrrrrr7rrrrrsrR                      r__main__)rD __future__rrrrrrYrerXr<r collectionsrrstringrrrr8compilerwobjectrrprintrrrrrs.  m