o
    Vh$                     @  sx   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r2d dlmZ d dlmZ G d	d
 d
eZdS )    )annotations)TYPE_CHECKING)ClassVar)argument)
EnvCommand)WINDOWS)ArgumentModulec                   @  sZ   e Zd ZU dZdZeddddgZded< dddZe	dddZ
dddZdddZdS )
RunCommandrunz.Runs a command in the appropriate environment.argsz)The command and arguments/options to run.T)multiplezClassVar[list[Argument]]	argumentsreturnintc                 C  sr   |  d}|d }| jjd}|r||v r| || |S z| jj| W S  ty8   | d| d Y dS w )Nr   r   scriptsz<error>Command not found: <c1>z</c1></error>   )	r   poetrylocal_configget
run_scriptenvexecuteFileNotFoundError
line_error)selfr   scriptr    r   o/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/poetry/console/commands/run.pyhandle   s   
zRunCommand.handler
   c                 C  s:   ddl m} | j}|j}|jjj}||j| |j	}|S )Nr   r	   )
 poetry.core.masonry.utils.moduler
   r   packagefilepathparentnameas_posixpackages)r   r
   r   r"   r$   moduler   r   r   _module'   s   
zRunCommand._moduler   str | dict[str, str]	list[str]c           	   
   C  s   | j jD ] }||d  }tr|d}| r$t|g|dd } nq| |d  t|tr5|d }|	d\}}| j
 rCdnd}d	d
g}|d|d| d| d| d	g7 }| j j| S )a  Runs an entry point script defined in the section ``[tool.poetry.scripts]``.

        When a script exists in the venv bin folder, i.e. after ``poetry install``,
        then ``sys.argv[0]`` must be set to the full path of the executable, so
        ``poetry run foo`` and ``poetry shell``, ``foo`` have the same ``sys.argv[0]``
        that points to the full path.

        Otherwise (when an entry point script does not exist), ``sys.argv[0]`` is the
        script name only, i.e. ``poetry run foo`` has ``sys.argv == ['foo']``.
        r   z.cmdr   Ncallable:zsys.path.append('src');  pythonz-cz<import sys; from importlib import import_module; sys.argv = z; zsys.exit(import_module('z').z()))r   script_dirsr   with_suffixexistsstr_warning_not_installed_script
isinstancedictsplitr*   	is_in_srcr   )	r   r   r   
script_dirscript_pathr)   	callable_src_in_sys_pathcmdr   r   r   r   2   s4   

zRunCommand.run_scriptr4   Nonec                 C  s   d| d}| j |dd d S )Nz
Warning: 'a  ' is an entry point defined in pyproject.toml, but it's not installed as a script. You may get improper `sys.argv[0]`.

The support to run uninstalled scripts will be removed in a future release.

Run `poetry install` to resolve and get rid of this message.
warning)style)r   )r   r   messager   r   r   r5   Z   s   z(RunCommand._warning_not_installed_scriptN)r   r   )r   r
   )r   r+   r   r,   r   r   )r   r4   r   r?   )__name__
__module____qualname__r&   descriptionr   r   __annotations__r    propertyr*   r   r5   r   r   r   r   r      s   
 


(r   N)
__future__r   typingr   r   cleo.helpersr   #poetry.console.commands.env_commandr   poetry.utils._compatr   cleo.io.inputs.argumentr   r!   r
   r   r   r   r   r   <module>   s    