U
    ARd                     @   s   U d 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 eeZdZdZedZe	e ed< ejjd	d
dZejjd	ddZdddZdd ZdS )zStreamlit version utilities.    N)version)Finalz$https://pypi.org/pypi/streamlit/jsong?Z	streamlitSTREAMLIT_VERSION_STRING)returnc                 C   s   t j| S )N)	packagingr   Version)version_str r	   5/tmp/pip-unpacked-wheel-b9et7o5g/streamlit/version.py_version_str_to_obj%   s    r   c                   C   s   t tS )zReturn the streamlit version string from setup.py.

    Returns
    -------
    str
        The version string specified in setup.py.

    )r   r   r	   r	   r	   r
    _get_installed_streamlit_version)   s    	r   c              
   C   sX   t jt| d}z| d d }W n, tk
rN } ztd|W 5 d}~X Y nX t|S )a`  Request the latest streamlit version string from PyPI.

    NB: this involves a network call, so it could raise an error
    or take a long time.

    Parameters
    ----------
    timeout : float or None
        The request timeout.

    Returns
    -------
    str
        The version string for the latest version of streamlit
        on PyPI.

    timeoutinfor   z!Got unexpected response from PyPIN)requestsgetPYPI_STREAMLIT_URLjson	ExceptionRuntimeErrorr   )r   Zrspr   er	   r	   r
   _get_latest_streamlit_version5   s    r   c               
   C   sn   t   tkrtd dS zt } tdd}W n6 tk
rd } ztjd|d W Y dS d}~X Y nX || kS )a  True if streamlit should show a 'new version!' notice to the user.

    We need to make a network call to PyPI to determine the latest streamlit
    version. Since we don't want to do this every time streamlit is run,
    we'll only perform the check ~5% of the time.

    If we do make the request to PyPI and there's any sort of error,
    we log it and return False.

    Returns
    -------
    bool
        True if we should tell the user that their streamlit is out of date.

    zSkipping PyPI version checkF   r   zFailed PyPI version check.)exc_infoN)randomCHECK_PYPI_PROBABILITY_LOGGERdebugr   r   r   )installed_versionZlatest_versionexr	   r	   r
   should_show_new_version_noticeO   s    
r    )N)__doc__r   Zpackaging.versionr   r   Zimportlib_metadatar   _versionZtyping_extensionsr   Zstreamlit.loggerloggerZ
get_logger__name__r   r   r   r   str__annotations__r   r   r   r   r    r	   r	   r	   r
   <module>   s   

