o
    Vh)                     @  s`  d dl mZ d dl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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" e
rd dl#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z* e+e! G dd deZ,G dd dZ-dS )    )annotationsN)cached_property)Path)TYPE_CHECKING)
NamedTuple)cast)overload)NullIO)	Verbosity)	THIS_ARCH)THIS_PLATFORM)PYTHON_VERSIONS)Version)VersionConstraint)parse_constraint)#NoCompatiblePythonVersionFoundError)PoetryPythonPathProvider)ShutilWhichPythonProvider)Iterator)IO)Config)Poetryc                   @  s6   e Zd ZU ded< ded< ded< ded< ded< d	S )

PythonInfointmajorminorpatchstrimplementationzPath | None
executableN)__name__
__module____qualname____annotations__ r$   r$   s/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/poetry/utils/env/python/manager.pyr   +   s   
 r   c                   @  s\  e Zd ZedLddZe	dMdNddZ			dOdPddZedQddZedQddZe		dRdSddZe	dMdddTd d!Z	e
dUd"d#Ze
dVd%d&Ze
dWd(d)Ze
dVd*d+Ze
dXd-d.Ze
dXd/d0Ze
dXd1d2Ze
dYd4d5ZedYd6d7ZedYd8d9ZedZd;d<Zed[d=d>Zed\d@dAZedMd]dFdGZedMd^dJdKZdS )_Pythonpythonfindpython.PythonVersionreturnNonec                C     d S Nr$   )selfr'   r$   r$   r%   __init__4   s   zPython.__init__Nr   
str | PathversionVersion | Nonec                 C  r+   r,   r$   )r-   r   r0   r$   r$   r%   r.   7   s   str | Path | Nonefindpython.PythonVersion | Nonec                 C  sZ   |r
|s|r
t d|r|| _d S |r)tjt||r"tjt|nd d| _d S t d)NzHWhen python is provided, neither executable or version must be specifiedr   _versionz,Either python or executable must be provided)	
ValueError_python
findpythonPythonVersionr   	packagingr0   r   r   )r-   r   r0   r'   r$   r$   r%   r.   >   s   
Iterator[Python]c                 c  sN    dt jv rtt jd nd }t D ]}|r|j|rq| |dV  qd S )NVIRTUAL_ENVr'   )osenvironr   r8   find_allr   is_relative_to)cls	venv_pathr'   r$   r$   r%   r@   S   s   zPython.find_allc                 c  s2    t jt gd}| D ]}| |dV  qd S )N)selected_providersr=   )r8   Finderr   namer@   )rB   finderr'   r$   r$   r%   find_poetry_managed_pythons]   s   z"Python.find_poetry_managed_pythons
constraintVersionConstraint | str | Noner   
str | NoneIterator[PythonInfo]c                 c  s    t |tr
t|}|ptd}|r| }t }|  D ].}|j|v s3||jr3|r4|j	 |kr4q|
|j t|j|j|j|j	 |jdV  qd S )N*r   r   r   r   r   )
isinstancer   r   lowersetr@   r   allowsr0   r   addr   r   r   r   )rB   rI   r   seenr'   r$   r$   r%   find_all_versionse   s0   



zPython.find_all_versionsFinclude_incompatiblerW   boolc             	   #  s    t |tr
t|}|ptd}tD ].} fddt| D D ] }|t|j|j|j	s/qt
|j|j|j	|j d dV  qqd S )NrM   c                   s0   h | ]} s|d  |d ft tfkr|d qS )r      )r   r   ).0krV   r$   r%   	<setcomp>   s    z4Python.find_downloadable_versions.<locals>.<setcomp>rN   )rO   r   r   r   rR   r   
from_partsr   r   micror   r   rP   )rB   rI   rW   pv_r$   rV   r%   find_downloadable_versions   s*   



z!Python.find_downloadable_versionsc                 C  s   | j S r,   )r7   r-   r$   r$   r%   r'      s   zPython.pythonr   c                 C     t d| jjS Nr   )r   r7   rF   rb   r$   r$   r%   rF         zPython.namer   c                 C  rc   )Nr   )r   r7   interpreterrb   r$   r$   r%   r      re   zPython.executablec                 C  s   t d| jj S rd   )r   r7   r   rP   rb   r$   r$   r%   r         zPython.implementationr   c                 C  rc   Nr   )r   r7   r   rb   r$   r$   r%   r      re   zPython.majorc                 C  rc   rh   )r   r7   r   rb   r$   r$   r%   r      re   zPython.minorc                 C  rc   rh   )r   r7   r   rb   r$   r$   r%   r      re   zPython.patchr   c                 C  s   t t| jjS r,   )r   parser   r7   r0   rb   r$   r$   r%   r0      rg   zPython.versionc                 C  s   t j| jj| jj| jjdS )N)r   r   r   )r   r]   r0   r   r   r   rb   r$   r$   r%   patch_version   s
   zPython.patch_versionc                 C  s   t j| jj| jjdS )N)r   r   )r   r]   r0   r   r   rb   r$   r$   r%   minor_version   s   zPython.minor_versionPython | Nonec                 C  s8   t   D ]}| |d  S td }r| |dS dS )a  
        Fetches the active Python interpreter from available system paths or falls
        back to finding the first valid Python executable named "python".

        An "active Python interpreter" in this context is an executable (or a symlink)
        with the name `python`. This is done so to detect cases where pyenv or
        alternatives are used.

        This method first uses the `ShutilWhichPythonProvider` to detect Python
        executables in the path. If no interpreter is found using, it attempts
        to locate a Python binary named "python" via the `findpython` library.

        :return: An instance representing the detected active Python,
                 or None if no valid environment is found.
        r=   r'   N)r   find_pythonsr8   find)rB   r'   r$   r$   r%   get_active_python   s
   
zPython.get_active_pythonc                 C  s<   | t jttjtjddd tj	dd D ddS )zk
        Creates and returns an instance of the class representing the Poetry's Python executable.
        .c                 s  s    | ]}t |V  qd S r,   )r   )rZ   vr$   r$   r%   	<genexpr>   s    z+Python.get_system_python.<locals>.<genexpr>N   r4   r=   )
r8   r9   r   sysr   r:   r0   r   joinversion_info)rB   r$   r$   r%   get_system_python   s   zPython.get_system_pythonpython_namec                 C  sl   t t t| }r| |dW  d    S W d    n1 s#w   Y  t| }r4| |dS d S )Nr=   )
contextlibsuppressr6   r   find_python_by_namer8   rn   )rB   rx   r'   r$   r$   r%   get_by_name   s   
zPython.get_by_nameconfigr   io	IO | Nonec                 C  sD   |pt  }|dst  }r|jd|j tjd |S |  S )a7  
        Determine and return the "preferred" Python interpreter based on the provided
        configuration and optional input/output stream.

        This method first attempts to get the active Python interpreter if the configuration
        does not mandate using Poetry's Python. If an active interpreter is found, it is returned.
        Otherwise, the method defaults to retrieving the Poetry's Python interpreter (System Python).

        This method **does not** attempt to sort versions or determine Python version constraint
        compatibility.
        zvirtualenvs.use-poetry-pythonzFound: )	verbosity)	r	   getr&   ro   write_error_liner   r
   VERBOSErw   )rB   r}   r~   active_pythonr$   r$   r%   get_preferred_python  s   


zPython.get_preferred_pythonpoetryr   c                 C  s\   |pt  }|jj}|  D ]}|j|r'|d|j d|j d |  S qt	|jj
)a  
        Retrieve a compatible Python version based on the given poetry configuration
        and Python constraints derived from the project.

        This method iterates through all available Python candidates and checks if any
        match the supported Python constraint as defined in the specified poetry package.

        :param poetry: The poetry configuration containing package information,
                       including Python constraints.
        :param io: The input/output stream for error and status messages. Defaults
                   to a null I/O if not provided.
        :return: A Python instance representing a compatible Python version.
        :raises NoCompatiblePythonVersionFoundError: If no Python version matches
                the supported constraint.
        z
Using <c1>z</c1> ())r	   packagepython_constraintr@   r0   
allows_anyr   rF   rj   r   python_versions)rB   r   r~   supported_pythonr'   r$   r$   r%   get_compatible_python  s   
zPython.get_compatible_python)r'   r(   r)   r*   r,   )r   r/   r0   r1   r)   r*   )NNN)r   r2   r0   r1   r'   r3   r)   r*   )r)   r;   )NN)rI   rJ   r   rK   r)   rL   )rI   rJ   rW   rX   r)   rL   )r)   r(   )r)   r   )r)   r   )r)   r   )r)   r   )r)   rl   )r)   r&   )rx   r   r)   rl   )r}   r   r~   r   r)   r&   )r   r   r~   r   r)   r&   )r    r!   r"   r   r.   classmethodr@   rH   rU   ra   propertyr'   rF   r   r   r   r   r   r0   r   rj   rk   ro   rw   r|   r   r   r$   r$   r$   r%   r&   3   sj    	r&   ).
__future__r   ry   r>   rt   	functoolsr   pathlibr   typingr   r   r   r   r8   packaging.versionr:   cleo.io.null_ior	   cleo.io.outputs.outputr
   pbs_installer._installr   r   pbs_installer._versionsr   poetry.core.constraints.versionr   r   r   "poetry.utils.env.python.exceptionsr   !poetry.utils.env.python.providersr   r   collections.abcr   
cleo.io.ior   poetry.config.configr   poetry.poetryr   register_providerr   r&   r$   r$   r$   r%   <module>   s>    
