o $"b@sddlmZmZddlZddlZddlZddlmZddlm Z m Z ddl m Z ddl mZddlmZGd d d e Zdd d Zdd dZddZGdddeZddZddZGdddeZdS))absolute_importunicode_literalsN)IS_WIN) ensure_str ensure_text)Discover) PythonInfo) PythonSpeccs@eZdZfddZeddZddZddZd d ZZ S) Builtincs:tt|||jr|jntjg|_|j|_|j|_dSN) superr __init__pythonsys executable python_specapp_datatry_first_with)selfoptions __class__>/usr/lib/python3/dist-packages/virtualenv/discovery/builtin.pyrs zBuiltin.__init__c Cs6|jddddtdgdd|jdd d tdgd ddS) Nz-pz--pythonrpyappendzinterpreter based on what to create environment (path/identifier) - by default use the interpreter where the tool is installed - first found wins)destmetavartypeactiondefaulthelpz--try-first-withrpy_exez:try first these interpreters before starting the discovery) add_argumentstr)clsparserrrradd_parser_argumentss&  zBuiltin.add_parser_argumentscCs4|jD]}t||j|j|j}|dur|SqdSr )rget_interpreterrr_env)rrresultrrrrun-s z Builtin.runcC t|Sr r __unicode__rrrr__repr__4 zBuiltin.__repr__cCs.t|jdkr |jdn|j}d|jj|S)Nrrz{} discover of python_spec={!r})lenrformatr__name__)rspecrrrr/7szBuiltin.__unicode__) r5 __module__ __qualname__r classmethodr(r,r1r/ __classcell__rrrrr s  r cCst|}td|t}|durtjn|}t||||D])\}}|j|f}||vr,qtd|| ||rBt d||S| |qdS)Nzfind interpreter for spec %rz proposed %sz accepted %s) r from_string_speclogginginfosetosenvironpropose_interpreterssystem_executable satisfiesdebugadd)keyrrenvr6proposed_paths interpreterimpl_must_matchrrrr)<s       r)c cs|durtjn|}|D](}tj|}zt|Wn ty$Yq wtjtj|||ddfVq |jdurfzt|jWn tyO|jrMYnwtjtj|j||ddfV|jredSnt |dfVt rddl m }||||D]}|dfVq|t |}t} t|D]D\} }t|}tt| ||t|D].\} } t| |} | durtj| }|| vr| |tj||d|d}|dur|| fVqqdS)N)rGTr)rAF)raise_on_errorrG)r?r@pathabspathlstatOSErrorr from_exeis_abscurrent_systemrwindowsrA get_pathsr> enumeraterr<rD LazyPathDumppossible_specs check_pathrEPathPythonInfo)r6rrrGr#rLrArIpaths tested_exespos candidatematchfoundexerrrrALsX            rAc Csj|tdd}|dur"ztd}Wnttfy!tj}Ynw|s(g}|Sdd|tjD}|S)NPATHCS_PATHcSsg|] }tj|r|qSr)r?rLexists).0prrr szget_paths..) getr%r?confstrAttributeError ValueErrordefpathsplitpathsep)rGrLrZrrrrT~s rTc@s$eZdZddZddZddZdS)rVcCs||_||_||_dSr )r\rLrG)rr\rLrGrrrrs zLazyPathDump.__init__cCr-r r.r0rrrr1r2zLazyPathDump.__repr__c Csd|j|j}|jtdrH|d7}t|jD]-}ztj|j|}tj |s2t |tj s4WqWn t y>Ynw|d7}||7}q|S)Nzdiscover PATH[{}]={}_VIRTUALENV_DEBUGz with => ) r4r\rLrGrgr%r?listdirjoinisdiraccessX_OKrO)rcontent file_name file_pathrrrr/s  zLazyPathDump.__unicode__N)r5r7r8rr1r/rrrrrVs rVcCs\tj|\}}tjdkr|dkr|d}tj|r|Stj||}tj|r,|SdS)Nwin32z.exe)r?rLsplitextrplatformisfilerq)r]rL_extrrrrXs  rXccs.|jdfV|D] \}}||fVq dS)NF)str_specgenerate_names)r6r`r^rrrrWs   rWc@seZdZdZdS)rYroN)r5r7r8__doc__rrrrrYsrY)NNr ) __future__rrr<r?rvirtualenv.inforvirtualenv.util.sixrrdiscoverrpy_infor py_specr r r)rArTobjectrVrXrWrYrrrrs"     - 2