a :i< @sddlZddlZddlZddlZddlmZmZddlmZddl m Z ddl m Z ddl mZddlmZddlmZdd lmZdd lmZd d lmZeejejZed ZGdddZGdddedZ ddZ!ddgZ"dS)N)ABCMetaabstractmethod)ArgumentTypeError) literal_eval) OrderedDict)Path)LogCmd) safe_delete)run_cmd) __version__)PyEnvCfgzdebug.pyc@seZdZddZdS) CreatorMetacCs d|_dSN)errorselfr=/usr/lib/python3.9/site-packages/virtualenv/create/creator.py__init__szCreatorMeta.__init__N)__name__ __module__ __qualname__rrrrrrsrc@seZdZdZddZddZddZedd Zed d Z e d d Z eddZ ddZ ddZddZeddZeddZdS)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 Z from_folder pyenv_cfgapp_dataenv)roptionsrrrrrs zCreator.__init__cCs(|jjdddd|DdS)N(z, css |]\}}|d|VqdS)=Nr).0kvrrr .z#Creator.__repr__..)) __class__rjoin_argsrrrr__repr__-szCreator.__repr__cCs dt|jfd|jfd|jfgS)Nrrr)strrrrrrrrr-0s z 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)clsrrrr can_create7szCreator.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` rz!directory to create virtualenv at)helptypez--clearr store_truezZremove the destination directory if exist before starting (will overwrite files otherwise)F)ractionr2defaultz--no-vcs-ignorerz>don't create VCS ignore directive in the destination directoryN) add_argument validate_dest)r0parserrmetar rrradd_parser_argumentsAs& zCreator.add_parser_argumentscCstdS)z)Perform the virtual environment creation.N)NotImplementedErrorrrrrcreate^szCreator.createc Csdd}t}t}|dkr&ddini}t|D]P}z0|j|fi||}||kr\Wq2t|Wq2tyd||<Yq20q2|rd|}d|d |d |} t | t j |vrd |d t j d } t | dt |} | r | r t d| dt t jt| } | } | r| r\t t| t jrRqn || | | j| j} } | | kr~|| | | } q(t| S)zANo path separator in the path, valid chars and must be write-ablecSs6ttj|j|jg}td||d|dS)Nthe destination z is not write-able at )rospath commonprefixpartsr relative_to)rvaluecommonrrrnon_write_ablegsz-Creator.validate_dest..non_write_ablembcserrorsignoreNzthe file system codec (z) cannot handle characters z within z destination z& must not contain the path separator (r*z+ as this would break the activation scriptsr>z already exists and is a file)sysgetfilesystemencodingrr/encodedecode ValueErrorr,keysrr?pathseprexistsis_filer@abspathresolveaccessW_OKparentname)r0Z raw_valuerFencodingZrefusedkwargscharZtripZbadmsgrDrbase_rrrr8csD        zCreator.validate_destcCsJ|jr(|jr(td|jt|j|||jsF| dS)Nz delete %s) rrRrloggingdebugr r= set_pyenv_cfgrsetup_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(r)z(Creator.set_pyenv_cfg.. version_infoZ virtualenv) rrZcontentr?r@dirnamerTrZsystem_executablerfr,rir rrrrrbs  zCreator.set_pyenv_cfgcCs$|jd}|s |jddddS)z9Generate ignore instructions for version control systems.z .gitignorez(# created by virtualenv automatically * zutf-8)rZN)rrR write_text)rZ git_ignorerrrrcs zCreator.setup_ignore_vcscCs4|jdur.|jdur.t|j||j|j|_|jS)zt :return: debug information about the virtual environment (only valid after :meth:`create` has run) N)rZexeget_env_debug_info debug_scriptr r!rrrrrasz Creator.debugcCstSr) DEBUG_SCRIPTrrrrrmszCreator.debug_scriptN)rrr__doc__rr.r- classmethodr1r;rr=r8rdrbrcpropertyra staticmethodrmrrrrrs&    -   r) metaclassc Cs"|}|dd||>}t|t|g}tdt|t|\}}}Wdn1sb0YzR|dkr|rt|}q|dkrd|vrt |t |n t |}|r||d<Wn8t y} z|||t | dWYd} ~ Sd} ~ 00d|vrd |dvr|dd d=|S) NZ PYTHONPATHz debug via %rrfileerr)outrv returncode exceptionrKr@)copypopZensure_extractedr/r`rarr rOSError Exceptionjsonloadsrepr) Zenv_exermr r!cmdcoderwrvresultryrrrrls*  ,    (rl)#r~r`r?rKabcrrargparserastr collectionsrpathlibrZ#virtualenv.discovery.cached_py_inforZvirtualenv.util.pathr Zvirtualenv.util.subprocessr Zvirtualenv.versionr rr r@rT__file__rXZHERErnrrrl__all__rrrrs,         !