
    bi                        U d Z 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 eZded<   d	Zdadd
ZddZddZddZddZddZy)a  Module for checking and comparing albumentations package versions.

This module provides utilities for version checking and comparison, including
the ability to fetch the latest version from PyPI and compare it with the currently
installed version. It helps users stay informed about available updates and
encourages keeping the library up-to-date with the latest features and bug fixes.
    )annotationsN)OpenerDirector)warn)__version__strr      c                     t         Xt        j                  j                  t        j                  j	                         t        j                  j                               a t         S )aA  Get or create a URL opener for making HTTP requests.

    This function implements a singleton pattern for the opener to avoid
    recreating it on each request. It lazily instantiates a URL opener
    with HTTP and HTTPS handlers.

    Returns:
        OpenerDirector: URL opener instance for making HTTP requests.

    )openerurllibrequestbuild_openerHTTPHandlerHTTPSHandler     W/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/albumentations/check_version.py
get_openerr      s>     ~,,V^^-G-G-I6>>KfKfKhiMr   c                 t   t               } d}	 | j                  |d      5 }|j                  t        k(  rI|j	                         }|j                         j                  d      }|j                  |      cddd       S 	 ddd       y# 1 sw Y   yxY w# t        $ r}t        d| d       Y d}~yd}~ww xY w)	a  Fetch version information from PyPI for albumentations package.

    This function retrieves JSON data from PyPI containing information about
    the latest available version of albumentations. It handles network errors
    gracefully and returns an empty string if the request fails.

    Returns:
        str: JSON string containing version information if successful,
             empty string otherwise.

    z)https://pypi.org/pypi/albumentations/json   )timeoutzutf-8NzError fetching version info 
stacklevel )
r   openstatusSUCCESS_HTML_CODEreadinfoget_content_charsetdecode	Exceptionr   )r
   urlresponsedataencodinges         r   fetch_version_infor'   +   s     \F
5C?[[a[( 	-H"33}}#==?>>wG{{8,		- 	-3	- 	-   ?+A3/A>>?s;   B AB4	B ?B BB B 	B7B22B7c                    | r8	 t        j                  |       }|j                  di       j                  dd      S y# t         j                  $ r Y yw xY w)z,Parses the version from the given JSON data.r   versionr   )jsonloadsgetJSONDecodeError)r$   	json_datas     r   parse_versionr/   D   sU    	

4(I==,00B??  ## 		s   6< AAc                   t        | |      D ]j  \  }}||k7  st        |t              rt        |t              r||kD  c S t        |t              rt        |t              r||kD  c S t        |t              c S  t	        |       t	        |      kD  rt        | t	        |         t              S t	        |      t	        |       kD  rt        |t	        |          t              S y)a  Compare two version tuples.
    Returns True if v1 > v2, False otherwise.

    Special rules:
    1. Release version > pre-release version (e.g., (1, 4) > (1, 4, 'beta'))
    2. Numeric parts are compared numerically
    3. String parts are compared lexicographically
    F)zip
isinstanceintr   len)v1v2p1p2s       r   compare_versionsr9   Q   s     b"+ 'B8"c"z"c':Bw"c"z"c':Bwb#&&' 2wR"SW+s++
2wR"SW+s++r   c                   g }| j                  d      D ]i  }t        j                  d|      }|D ]L  }|j                         r|j	                  t        |             .|j	                  |j                                N k t        |      S )zConvert version string to tuple of (int | str) parts following PEP 440 conventions.

    Examples:
        "1.4.24" -> (1, 4, 24)
        "1.4beta" -> (1, 4, "beta")
        "1.4.beta2" -> (1, 4, "beta", 2)
        "1.4.alpha2" -> (1, 4, "alpha", 2)

    .z([0-9]+|[a-zA-Z]+))splitrefindallisdigitappendr3   lowertuple)version_strpartspartsegmentssegments        r   parse_version_partsrH   p   s{     E!!#& .::3T: 	.G S\*W]]_-		.. <r   c                    	 t               } t        |       }|rEt        |      }t        t              }t	        ||      rt        d|dt        dt        d       yyy# t        $ r }t        d| dt        d       Y d}~yd}~ww xY w)	a  Check if a newer version of albumentations is available on PyPI.

    This function compares the current installed version with the latest version
    available on PyPI. If a newer version is found, it issues a warning to the user
    with upgrade instructions. All exceptions are caught to ensure this check
    doesn't affect normal package operation.

    The check can be disabled by setting the environment variable
    NO_ALBUMENTATIONS_UPDATE to 1.
    z.A new version of Albumentations is available: z (you have z). Upgrade using: pip install -U albumentations. To disable automatic update checks, set the environment variable NO_ALBUMENTATIONS_UPDATE to 1.r   r   z*Failed to check for updates due to error: za. To disable automatic update checks, set the environment variable NO_ALBUMENTATIONS_UPDATE to 1.N)r'   r/   rH   current_versionr9   r   UserWarningr!   )r$   latest_versionlatest_partscurrent_partsr&   s        r   check_for_updatesrO      s    
!#&t,.~>L/@Mm<D^DVVabqat uv v    =   
8 <n n		
 	

s   AA 	B(BB)returnr   )rP   r   )r$   r   rP   r   )r5   tuple[int | str, ...]r6   rQ   rP   bool)rC   r   rP   rQ   )rP   None)__doc__
__future__r   r*   r=   urllib.requestr   r   warningsr   albumentationsr   rJ   __annotations__r   r
   r   r'   r/   r9   rH   rO   r   r   r   <module>rZ      sT    #  	  )  9"S " 	"2
>.
r   