o
    VhV                     @  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 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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l'm(Z( d dl'm)Z) erd dl*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1 d dl2m3Z3 d dl4m5Z5 d dl6m7Z7 d dl8m9Z9 d/d#d$Z:g d%Z;d&Z<d'd(iZ=G d)d* d*eZd0d,d-Z>e?d.kre>  dS dS )1    )annotationsN)suppress)import_module)Path)TYPE_CHECKING)cast)find_similar_names)Application)ConsoleCommandEvent)COMMAND)EventDispatcher)CleoCommandNotFoundError)	CleoError)Style)	ArgvInput)__version__)CommandLoader)Command)PoetryRuntimeError)	directory)ensure_path)Callable)Event)
Definition)Input)IO)OutputInstallerCommand)PoetrynamestrreturnCallable[[], Command]c                   s   d fdd}|S )Nr"   r   c                    sD     d} tdd|  }t|ddd | D d }| }|S )N zpoetry.console.commands.. c                 s  s    | ]}|  V  qd S N)title).0c r+   n/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/poetry/console/application.py	<genexpr>/   s    z.load_command.<locals>._load.<locals>.<genexpr>r   )splitr   joingetattr)wordsmodulecommand_classcommandr    r+   r,   _load,   s
   
zload_command.<locals>._load)r"   r   r+   )r    r6   r+   r5   r,   load_command+   s   r7   ))aboutaddbuildcheckconfiginitinstalllocknewpublishremoverunsearchshowsyncupdateversionzcache clearz
cache listz
debug infozdebug resolvez
debug tagszenv activatezenv infozenv listz
env removezenv usezpython installzpython listzpython removezself addzself installz	self lockzself removezself updatez	self showzself show pluginsz	self syncz
source addzsource removezsource showzGLooks like you're trying to use a Poetry command that is not available.shella  
Since <info>Poetry (<b>2.0.0</>)</>, the <c1>shell</> command is not installed by default. You can use,

  - the new <c1>env activate</> command (<b>recommended</>); or
  - the <c1>shell plugin</> to install the <c1>shell</> command

<b>Documentation:</> https://python-poetry.org/docs/managing-environments/#activating-the-environment

<warning>Note that the <c1>env activate</> command is not a direct replacement for <c1>shell</> command.
c                      s   e Zd Zd@ fddZedA fddZedBd	d
ZedCddZedDddZd@ddZ				dEdF fddZ
dG fddZ	dHdId$d%ZdJd&d'ZdJd(d)ZdJd*d+ZdJ fd,d-ZdKd4d5ZdKd6d7ZedKd8d9ZedLd<d=ZdJd>d?Z  ZS )Mr	   r"   Nonec                   s   t  dt d | _d | _d| _d| _d| _t	 | _
d | _t }|t| j |t| j |t| j | | tdd tD }| | d S )NpoetryFc                 S  s   i | ]}|t |qS r+   )r7   r)   r    r+   r+   r,   
<dictcomp>   s    z(Application.__init__.<locals>.<dictcomp>)super__init__r   _poetry_io_disable_plugins_disable_cache_plugins_loadedr   cwd_working_directory_project_directoryr   add_listenerr   register_command_loggersconfigure_envconfigure_installer_for_eventset_event_dispatcherr   COMMANDSset_command_loader)self
dispatchercommand_loader	__class__r+   r,   rO   }   s   

zApplication.__init__r   c                   sl   ddl m} t j}||dddd ||dddd ||d	d
ddd ||ddddd |S )Nr   )Option--no-pluginsTzDisables plugins.)flagdescriptionz
--no-cachezDisables Poetry source caches.z	--projectz-PFzSpecify another path as the project root. All command-line arguments will be resolved relative to the current working directory.z--directoryz-CzThe working directory for the Poetry command (defaults to the current working directory). All command-line arguments will be resolved relative to the given directory.)cleo.io.inputs.optionrd   rN   _default_definition
add_option)r_   rd   
definitionrb   r+   r,   ri      s6   zApplication._default_definitionr   c                 C  s   | j p| jS r'   )rW   rV   r_   r+   r+   r,   project_directory   s   zApplication.project_directoryr   c                 C  s@   ddl m} | jd ur| jS | j| j| j| j| jd| _| jS )Nr   )Factory)rU   iodisable_pluginsdisable_cache)poetry.factoryrn   rP   create_poetryrm   rQ   rR   rS   )r_   rn   r+   r+   r,   rK      s   
zApplication.poetryr   c                 C  s   | j }t|ts
J |S r'   )_command_loader
isinstancer   )r_   ra   r+   r+   r,   ra      s   zApplication.command_loaderc                 C  s
   d | _ d S r'   )rP   rl   r+   r+   r,   reset_poetry   s   
zApplication.reset_poetryNinputInput | NoneoutputOutput | Noneerror_outputr   c                   s   t  |||}|jj}|dtd |dtddgd |dtd |d	td
 |dtd |dtddgd |dtd
 |dtddgd |dtdddgd |dtd
dgd |j| |j| || _|S )Nc1cyanc2defaultbold)optionsinfobluecommentgreenwarningyellowdebugdarksuccessc1_darkc2_darksuccess_dark)	rN   	create_iory   	formatter	set_styler   set_formatterr{   rQ   )r_   rw   ry   r{   ro   r   rb   r+   r,   r      s    zApplication.create_ioro   intc           	        s  |  | | | d}t| j zt |}W n ty; } z|d || |d W Y d }~nd }~w t	y } z| 
|}|d urnt| }rn|d |t || W Y d }~W d    dS |d ur||  v rg }| jD ]}|| dr|| q}|d| d t||}| ||d|  W Y d }~W d    dS |d urt|t| j }|d| d | || W Y d }~W d    dS |d }~ww W d    |S W d    |S 1 sw   Y  |S )	N   r&   r$   z0The requested command does not exist in the <c1>z</> namespace.#zThe requested command <c1>z</> does not exist.)_configure_global_options_load_pluginsr   rV   rN   _runr   write_error_linewriter   _get_command_nameCOMMAND_NOT_FOUND_MESSAGESget COMMAND_NOT_FOUND_PREFIX_MESSAGEget_namespaces	_commands
startswithappendr    _error_write_command_suggestionslistkeys)	r_   ro   	exit_codeer4   messagesub_commandskeysuggested_namesrb   r+   r,   r      sr   













"

,
.
..zApplication._runr   	list[str]doc_tag
str | Nonec                   sT   |r fdd|D }d dgt|}|d|  |d|p#d d d S )Nc                   s.   g | ]}d | ddd d j| j qS )z<c1>r$   z</> <b>r   z</>: )replacer   rg   rL   rl   r+   r,   
<listcomp>6  s     z@Application._error_write_command_suggestions.<locals>.<listcomp>z
    r&   z-
<error>Did you mean one of these perhaps?</>z?
<b>Documentation: </><info>https://python-poetry.org/docs/cli/</>)r/   sortedr   )r_   ro   r   r   suggestion_linessuggestionsr+   rl   r,   r   2  s   
z,Application._error_write_command_suggestionsc                 C  s   |j d| _|j d| _t|j dpt dd| _|j d| _| jdurIt| j| _t| j	 r8| jn
| j
| jjdd	dd| _dS dS )
a  
        Configures global options for the application by setting up the relevant
        directories, disabling plugins or cache, and managing the working and
        project directories. This method ensures that all directories are valid
        paths and handles the resolution of the project directory relative to the
        working directory if necessary.

        :param io: The IO instance whose input and options are being read.
        :return: Nothing.
        z
no-pluginszno-cacher   T)is_directoryprojectNF)strict)rw   optionrR   rS   r   r   rU   rV   rW   is_absolutejoinpathresolver_   ro   r+   r+   r,   r   D  s"   
z%Application._configure_global_optionsc                 C  sP  t d|j}|j}tjdd}| jjD ]"}|jd|j g|j	r'd|j	 gng R d|
 r1dndi q||\}}g }| jjD ])}|jdd	}t||d
}	|	d
url|	ra|d|j  | rl|t|	 qCt| jprdg||}
|
|j |
|j  tt |
| j W d
   n1 sw   Y  ||
 d
S )a>  
        Sorts global options of the provided IO instance according to the
        definition of the available options, reordering and parsing arguments
        to ensure consistency in input handling.

        The function interprets the options and their corresponding values
        using an argument parser, constructs a sorted list of tokens, and
        recreates the input with the rearranged sequence while maintaining
        compatibility with the initially provided input stream.

        If using in conjunction with `_configure_run_command`, it is recommended that
        it be called first in order to correctly handling cases like
        `poetry run -V python -V`.

        :param io: The IO instance whose input and options are being processed
                   and reordered.
        :return: Nothing.
        r   F)add_help---action
store_truestore_Nr&   )r   rw   _tokensargparseArgumentParserrk   r   add_argumentr    shortcutis_flagparse_known_argsr   r0   r   accepts_valuer!   r   _name
set_streamstreaminteractiveis_interactiver   r   bind	set_input)r_   ro   original_inputtokensparserr   argsremaining_argsr   valuesorted_inputr+   r+   r,   _sort_global_optionsd  s:   

z Application._sort_global_optionsc                 C  s  t t |j| j W d   n1 sw   Y  |jj}|dkrtd|j}|j}d|v r3dS ||}|t	|d k rzt
| jpFdg|d|d  | jd}W n2 ty}   z|||d d |d 7 }W n tyz   t	|}Y nw Y nw |t	|d k s@dS ||d d }t
| jpdg|d}t t || j W d   n1 sw   Y  |j}	|	r||	nd| d }
t
| jpdg|d| ||d |
 |d||
d }||j t t || j W d   n	1 sw   Y  || dS dS )	a  
        Configures the input for the "run" command to properly handle cases where the user
        executes commands such as "poetry run -- <subcommand>". This involves reorganizing
        input tokens to ensure correct parsing and execution of the run command.
        NrC   r   r   r   r&   )rk   r   )r   r   rw   r   rk   first_argumentr   r   indexlenr   r   
ValueErrorr   r   r   )r_   ro   command_namer   r   command_indexr   tokens_without_commandwithout_command
subcommandsubcommand_index	run_inputr+   r+   r,   _configure_run_command  s~   







z"Application._configure_run_commandc                   s$   |  | | | t | d S r'   )r   r   rN   _configure_ior   rb   r+   r,   r     s   

zApplication._configure_ioeventr   
event_namer!   r   r   c                 C  s  ddl m} ddlm} ddlm} t|tsJ |j}t|t	s#d S |j
}g d}	|	|j7 }	||}
|
|  tj}| rDtj}n| sL| rOtj}tj||
gd | s`|
| |	D ]}t|}|}|jdry|tjkrytj}|| qbd S )Nr   )POETRY_FILTER)IOFormatter)	IOHandler)zpoetry.packages.lockerzpoetry.packages.packagezpoetry.utils.password_manager)levelhandlerszpoetry.core.masonry.builders)poetry.console.logging.filtersr   #poetry.console.logging.io_formatterr   !poetry.console.logging.io_handlerr   ru   r
   r4   r   ro   loggerssetFormatterloggingWARNINGis_debugDEBUGis_very_verbose
is_verboseINFObasicConfig	addFilter	getLoggerr    r   setLevel)r_   r   r   r   r   r   r   r4   ro   r   handlerr   r    logger_levelr+   r+   r,   rY     s:   





z$Application.register_command_loggersc                 C  s   ddl m} ddlm} t|tsJ |j}t||r t||r"d S |jd ur)d S ddlm	} |j
}|j}	||	|d}
|
 }| rQ| rQ|d|j d || d S )Nr   )
EnvCommand)SelfCommand)
EnvManager)ro   zUsing virtualenv: <comment>r   )#poetry.console.commands.env_commandr  )poetry.console.commands.self.self_commandr  ru   r
   r4   _envpoetry.utils.envr  ro   rK   create_venvis_venvr   
write_linepathset_env)r_   r   r   r   r  r  r4   r  ro   rK   env_managerenvr+   r+   r,   rZ   3  s    
zApplication.configure_envc                 C  sN   ddl m} t|tsJ |j}t||sd S |jd urd S | ||j d S )Nr   r   ))poetry.console.commands.installer_commandr   ru   r
   r4   
_installerconfigure_installer_for_commandro   )clsr   r   r   r   r4   r+   r+   r,   r[   L  s   

z)Application.configure_installer_for_eventr4   r   c              	   C  sB   ddl m} | j}||| j|j|j|j|j|jd}| 	| d S )Nr   )	Installer)rq   )
poetry.installation.installerr  rK   r  packagelockerpoolr<   rq   set_installer)r4   ro   r  rK   	installerr+   r+   r,   r  ^  s   	z+Application.configure_installer_for_commandc                 C  sh   | j rd S |jd| _| js/ddlm} ddlm} || j	 ||j
}|  ||  d| _ d S )Nre   r   )ApplicationPlugin)PluginManagerT)rT   rw   has_parameter_optionrR   !poetry.plugins.application_pluginr  poetry.plugins.plugin_managerr  add_project_plugin_pathrm   groupload_pluginsactivate)r_   ro   r  r  managerr+   r+   r,   r   n  s   


zApplication._load_plugins)r"   rJ   )r"   r   )r"   r   )r"   r   )r"   r   )NNN)rw   rx   ry   rz   r{   rz   r"   r   )ro   r   r"   r   r'   )ro   r   r   r   r   r   r"   rJ   )ro   r   r"   rJ   )r   r   r   r!   r   r   r"   rJ   )r4   r   ro   r   r"   rJ   )__name__
__module____qualname__rO   propertyri   rm   rK   ra   rv   r   r   r   r   r   r   r   rY   rZ   classmethodr[   staticmethodr  r   __classcell__r+   r+   rb   r,   r	   |   s:    *
<

 
<Z

4r	   r   c                  C  s   t   } | S r'   )r	   rC   )r   r+   r+   r,   main  s   
r+  __main__)r    r!   r"   r#   )r"   r   )@
__future__r   r   r   
contextlibr   	importlibr   pathlibr   typingr   r   cleo._utilsr   cleo.applicationr	   BaseApplication!cleo.events.console_command_eventr
   cleo.events.console_eventsr   cleo.events.event_dispatcherr   cleo.exceptionsr   r   cleo.formatters.styler   cleo.io.inputs.argv_inputr   poetry.__version__r   poetry.console.command_loaderr   poetry.console.commands.commandr   poetry.console.exceptionsr   poetry.utils.helpersr   r   collections.abcr   cleo.events.eventr   cleo.io.inputs.definitionr   cleo.io.inputs.inputr   
cleo.io.ior   cleo.io.outputs.outputr   r  r   poetry.poetryr   r7   r]   r   r   r+  r$  r+   r+   r+   r,   <module>   s^    
6    

