o $"b@sdZddlmZmZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZddlmZdd lmZdd lmZmZe Ze eeej<dd dZdddZddZddZGdddeZddZdZ dS)z We acquire the python information by running an interrogation script via subprocess trigger. This operation is not cheap, especially not on Windows. To not have to pay this hefty cost every time we apply multiple levels of caching. )absolute_importunicode_literalsN) OrderedDict)AppDataDisabled) PythonInfo)PY2)Path) ensure_text)Popen subprocessTFcCsN|durtjn|}t|||||d}t|tr%|r|tdt|d}|S)N) ignore_cachez%s)osenviron_get_from_cache isinstance Exceptionlogginginfostr)clsapp_dataexeenvraise_on_errorr resultrE/usr/lib/python3/dist-packages/virtualenv/discovery/cached_py_info.pyfrom_exes rcCsNt|}|s|tvrt|}nt|||||}|}t|<t|tr%||_|SN)r_CACHE_get_via_file_cacherr executable)rrrrr exe_pathrpy_inforrrr&s    rcCsdtt|}z|j}Wn tyd}Ynw|dur t}d||}}|||ro| } | d| d| d} } } | |krk| |krk| dd| D}|j } | durjt j| sj|d}n||durt||||\}}|dur|||d} || n|}Wd|SWd|SWd|S1swY|S)Npathst_mtimecontentcSsi|]\}}||qSrr).0kvrrr Csz'_get_via_file_cache..)r&r%r')r rstatr&OSErrorrr#lockedexistsread _from_dictitemssystem_executabler r%remove_run_subprocess_to_dictwrite)rrr%rr path_text path_modifiedr# py_info_storedataof_path of_st_mtime of_contentsys_exefailurerrrr 5sJ       r c Cs>ttjtjd}||U}|t|g}|}| ddt dt |zt |dtjtjtj|d}|\}}|j} Wnty]} zd| j| j}}} WYd} ~ nd} ~ wwWdn1shwYd\} } | dkr||} || _| | fSd || |rd |nd|rd |nd} t| } | | fS) Nz py_info.py__PYVENV_LAUNCHER__z get interpreter info via cmd: %sT)universal_newlinesstdinstderrstdoutr)NNrz#failed to query {} with code {}{}{}z out: {!r}z err: {!r})rr r%abspath__file__parentensure_extractedrcopypoprdebugLogCmdr r PIPE communicate returncoder-strerrorerrno _from_jsonr!format RuntimeError)rrrrpy_info_scriptcmdprocessouterrcodeos_errorrr@msgrrrr5TsH        r5c@s&eZdZdddZddZddZdS) rNNcCs||_||_dSr)rXr)selfrXrrrr__init__ys zLogCmd.__init__csVdddfdd|jD}|jdur"|d|j7}tr)|dS|S)NcSst|tr |dS|SNutf-8)rbytesdecode)r*rrre~szLogCmd.__repr__..e c3s|] }t|VqdSr)pipesquote)r(crerr sz"LogCmd.__repr__..z env of {!r}rb)joinrXrrUrencode)r_cmd_reprrrjr__repr__}s  zLogCmd.__repr__cCst|}tr |dS|Sra)reprrrd)r_rawrrr __unicode__s zLogCmd.__unicode__r)__name__ __module__ __qualname__r`rorrrrrrrNxs  rNcCs|tdSr) py_info_clearrclear)rrrrrws rw)rrwrN)NTF)T)!__doc__ __future__rrrr rgsys collectionsrvirtualenv.app_datarvirtualenv.discovery.py_inforvirtualenv.inforvirtualenv.util.pathrvirtualenv.util.sixr virtualenv.util.subprocessr r rr!rrr r5objectrNrw ___all___rrrrs,        $