o
    Uhd                     @  s   d dl 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dgZ#dS )#    )annotationsN)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   k/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/virtualenv/run/__init__.pycli_run   s   


r   c           	        sb   |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>3   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   %   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 rBd| }t|t||t||t||g}|| \}}	|D ]}
|
| qY|  ||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'   RuntimeErrorr   r   r   parse_known_argshandle_selected_arg_parseenable_help)r   r   r   r   r(   discoverr8   msgr)   _elementr   r   r   r"   >   s4   

r"   c                 C  s   t | d S )z0Used to provide a parser for the doc generation.r   )r"   )r   r   r   r   build_parser_only]   s   rA   c                 C  s    | j rt| j| j}t|d S r   )upgrade_embed_wheelsr	   r&   r   
SystemExit)r   resultr   r   r   r7   b   s   r7   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-datar.   zMuse app data folder in read-only mode (write operations will fail with error))r0   r2   )	namespacez
--app-dataz-a data folder used as cache by the virtualenv)	read_onlyr   )r2   typer1   z--reset-app-dataz start with empty app data folderz--upgrade-embed-wheelsz.trigger a manual update of the embedded wheels)	r4   r:   r   r   read_only_app_datar   reset_app_datar&   reset)r   r(   r   r?   r   r   r   r6   h   s4   
r6   c                 C  s,   dd l }| jdddt d|j dd d S )Nr   z	--versionversionz	%(prog)s z from zIdisplay the version of the virtualenv package and its location, then exit)r0   rK   r2   )
virtualenvr4   r
   __file__)r(   rL   r   r   r   r3      s   
r3   c           	      C  s   d dd 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 | 
|\}}|rJt|j d S d S )Nz, c                 s  s(    | ]\}}t | d | V  qdS )=N)logginggetLevelName)r   cliner   r   r   r!      s   & z#_do_report_setup.<locals>.<genexpr>z6verbosity = verbose - quiet, default {}, mapping => {}r%      )titledescriptionz-vz	--verbosecountverbosezincrease verbosity   )r0   r/   r2   r1   z-qz--quietquietzdecrease verbosityr   )joinsortedr   itemsadd_argument_groupformatrO   rP   add_mutually_exclusive_groupr4   r:   r   r%   )	r(   r   r   	level_mapr>   verbosity_groupr%   optionr?   r   r   r   r5      s   r5   )NTN)NNTNr   )$
__future__r   rO   r   	functoolsr   virtualenv.app_datar   virtualenv.config.cli.parserr   virtualenv.reportr   r   virtualenv.run.sessionr   &virtualenv.seed.wheels.periodic_updater	   virtualenv.versionr
   plugin.activatorsr   plugin.creatorsr   plugin.discoveryr   plugin.seedersr   r   r   r"   rA   r7   r6   r3   r5   __all__r   r   r   r   <module>   s2    



