
    Ki'                       d dl mZ d dlZd dlmZmZ ddlmZ ddlm	Z	 g dZ
ddZ G d	 d
e      Z G d de      Z G d de      Z G d d      Z G d d      Z	 	 	 	 	 	 ddZ ej&                  d      ZddZ	 	 	 	 	 	 ddZy)    )annotationsN)MappingSequence   )_ErrorCollector)Requirement)CyclicDependencyGroupDependencyGroupIncludeDependencyGroupResolverDuplicateGroupNamesInvalidDependencyGroupObjectresolve_dependency_groupsc                     t         S N)__all__     g/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/packaging/dependency_groups.py__dir__r      s    Nr   c                      e Zd ZdZy)r   z]
    The same dependency groups were defined twice, with different non-normalized names.
    N__name__
__module____qualname____doc__r   r   r   r   r      s    r   r   c                  $     e Zd ZdZd fdZ xZS )r	   z5
    The dependency group includes form a cycle.
    c                    || _         || _        || _        ||k(  r| d}n| d| d| d| }t        |   d| d|        y )Nz includes itselfz -> , z0Cyclic dependency group include while resolving z: )requested_groupgroupinclude_groupsuper__init__)selfr   r    r!   reason	__class__s        r   r#   zCyclicDependencyGroup.__init__'   sl    .
*E!w./F%d5'E7$}oNF>r&+	
r   )r   strr    r'   r!   r'   returnNone)r   r   r   r   r#   __classcell__)r&   s   @r   r	   r	   "   s    
 
r   r	   c                      e Zd ZdZy)r   ze
    A member of a dependency group was identified as a dict, but was not in a valid
    format.
    Nr   r   r   r   r   r   9   s    r   r   c                       e Zd ZdZddZddZy)r
   r!   c                    || _         y)z
        Initialize a DependencyGroupInclude.

        :param include_group: The name of the group referred to by this include.
        Nr-   )r$   r!   s     r   r#   zDependencyGroupInclude.__init__H   s     +r   c                N    | j                   j                   d| j                  dS )N())r&   r   r!   )r$   s    r   __repr__zDependencyGroupInclude.__repr__P   s'    ..))*!D,>,>+ACCr   N)r!   r'   r(   r)   )r(   r'   )r   r   r   	__slots__r#   r2   r   r   r   r
   r
   E   s    "I+Dr   r
   c                  \    e Zd ZdZ	 	 	 	 ddZd	dZd
dZ	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZy)r   a\  
    A resolver for Dependency Group data.

    This class handles caching, name normalization, cycle detection, and other
    parsing requirements. There are only two public methods for exploring the data:
    ``lookup()`` and ``resolve()``.

    :param dependency_groups: A mapping, as provided via pyproject
        ``[dependency-groups]``.
    c                    t               }t        ||      | _        i | _        i | _        i | _        |j                  d       y )Nz$[dependency-groups] data was invalid)r   _normalize_group_namesdependency_groups_parsed_groups_include_graph_ancestors_resolve_cachefinalize)r$   r7   errorss      r   r#   z DependencyGroupResolver.__init__`   sJ     !"!78I6!R
  	 EG%BD>?r   c                    t        |      }t               j                  d|d      5 }| j                  ||      cddd       S # 1 sw Y   yxY w)z
        Lookup a group name, returning the parsed dependency data for that group.
        This will not resolve includes.

        :param group: the name of the group to lookup
        [dependency-groups] data for  was malformedN)_normalize_namer   on_exit_parse_groupr$   r    r<   s      r   lookupzDependencyGroupResolver.lookups   sS      &&&+E9NC
 	4$$UF3	4 	4 	4s   AAc                    t        |      }t               j                  d|d      5 }| j                  |||      cddd       S # 1 sw Y   yxY w)z
        Resolve a dependency group to a list of requirements.

        :param group: the name of the group to resolve
        r>   r?   N)r@   r   rA   _resolverC   s      r   resolvezDependencyGroupResolver.resolve   sS      &&&+E9NC
 	7==v6	7 	7 	7s   AAc                   || j                   v r| j                   |   S | j                  ||      }g }|D ]  }t        |t              r|j	                  |       %t        |t
              rt        |j                        }|| j                  j                  |d      v r'|j                  t        |||j                               g | j                  j                  |d      || j                  |<   |j                  | j                  |||             t        d|        |j                  ryt!        |      | j                   |<   | j                   |   S )a  
        This is a helper for cached resolution to strings. It preserves the name of the
        group which the user initially requested in order to present a clearer error in
        the event that a cycle is detected.

        :param group: The normalized name of the group to resolve.
        :param requested_group: The group which was used in the original, user-facing
            request.
        r   z+Invalid dependency group item after parse: )r:   rB   
isinstancer   appendr
   r@   r!   r9   geterrorr	   extendrF   NotImplementedErrorr<   tuple)r$   r    r   r<   parsedresolved_groupitemr!   s           r   rF   z DependencyGroupResolver._resolve   s^    D'''&&u--""5&1 	D$,%%d+D"89 /0B0B C !D$A$A$E$EeR$PPLL-+UD4F4FD66::5"EDDD11-@ #))m_fM *A$H 5	B ==%*>%:E"""5))r   c                6   || j                   v r| j                   |   S || j                  vr|j                  t        d| d             y| j                  |   }t	        |t
              r|j                  t        d|d             yt	        |t              s|j                  t        d|d             yg }|D ]  }t	        |t
              r|j                  t        |             .t	        |t              r[t        |j                               dk7  r|j                  t        d|             x|d	   }|j                  t        |
             |j                  t        d|              t        |      | j                   |<   | j                   |   S )NzDependency group 'z' not foundr   zDependency group z' contained a string rather than a list.z is not a sequence type.)include-groupzInvalid dependency group item: rT   r-   )r8   r7   rL   LookupErrorrI   r'   	TypeErrorr   rJ   r   r   rO   keysr   r
   )r$   r    r<   	raw_groupelementsrR   r!   s          r   rB   z$DependencyGroupResolver._parse_group   s    D'''&&u--...LL'9%%LMN**51	i%LL'y0WX
 )X.LL-eY6NOP ?A 	TD$$ D 12D'*%);;LL4=dXF %)$9MOO$:$WXY)H'QRS#	T& &+8_E"""5))r   N)r7   /Mapping[str, Sequence[str | Mapping[str, str]]]r(   r)   )r    r'   r(   0tuple[Requirement | DependencyGroupInclude, ...])r    r'   r(   tuple[Requirement, ...])r    r'   r   r'   r<   r   r(   r\   )r    r'   r<   r   r(   r[   )	r   r   r   r   r#   rD   rG   rF   rB   r   r   r   r   r   T   sn    	@J@ 
@&478*8*+.8*8G8*	 8*t/*/*"1/*	9/*r   r   c               B    t        |       t        fd|D              S )z
    Resolve a dependency group to a tuple of requirements, as strings.

    :param dependency_groups: the parsed contents of the ``[dependency-groups]`` table
        from ``pyproject.toml``
    :param groups: the name of the group(s) to resolve
    c              3  `   K   | ]%  }j                  |      D ]  }t        |        ' y wr   )rG   r'   ).0r    rresolvers      r   	<genexpr>z,resolve_dependency_groups.<locals>.<genexpr>
  s,     MEX5E5Ee5LMQMMs   +.)r   rO   )r7   groupsra   s     @r   r   r      s!     ''89HMVMMMr   z[-_.]+c                J    t         j                  d|       j                         S )N-)_NORMALIZE_PATTERNsublower)names    r   r@   r@     s    !!#t,2244r   c                N   i }i }| j                         D ]6  \  }}t        |      }|j                  |g       j                  |       |||<   8 |j                         D ]D  \  }}t	        |      dkD  s|j                  t        d| ddj                  |       d             F |S )Nr   z"Duplicate dependency group names: z (r   r1   )itemsr@   
setdefaultrJ   lenrL   r   join)	r7   r<   original_namesnormalized_groups
group_namevaluenormed_group_namenormed_namenamess	            r   r6   r6     s     ,.NFH.446 5
E+J7!!"3R8??
K/4+,5
 -224 Uu:>LL#8"m2dii&6%7q: r   )r(   z	list[str])r7   rZ   rc   r'   r(   ztuple[str, ...])ri   r'   r(   r'   )r7   rZ   r<   r   r(   z,dict[str, Sequence[str | Mapping[str, str]]])
__future__r   recollections.abcr   r   r<   r   requirementsr   r   r   
ValueErrorr   r	   r   r
   r   r   compilerf   r@   r6   r   r   r   <module>r|      s    " 	 - # %* 
J 
.: D Dc* c*VNFNTWNN&  RZZ	* 5F 2r   