U
    9%e                     @   s   d Z ddlZddlZddlZddlZddlmZ ddlm	Z	 ej
ejejejejejdZdd Zdeee ddd	d
Zdd ZdS )z-
Utilities for working with package versions
    N)Optional)version)<z<===z!=z>=>c              
   C   sn   |d ks|d kr2t d| d| d| d| d	t|  t|t|sjt| d| d| d| d S )NzUnable to compare versions for z: need=z found=z). This is unusual. Consider reinstalling .z@ is required for a normal functioning of this module, but found r   )
ValueErroropsr   parseImportError)opgot_verwant_verrequirementpkghint r   Z/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/transformers/utils/versions.py_compare_versions%   s    r   )r   r   returnc              	   C   s  |dk	rd| nd}t d| r4| dd  }}}nt d| }|sRtd|  |d \}}|d}i }|D ]^}	t d	|	}|std|  |d \}}|||< |tkrpt|  d
tt  d| qp|dkr"ddd t	j
dd D }
| D ]\}}t||
|| || q dS ztj|}
W n2 tjjk
rd   tjd|  d| Y nX |dk	r| D ]\}}t||
|| || qxdS )a/  
    Perform a runtime check of the dependency versions, using the exact same syntax used by pip.

    The installed module version comes from the *site-packages* dir via *importlib.metadata*.

    Args:
        requirement (`str`): pip style definition, e.g.,  "tokenizers==0.9.4", "tqdm>=4.27", "numpy"
        hint (`str`, *optional*): what suggestion to print in case of requirements not being met

    Example:

    ```python
    require_version("pandas>1.1.2")
    require_version("numpy>1.18.5", "this is important to have for whatever reason")
    ```N
 z^[\w_\-\d]+$z^([^!=<>\s]+)([\s!=<>]{1,2}.+)zgrequirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but got r   ,z^([\s!=<>]{1,2})(.+)z: need one of z
, but got pythonr   c                 S   s   g | ]}t |qS r   )str).0xr   r   r   
<listcomp>_   s     z#require_version.<locals>.<listcomp>   zThe 'zB' distribution was not found and is required by this application. )rematchfindallr   splitr	   listkeysjoinsysversion_infoitemsr   	importlibmetadatar   ZPackageNotFoundError)r   r   r   r   r   r    Z	want_fullZ
want_rangewantedwr   r   r   r   require_version1   sF    
"


r-   c                 C   s   d}t | |S )zCrequire_version wrapper which emits a core-specific hint on failurez[Try: pip install transformers -U or pip install -e '.[dev]' if you're working with git main)r-   )r   r   r   r   r   require_version_corer   s    r.   )N)__doc__importlib.metadatar)   operatorr   r&   typingr   	packagingr   ltleeqnegegtr	   r   r   r-   r.   r   r   r   r   <module>   s    
A