o
    $¼"bÊ  ã                   @   sø   d dl mZmZ d dlZd dlZd dlmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ d"dd„Zd"dd„Zd#dd„Zd$dd„Zdd„ Z dd„ Z!dd„ Z"dd „ Z#d!Z$dS )%é    )Úabsolute_importÚunicode_literalsN)Úpartialé   )Úmake_app_data)ÚVirtualEnvConfigParser)ÚLEVELSÚsetup_report)ÚSession)Úmanual_upgrade)Ú__version__é   )ÚActivationSelector)ÚCreatorSelector)Úget_discover)ÚSeederSelectorTc                 C   sR   |du rt jn|}t| |||ƒ}|� | ¡  W d  ƒ |S 1 s"w   Y  |S )aó  
    Create a virtual environment given some command line interface arguments.

    :param args: the command line arguments
    :param options: passing in a ``VirtualEnvOptions`` object allows return of the parsed options
    :param setup_logging: ``True`` if setup logging handlers, ``False`` to use handlers already registered
    :param env: environment variables to use
    :return: the session object of the creation (its structure for now is experimental and might change on short notice)
    N)ÚosÚenvironÚsession_via_cliÚrun)ÚargsÚoptionsÚsetup_loggingÚenvÚ
of_session© r   ú9/usr/lib/python3/dist-packages/virtualenv/run/__init__.pyÚcli_run   s   


ÿþr   c           
         sf   |du rt jn|}t| ˆ ||ƒ\}}| | ¡‰ t‡ fdd„|D ƒƒ\}}}tˆ jˆ j|j|||ƒ}	|	S )aq  
    Create a virtualenv session (same as cli_run, but this does not perform the creation). Use this if you just want to
    query what the virtual environment would look like, but not actually create it.

    :param args: the command line arguments
    :param options: passing in a ``VirtualEnvOptions`` object allows return of the parsed options
    :param setup_logging: ``True`` if setup logging handlers, ``False`` to use handlers already registered
    :param env: environment variables to use
    :return: the session object of the creation (its structure for now is experimental and might change on short notice)
    Nc                 3   s   � | ]}|  ˆ ¡V  qd S ©N)Úcreate)Ú.0Úe©r   r   r   Ú	<genexpr>2   s   € z"session_via_cli.<locals>.<genexpr>)	r   r   Úbuild_parserÚ
parse_argsÚtupler
   Ú	verbosityÚapp_dataÚ_interpreter)
r   r   r   r   ÚparserÚelementsÚcreatorÚseederÚ
activatorsr   r   r"   r   r   $   s   
r   c           
      C   sÎ   t ||d u r	tjn|ƒ}t|ƒ |jdddddd� t|| |ƒ t| ||ƒ}t|ƒ t|| ƒ}|j	 |_
}|d u r@td |¡ƒ‚t||ƒt||ƒt||ƒg}| | ¡\}}|D ]}	|	 |¡ qW| ¡  ||fS )Nz--with-tracebackÚwith_tracebackÚ
store_trueFz>on failure also display the stacktrace internals of virtualenv)ÚdestÚactionÚdefaultÚhelpz!failed to find interpreter for {})r   r   r   Úadd_version_flagÚadd_argumentÚ_do_report_setupÚload_app_dataÚhandle_extra_commandsr   Úinterpreterr)   ÚRuntimeErrorÚformatr   r   r   Úparse_known_argsÚhandle_selected_arg_parseÚenable_help)
r   r   r   r   r*   Údiscoverr:   r+   Ú_Úelementr   r   r   r$   7   s2   û
ýr$   c                 C   s   t | ƒd S )z/Used to provide a parser for the doc generationr   )r$   )r   r   r   r   Úbuild_parser_onlyU   s   rC   c                 C   s    | j rt| j| jƒ}t|ƒ‚d S r   )Úupgrade_embed_wheelsr   r(   r   Ú
SystemExit)r   Úresultr   r   r   r9   Z   s   þr9   c              	   C   s–   |j dddd� |j| |d�\}}|j ddtt|j|jd�td |j|jd�d	� |j d
ddd� |j dddd� |j| |d�\}}|jrI|j ¡  |S )Nz--read-only-app-datar0   zMuse app data folder in read-only mode (write operations will fail with error))r2   r4   )Ú	namespacez
--app-dataz-a data folder used as cache by the virtualenv)Ú	read_onlyr   )r4   Útyper3   z--reset-app-dataz start with empty app data folderz--upgrade-embed-wheelsz.trigger a manual update of the embedded wheels)	r6   r=   r   r   Úread_only_app_datar   Úreset_app_datar(   Úreset)r   r*   r   rA   r   r   r   r8   `   s4   ýüýý
r8   c                 C   s(   dd l }| jddd t|j¡dd� d S )Nr   z	--versionÚversionz%(prog)s {} from {}zIdisplay the version of the virtualenv package and its location, then exit)r2   rM   r4   )Ú
virtualenvr6   r<   r   Ú__file__)r*   rN   r   r   r   r5      s   
ür5   c           	      C   sœ   d  dd„ ttt ¡ ƒƒD ƒ¡}d}| jd| t td ¡|¡d�}| 	¡ }|j
dd	d
dddd� |j
ddd
dddd� |  |¡\}}|rLt|jƒ d S d S )Nz, c                 s   s&   � | ]\}}d   t |¡|¡V  qdS )z{}={}N)r<   ÚloggingÚgetLevelName)r    ÚcÚlr   r   r   r#   ‹   s   €$ z#_do_report_setup.<locals>.<genexpr>z6verbosity = verbose - quiet, default {}, mapping => {}r'   é   )ÚtitleÚdescriptionz-vz	--verboseÚcountÚverbosezincrease verbosityr   )r2   r1   r4   r3   z-qz--quietÚquietzdecrease verbosityr   )ÚjoinÚsortedÚlistr   ÚitemsÚadd_argument_groupr<   rP   rQ   Úadd_mutually_exclusive_groupr6   r=   r	   r'   )	r*   r   r   Ú	level_mapÚmsgÚverbosity_groupr'   ÚoptionrA   r   r   r   r7   Š   s    þÿr7   )r   r   )NTN)NNTNr   )%Ú
__future__r   r   rP   r   Ú	functoolsr   r(   r   Úconfig.cli.parserr   Úreportr   r	   Úrun.sessionr
   Úseed.wheels.periodic_updater   rM   r   Úplugin.activatorsr   Úplugin.creatorsr   Úplugin.discoveryr   Úplugin.seedersr   r   r   r$   rC   r9   r8   r5   r7   Ú__all__r   r   r   r   Ú<module>   s.    



