
    3i%                    6   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mZmZ  ej                  dej                        Z ej                  d	ej                        Zd
Zded<   dZded<   eZeZeZeZddZddZddZddZ G d d      Zg dZy)zOA Python specification is an abstract requirement definition of an interpreter.    )annotationsN)Final   )normalize_isa)SimpleSpecifierSimpleSpecifierSetSimpleVersionaR  
    ^
    (?P<impl>[a-zA-Z]+)?            # implementation (e.g. cpython, pypy)
    (?P<version>[0-9.]+)?           # version (e.g. 3.12, 3.12.1)
    (?P<threaded>t)?                # free-threaded flag
    (?:-(?P<arch>32|64))?           # architecture bitness
    (?:-(?P<machine>[a-zA-Z0-9_]+))?  # ISA (e.g. arm64, x86_64)
    $
    z
    ^
    (?:(?P<impl>[A-Za-z]+)\s*)?     # optional implementation prefix
    (?P<spec>(?:===|==|~=|!=|<=|>=|<|>).+)  # PEP 440 version specifier
    $
       z
Final[int]_MAX_VERSION_PARTS	   _SINGLE_DIGIT_MAXc                     | d S t        |       S Nint)vals    L/var/www/opsc/venv/lib/python3.12/site-packages/python_discovery/_py_spec.py_int_or_noner   ,   s    ;4,CH,    c                z   t        d | j                  d      D              }t        |      t        kD  rd}t	        |      t        |      t        k(  r|d   |d   |d   fS t        |      dk(  r|d   |d   d fS |d   }t        t        |      d         }|t        kD  rt        t        |      dd        nd }||d fS )Nc              3  8   K   | ]  }|st        |        y wr   r   ).0is     r   	<genexpr>z'_parse_version_parts.<locals>.<genexpr>1   s     =1SV=s   .ztoo many version partsr   r      )tuplesplitlenr   
ValueErrorr   strr   )versionversionsmsgversion_datamajorminors         r   _parse_version_partsr(   0   s    =W]]3%7==H
8}))&o
8}**{HQK!44
8}{HQK--A;LL!!$%E*69J*JCL!!"%&PTE%r   c                h   t        j                  t        |       x}sy |j                         }|d   }d\  }}}}|	 t	        |      \  }}}t        |d         }|d   }|dv rd }t        |d         }	|j                  d      }
|
t        |
      }
t        | |||||	d ||
	      S # t
        $ r Y y w xY w)	Nr"   )NNNNthreadedimpl>   pypythonarchmachine)free_threadedr/   )rematchPATTERN	groupdictr(   r    boolr   getr   
PythonSpec)string_specr2   groupsr"   r&   r'   micror*   r+   r.   r/   s              r   _parse_spec_patternr;   ?   s    XXg{33E3__FYG$:!E5%	"6w"?E5% z*+&>Dv'Djj#G(k4udDX`jqrr  		s   B% %	B10B1c           
     8   t         j                  | j                               x}sy t        y |j	                  d      }|j	                  d      j                         }	 t        j                  |      }|dv rd }t        | |d d d d d |      S # t        $ r Y y w xY w)Nr+   spec>   r,   r-   )version_specifier)SPECIFIER_PATTERNr2   stripSpecifierSetgroupfrom_stringInvalidSpecifierr7   )r8   specifier_matchr+   	spec_textr>   s        r   _parse_specifierrG   U   s    066{7H7H7JKKOK  (D%%f-335I(44Y? k4tT4Yjkk	  s   B 	BBc                      e Zd ZdZdddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZedd       ZddZedd       Z	ddZ
edd	       Zdd
ZddZy)r7   aV  
    Contains specification about a Python Interpreter.

    :param str_spec: the raw specification string as provided by the caller.
    :param implementation: interpreter implementation name (e.g. ``"cpython"``, ``"pypy"``), or ``None`` for any.
    :param major: required major version, or ``None`` for any.
    :param minor: required minor version, or ``None`` for any.
    :param micro: required micro (patch) version, or ``None`` for any.
    :param architecture: required pointer-size bitness (``32`` or ``64``), or ``None`` for any.
    :param path: filesystem path to a specific interpreter, or ``None``.
    :param free_threaded: whether a free-threaded build is required, or ``None`` for any.
    :param machine: required ISA (e.g. ``"arm64"``), or ``None`` for any.
    :param version_specifier: PEP 440 version constraints, or ``None``.
    N)r0   r/   r>   c                   || _         || _        || _        || _        || _        || _        || _        |	| _        || _        |
| _	        y r   )
str_specimplementationr&   r'   r:   r0   architecturer/   pathr>   )selfrJ   rK   r&   r'   r:   rL   rM   r0   r/   r>   s              r   __init__zPythonSpec.__init__u   sN     !,


*(	!2r   c           	         t        j                  |      j                         r | |ddddd|      S t        |      x}r|S t	        |      x}r|S  | |ddddd|      S )u   
        Parse a string specification into a :class:`PythonSpec`.

        :param string_spec: an interpreter spec — an absolute path, a version string, an implementation prefix,
            or a PEP 440 specifier.
        N)pathlibPathis_absoluter;   rG   )clsr8   results      r   from_string_speczPythonSpec.from_string_spec   sq     <<$002{D$dD+NN(5565M%k2262M;dD$kJJr   c                   dj                   d | j                  | j                  | j                  fD         }| j                  dn!dt        j                  | j                         }| j                  rdnd}|rdnd}|s| j                  dnd}t        j                  d	| d
| | d| | d	t
        j                        S )z
        Generate a regular expression for matching interpreter filenames.

        :param windows: if ``True``, require a ``.exe`` suffix.
        z{}(\.{}(\.{})?)?c              3  (   K   | ]
  }|dn|  y w)Nz\d+ )r   vs     r   r   z)PythonSpec.generate_re.<locals>.<genexpr>   s     WQ	fq(Ws   r-   zpython|zt? z\.exe?z	(?P<impl>z)(?P<v>)$)flags)
formatr&   r'   r:   rK   r1   escaper0   compile
IGNORECASE)rN   windowsr"   r+   modsuffixversion_conditionals          r   generate_rezPythonSpec.generate_re   s     -%,,W4::tzz4::2VW
  ..6xgbiiPTPcPcFdEe<f((db$"%,

0BczzggYse15H4I&QRS--
 	
r   c                |    | j                   duxr- t        j                  | j                         j                         S )z;``True`` if the spec refers to an absolute filesystem path.N)rM   rQ   rR   rS   )rN   s    r   is_abszPythonSpec.is_abs   s.     yy$Ndii)@)L)L)NNr   c                   g }| j                   | j                  | j                  fD ]  }| n|j                  |        |sydj	                  d |D              }|j
                  yt        j                  t              5  t        j                  |       |j
                  D ]?  }| j                  |      }|t        |      |k  r%|j                  |      r7 ddd       y 	 ddd       y# 1 sw Y   yxY w)z(Check if version specifier is satisfied.NTr   c              3  2   K   | ]  }t        |        y wr   )r!   )r   parts     r   r   z6PythonSpec._check_version_specifier.<locals>.<genexpr>   s     @Ts4y@s   F)r&   r'   r:   appendjoinr>   
contextlibsuppressInvalidVersionVersionrC   _get_required_precisionr   contains)rN   r=   
componentsrm   version_stritemrequired_precisions          r   _check_version_specifierz#PythonSpec._check_version_specifier   s     "
ZZTZZ8 	$D|d#	$ hh@Z@@!!)  0 	!,.. !%)%A%A$%G"%-ZCU1U}}[1 	! 	!!	! 	! s   AC/C/$C//C8c                    | j                   yt        j                  t        t              5  t        | j                   j                        cddd       S # 1 sw Y   yxY w)z0Get the required precision for a specifier item.N)r"   rp   rq   AttributeErrorr    r   release)rx   s    r   rt   z"PythonSpec._get_required_precision   sK     <<  < 	-t||++,	- 	- 	-s   AAc           	        |j                   r&| j                   r| j                  |j                  k7  ry|j                  B| j                  6|j                  j                         | j                  j                         k7  ry|j                  |j                  | j                  k7  ry|j
                  &| j
                  |j
                  | j
                  k7  ry|j                  |j                  | j                  k7  ry|j                  | j                  |      syt        d t        | j                  | j                  | j                  f|j                  |j                  |j                  f      D              S )z
        Check if this spec is compatible with the given *spec* (e.g. PEP-514 on Windows).

        :param spec: the requirement to check against.
        Fc              3  D   K   | ]  \  }}|d u xs |d u xs ||k(    y wr   rY   )r   ourreqs      r   r   z'PythonSpec.satisfies.<locals>.<genexpr>   s5      
S 4K43$;4#*4
s    )rj   rM   rK   lowerrL   r/   r0   r>   rz   allzipr&   r'   r:   )rN   r=   s     r   	satisfieszPythonSpec.satisfies   s:    ;;4;;499		+A+##/##))+t/B/B/H/H/JJ(T->->$BSBS-S<<#(@T\\UYUaUaEa)d.@.@DDVDV.V!!-d6S6STX6Y 
TZZ DtzzSWS]S]_c_i_iFjk
 
 	
r   c                r     t               j                  }d}| ddj                   fd|D               dS )N)	rK   r&   r'   r:   rL   r/   rM   r0   r>   (z, c              3  Z   K   | ]"  }t        |      | dt        |        $ y w)N=)getattr)r   krN   s     r   r   z&PythonSpec.__repr__.<locals>.<genexpr>   s3     "mPWX\^_P`PlaS'$*:);#<"ms   ++r]   )type__name__ro   )rN   nameparamss   `  r   __repr__zPythonSpec.__repr__   s?    Dz""

 q"mf"mmnnoppr   )rJ   r!   rK   
str | Noner&   
int | Noner'   r   r:   r   rL   r   rM   r   r0   zbool | Noner/   r   r>   zSpecifierSet | NonereturnNone)r8   r!   r   r7   )rd   r5   r   z
re.Pattern)r   r5   )r=   r7   r   r5   )rx   r   r   r   )r   r!   )r   
__module____qualname____doc__rO   classmethodrV   rh   propertyrj   rz   staticmethodrt   r   r   rY   r   r   r7   r7   e   s    2 &*"1533 #3 	3
 3 3 !3 3 #3 3 /3 
32 K K
$ O O.  
6qr   r7   )rD   rr   r7   rA   rs   )r   r   r   r   )r"   r!   r   z)tuple[int | None, int | None, int | None])r8   r!   r   zPythonSpec | None) r   
__future__r   rp   rQ   r1   typingr   _py_infor   
_specifierr   r   r	   rb   VERBOSEr3   r?   r   __annotations__r   rA   rs   r    rD   rr   r   r(   r;   rG   r7   __all__rY   r   r   <module>r      s    U "   	  # J J
"** JJ BJJ JJ  "# J " ! : !!
 -s,l Xq Xqvr   