o $"b"@s*ddlmZmZmZddlZddlZddlZddlZddlm Z m Z ddl m Z ddl mZddlmZddlmZddlmZdd lmZdd lmZdd lmZmZdd lmZmZdd lm Z ddl!m"Z"ddl#m$Z$eej%&e'j(Z)e)dZ*Gddde+Z,ee Gddde+Z-ddZ.dS))absolute_importprint_functionunicode_literalsN)ABCMetaabstractmethod)ArgumentTypeError) literal_eval) OrderedDict)dedent) add_metaclass)LogCmd) WIN_CPYTHON_2)Path safe_delete) ensure_str ensure_text)run_cmd) __version__)PyEnvCfgzdebug.pyc@seZdZddZdS) CreatorMetacCs d|_dSN)errorselfr;/usr/lib/python3/dist-packages/virtualenv/create/creator.py__init__s zCreatorMeta.__init__N)__name__ __module__ __qualname__rrrrrrs rc@seZdZdZddZddZddZdd Zed d Z ed d Z e ddZ eddZ ddZddZddZeddZddZdS)CreatorzEA class that given a python Interpreter creates a virtual environmentcCsJ||_d|_t|j|_|j|_|j|_t|j|_|j |_ |j |_ dS)zConstruct a new virtual environment creator. :param options: the CLI option as parsed from :meth:`add_parser_arguments` :param interpreter: the interpreter to create virtual environment from N) interpreter_debugrdestclear no_vcs_ignorer from_folder pyenv_cfgapp_dataenv)roptionsr"rrrr%s  zCreator.__init__cCs t|Sr)r __unicode__rrrr__repr__4s zCreator.__repr__cCs$d|jjddd|DS)Nz{}({})z, css |] \}}d||VqdS)z{}={}N)format).0kvrrr 8sz&Creator.__unicode__..)r. __class__rjoin_argsrrrrr,7s$zCreator.__unicode__cCs$dtt|jfd|jfd|jfgS)Nr$r%r&)rstrr$r%r&rrrrr5:sz Creator._argscCsdS)aDetermine if we can create a virtual environment. :param interpreter: the interpreter in question :return: ``None`` if we can't create, any other object otherwise that will be forwarded to :meth:`add_parser_arguments` Tr)clsr"rrr can_createAszCreator.can_createcCs>|jdd|jd|jdddddd |jd d dd dd d S)aAdd CLI arguments for the creator. :param parser: the CLI parser :param app_data: the application data folder :param interpreter: the interpreter we're asked to create virtual environment for :param meta: value as returned by :meth:`can_create` r$z!directory to create virtualenv at)helptypez--clearr% store_truezZremove the destination directory if exist before starting (will overwrite files otherwise)F)r$actionr9defaultz--no-vcs-ignorer&z>don't create VCS ignore directive in the destination directoryN) add_argument validate_dest)r7parserr"metar)rrradd_parser_argumentsKs&  zCreator.add_parser_argumentscCst)z)Perform the virtual environment creation.)NotImplementedErrorrrrrcreatehszCreator.createc Csdd}t}t}|dkrddini}t|D]%}z|j|fi||}||kr.Wqt|ty>d||<Yqw|rOtd|d | |t j |vr]td |t j t |}|rp|rptd |d tjkr{d krnn t t j|} n t t jt|} | }| r| rt tt| t jr t|S|| || j| j} } | | kr|| || } | st|S) zANo path separator in the path, valid chars and must be write-ablecSs.ttj|j|jg}td|||)Nz*the destination {} is not write-able at {})rospath commonprefixpartsrr. relative_to)r$valuecommonrrrnon_write_ableqsz-Creator.validate_dest..non_write_ablembcserrorsignoreNzDthe file system codec ({}) cannot handle characters {!r} within {!r}zddestination {!r} must not contain the path separator ({}) as this would break the activation scriptsz/the destination {} already exists and is a file)rQ)rQ)sysgetfilesystemencodingr rencodedecode ValueErrorrr.r4keysrEpathseprexistsis_file version_inforFrealpathabspathr6resolveaccessW_OKparentname) r7 raw_valuerLencodingrefusedkwargschartriprJr$base_rrrr?msZ         zCreator.validate_destcCsN|jr|jrtd|jt|j|||js%| dSdS)Nz delete %s) r$rZr%loggingdebugrrD set_pyenv_cfgr&setup_ignore_vcsrrrrruns  z Creator.runcCsRt|j_|jj|jd<|jj|jd<ddd|jjD|jd<t|jd<dS)Nhomeimplementation.css|]}t|VqdSr)r6r/irrrr2sz(Creator.set_pyenv_cfg..r\ virtualenv) r r(contentr"system_exec_prefixrrr4r\rrrrrrns zCreator.set_pyenv_cfgcCs,|jd}|s|tddSdS)z9Generate ignore instructions for version control systems.z .gitignoreze # created by virtualenv automatically * N)r$rZ write_textr lstrip)r git_ignorerrrros zCreator.setup_ignore_vcscCs4|jdur|jdurt|j||j|j|_|jS)zt :return: debug information about the virtual environment (only valid after :meth:`create` has run) N)r#exeget_env_debug_info debug_scriptr)r*rrrrrmsz Creator.debugcCstSr) DEBUG_SCRIPTrrrrr~szCreator.debug_scriptN)rrr __doc__rr-r,r5 classmethodr8rBrrDr?rprnropropertyrmr~rrrrr!!s(    9   r!c Cs|}|tdd||*}t|t|g}tr#dd|D}ttdt|t|\}}}Wdn1s>wYz|dkrMt |}nt |}|rX||d<Wnt yt} z|||t | dWYd} ~ Sd} ~ wwd|vrd |dvr|dd d=|S) N PYTHONPATHcSsg|]}t|qSr)rrtrrr sz&get_env_debug_info..z debug via %rrerr)outr returncode exceptionrSrF)copypopr6ensure_extractedr rlrmr rrjsonloads Exceptionrepr) env_exer~r)r*cmdcoderrresultrrrrr}s.   r})/ __future__rrrrrlrErSabcrrargparserastr collectionsr textwrapr sixr #virtualenv.discovery.cached_py_infor virtualenv.infor virtualenv.util.pathrrvirtualenv.util.sixrrvirtualenv.util.subprocessrvirtualenv.versionrr(rrFr^__file__rbHERErobjectrr!r}rrrrs2           7