o
    Uh                     @  st   d dl mZ d dlZd dlZd dlmZmZ d dlmZm	Z	 d dl
mZ d dlmZmZ edZG dd	 d	ZdS )
    )annotationsN)CallableIterable)ALL_PROVIDERSBaseProvider)PythonVersion)get_suffix_preferenceparse_major
findpythonc                   @  s   e Zd ZdZ				d1d2ddZ	d3d4ddZd3d5ddZ									d6d7d$d%Z									d6d8d'd(Zd9d*d+Z	d:d/d0Z
dS );Findera  Find python versions on the system.

    :param resolve_symlinks: Whether to resolve symlinks.
    :param no_same_file: Whether to deduplicate with the python executable content.
    :param no_same_interpreter: Whether to deduplicate with the python executable path.
    FNresolve_symlinksboolno_same_fileno_same_interpreterselected_providerslist[str] | NonereturnNonec                 C  s"   || _ || _|| _| || _d S N)r   r   r   setup_providers
_providers)selfr   r   r   r    r   e/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/findpython/finder.py__init__   s   zFinder.__init__list[BaseProvider]c                 C  sZ   g }t }|d urdd |D }| D ]}| }|d u r%td|j q|| q|S )Nc                 S  s   i | ]}|t | qS r   )r   ).0namer   r   r   
<dictcomp>)   s    z*Finder.setup_providers.<locals>.<dictcomp>zProvider %s is not available)r   valuescreateloggerdebug__name__append)r   r   	providersallowed_providersprovider_classproviderr   r   r   r   "   s   zFinder.setup_providersr(   r   pos
int | Nonec                 C  s*   |dur| j || dS | j | dS )zoAdd provider to the provider list.
        If pos is given, it will be inserted at the given position.
        N)r   insertr$   )r   r(   r)   r   r   r   add_provider2   s   zFinder.add_providermajorint | str | Noneminorpatchprebool | Nonedevr   
str | Nonearchitectureallow_prereleasesimplementationlist[PythonVersion]c
                 C  s   |r|du s
|du rt dt|trYtdd |||||fD r%t dt|}
|
durT|
d }|
d }|
d	 }|
d
 }|
d }|rK|pFd}|pJd}|
d }|
d }	n|d}}td||||||||		}t|  }| 	||S )a  
        Return all Python versions matching the given version criteria.

        :param major: The major version or the version string or the name to match.
        :param minor: The minor version to match.
        :param patch: The micro version to match.
        :param pre: Whether the python is a prerelease.
        :param dev: Whether the python is a devrelease.
        :param name: The name of the python.
        :param architecture: The architecture of the python.
        :param allow_prereleases: Whether to allow prereleases.
        :param implementation: The implementation of the python. E.g. "cpython", "pypy".
        :return: a list of PythonVersion objects
        Fz<If allow_prereleases is True, pre and dev must not be False.c                 s  s    | ]}|d uV  qd S r   r   )r   vr   r   r   	<genexpr>Z   s    z"Finder.find_all.<locals>.<genexpr>zLIf major is a string, minor, patch, pre, dev and name must not be specified.Nr-   r/   r0   r1   r3   r5   r7   matches)

ValueError
isinstancestranyr	   operatormethodcallerset_find_all_python_versions_dedup)r   r-   r/   r0   r1   r3   r   r5   r6   r7   version_dictversion_matchermatched_pythonr   r   r   find_all;   sF   


zFinder.find_allPythonVersion | Nonec
           
      C  s$   t t| |||||||||		dS )a  
        Return the Python version that is closest to the given version criteria.

        :param major: The major version or the version string or the name to match.
        :param minor: The minor version to match.
        :param patch: The micro version to match.
        :param pre: Whether the python is a prerelease.
        :param dev: Whether the python is a devrelease.
        :param name: The name of the python.
        :param architecture: The architecture of the python.
        :param allow_prereleases: Whether to allow prereleases.
        :param implementation: The implementation of the python. E.g. "cpython", "pypy".
        :return: a Python object or None
        N)nextiterrH   )
r   r-   r/   r0   r1   r3   r   r5   r6   r7   r   r   r   find}   s    zFinder.findIterable[PythonVersion]c                 c  s     | j D ]	}| E dH  qdS )z'Find all python versions on the system.N)r   find_pythons)r   r(   r   r   r   rC      s   
z Finder._find_all_python_versionspython_versionsrF   Callable[[PythonVersion], bool]c                   sf   d fdd}ddd	}i }t ||d
D ]}||}||vr*| r*||r*|||< qt | ddS )Npython_versionr   r   r>   c                   s>    j r| j S  jr|  S  jr| js| j S | j S r   )	r   interpreteras_posixr   binary_hashr   keep_symlink	real_path
executablerQ   r   r   r   	dedup_key   s   


z Finder._dedup.<locals>.dedup_keytuple[int, int, int]c                 S  s"   | j  t| jt| j   fS r   )rW   
is_symlinkr   r   lenrS   rX   r   r   r   sort_key   s   zFinder._dedup.<locals>.sort_key)keyT)reverse)rQ   r   r   r>   )rQ   r   r   r[   )sortedis_validr   )r   rO   rF   rZ   r^   resultrQ   r_   r   rY   r   rD      s   
	zFinder._dedup)FFFN)
r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   )r(   r   r)   r*   r   r   )	NNNNNNNFN)r-   r.   r/   r*   r0   r*   r1   r2   r3   r2   r   r4   r5   r4   r6   r   r7   r4   r   r8   )r-   r.   r/   r*   r0   r*   r1   r2   r3   r2   r   r4   r5   r4   r6   r   r7   r4   r   rI   )r   rM   )rO   rM   rF   rP   r   r8   )r#   
__module____qualname____doc__r   r   r,   rH   rL   rC   rD   r   r   r   r   r      s@    	D
+r   )
__future__r   loggingr@   typingr   r   findpython.providersr   r   findpython.pythonr   findpython.utilsr   r	   	getLoggerr!   r   r   r   r   r   <module>   s    
