U e0!@sddlmZddlZddlZddlZddlZddlmZmZddl m Z ddl m Z ddl mZddlmZddlmZdd lmZdd lmZdd lmZd d lmZeejejZedZ GdddZ!GdddeZ"ddZ#ddgZ$dS)) annotationsN)ABCabstractmethod)ArgumentTypeError) literal_eval) OrderedDict)Path)LogCmd) safe_delete)run_cmd) __version__)PyEnvCfgzdebug.pyc@seZdZddddZdS) CreatorMetaNonereturncCs d|_dSN)errorselfrG/opt/hc_python/lib/python3.8/site-packages/virtualenv/create/creator.py__init__szCreatorMeta.__init__N)__name__ __module__ __qualname__rrrrrrsrc@seZdZdZddddZddddZd d Zed d Zed dZ e ddZ eddZ ddZ ddZddZeddZeddZdS)CreatorzFA class that given a python Interpreter creates a virtual environment.rrcCsJ||_d|_t|j|_|j|_|j|_t|j|_|j |_ |j |_ dS)z Construct 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_ignorerZ from_folder pyenv_cfgapp_dataenv)roptionsrrrrr s zCreator.__init__strcCs(|jjdddd|DdS)N(z, css |]\}}|d|VqdS)=Nr).0kvrrr 1sz#Creator.__repr__..)) __class__rjoin_argsrrrr__repr__0szCreator.__repr__cCs dt|jfd|jfd|jfgS)Nr r!r")r'r r!r"rrrrr13s z Creator._argscCsdS)a Determine 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)clsrrrr can_create:s zCreator.can_createcCs>|jdd|jd|jdddddd |jd d dd dd d S)a' Add 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 actionr5defaultz--no-vcs-ignorer"z>don't create VCS ignore directive in the destination directoryN) add_argument validate_dest)r3parserrmetar$rrradd_parser_argumentsEs& zCreator.add_parser_argumentscCstdS)z)Perform the virtual environment creation.N)NotImplementedErrorrrrrcreatecszCreator.createc Csdd}t}t}|dkr&ddini}t|D]N}z,|j|f||}||krXWq2t|Wq2tk r~d||<Yq2Xq2|rd|}d|d |d |} t | t j |krd |d t j d } t | t |} | r| rd| d} t | t t jt| } | } | r| rVt t| t jrLq|| | | j| j} } | | krx|| | | } q$t| S)zBNo path separator in the path, valid chars and must be write-able.cSs:ttj|j|jg}d||d|}t|dS)Nthe destination z is not write-able at )rospath commonprefixparts relative_tor)r valuecommonmsgrrrnon_write_ablelsz-Creator.validate_dest..non_write_ablembcserrorsignoreNzthe file system codec (z) cannot handle characters z within z destination z& must not contain the path separator (z,) as this would break the activation scriptsrAz already exists and is a file)sysgetfilesystemencodingrr'encodedecode ValueErrorr0keysrrBpathseprexistsis_filerCabspathresolveaccessW_OKparentname)r3Z raw_valuerJencodingZrefusedkwargscharZtripbadrIrGr base_rrrr;hsH        zCreator.validate_destcCsJ|jr(|jr(td|jt|j|||jsF| dS)Nz delete %s) r rVr!loggingdebugr r@ set_pyenv_cfgr"setup_ignore_vcsrrrrruns z Creator.runcCsbt|j_tjtj|jj|jd<|jj |jd<d dd|jj D|jd<t |jd<dS)Nhomeimplementation.css|]}t|VqdSr)r')r*irrrr-sz(Creator.set_pyenv_cfg.. version_info virtualenv) rr#contentrBrCdirnamerXrZsystem_executablerjr0rmr rrrrrfs  zCreator.set_pyenv_cfgcCs$|jd}|s |jddddS)z9Generate ignore instructions for version control systems.z .gitignorez(# created by virtualenv automatically * zutf-8)r^N)r rV write_text)rZ git_ignorerrrrgs zCreator.setup_ignore_vcscCs4|jdkr.|jdk r.t|j||j|j|_|jS)zb:return: debug information about the virtual environment (only valid after :meth:`create` has run)N)rexeget_env_debug_info debug_scriptr$r%rrrrresz Creator.debugcCstSr) DEBUG_SCRIPTrrrrrtszCreator.debug_scriptN)rrr__doc__rr2r1 classmethodr4r>rr@r;rhrfrgpropertyre staticmethodrtrrrrrs&    1   rc Cs|}|dd||4}t|t|g}tdt|t|\}}}W5QRXzR|dkr|rpt|} q|dkrd|krt |t |n t |} |r|| d<Wn8t k r} z|||t | dWYSd} ~ XYnXd| kr d | dkr | dd d=| S) N PYTHONPATHz debug via %rrfileerr)outr} returncode exceptionrOrC)copypopZensure_extractedr'rdrer r rOSError Exceptionjsonloadsrepr) Zenv_exertr$r%Zdebug_script_extractedcmdcoder~r}resultrrrrrss*      (rs)% __future__rrrdrBrOabcrrargparserastr collectionsrpathlibrZ#virtualenv.discovery.cached_py_infor Zvirtualenv.util.pathr Zvirtualenv.util.subprocessr Zvirtualenv.versionr r#rrCrX__file__r\ZHERErurrrs__all__rrrrs.          &