
    Ki                         d dl mZmZ d dlmZ d dlmZ d dlmZ erd dl	m
Z
 e G d d             Zdeeeee   f      d	eez  d
efdZddddedeeeee   f      fdZddddedeedee   f      fdZy)    )TYPE_CHECKINGAny)CommandSpec)Group)frozen)Appc                   0    e Zd ZU dZeedf   ed<   ded<   y)RegisteredCommanda  A command with the names it was registered under.

    Parameters
    ----------
    names : tuple[str, ...]
        All names (including aliases) this command is registered under.
    app : App | CommandSpec
        The command's App or unresolved CommandSpec instance.
    .nameszApp | CommandSpecappN)__name__
__module____qualname____doc__tuplestr__annotations__     e/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/cyclopts/group_extractors.pyr
   r
      s     c?	r   r
   group_mappinggroupelementc                    t        |t              rt        |      }nt        |t              rnt        | D ]4  }|d   j                  |j                  k(  s |d   j                  |        y  | j                  ||gf       y )Nr      )
isinstancer   r   	TypeErrornameappend)r   r   r   mappings       r   _create_or_appendr!      sx     %e	E5	!  11:??ejj(AJg&1
 	egY/0r   r   r   resolve_lazyreturnc                 t   t        | j                  t              rJ | j                  xs t        j                         }i }i }i }i }| D ]  }| j                  |d      }t        |t              rQ|j                  sE|sC|j                  sAt        |      }	|j                  |	g       j                  |       |	|vr|||	<   w| |   }
t        |
      }|j                  |g       j                  |       ||vs|
||<    |g fg}|j                         D ]  }
t        |
j                  t              sJ |
j                  D ]k  }t        |t              s|D ]@  }|d   |u r "|d   j                  |j                  k(  s)t!        d|j                   d       |j                  |g f       m  |j#                         D ]s  \  }}
t        ||         }t%        ||
      }|
j                  r;t        |
j                  t              sJ |
j                  D ]  }t'        |||        gt'        |||       u |j                         D ]  }|j                  t        |j                  t              r|j                  n|j                  f}|D ]k  }t        |t              s|D ]@  }|d   |u r "|d   j                  |j                  k(  s)t!        d|j                   d       |j                  |g f       m  |j#                         D ]  \  }	}t        ||	         }t%        ||      }|j                  Ht        |j                  t              r|j                  n|j                  f}|D ]  }t'        |||        tt'        |||        |D cg c]
  }|d   s	| }}|j)                  d        |S c c}w )	a  Extract Group/App association from all commands of ``app``.

    Parameters
    ----------
    app : App
        The application to extract groups from.
    resolve_lazy : bool
        If ``True``, resolve lazy commands (import their modules) to include them
        in the output. If ``False`` (default), skip unresolved lazy commands.
        Set to ``True`` when generating static artifacts that need all commands,
        such as shell completion scripts.

    Returns
    -------
    list
        List of items where each item is a tuple containing:

        * :class:`.Group` - The group

        * ``list[RegisteredCommand]`` - List of RegisteredCommand tuples containing
          the registered names and app instance for each command.
    T)recurse_metar   zCommand Group "z" already exists.r   c                      | d   j                   S )Nr   )r   )xs    r   <lambda>z!groups_from_app.<locals>.<lambda>   s    QqTYY r   )key)r   group_commandsr   r   create_default_commands	_get_itemr   is_resolvedshowid
setdefaultr   valuesr   r   r   
ValueErroritemsr
   r!   sort)r   r"   r*   	app_namesunique_apps
lazy_namesunique_lazyr   cmdcmd_idsubappapp_idr   r   r    r   registered_commandgroupsr'   s                      r   groups_from_appr?   0   s   . #,,c222''J5+H+H+JN ')I"$K')J*,K )mmDtm4c;' xxC%%fb188>,*-K'TFVR(//5$"(K#)( 
BM
 $$& 
6&,,...\\ 	6E%', 6GqzU* EJJ6(?5::,FW)XYY	6 "((%5	6
6 &++- Qi'(.uf=<<fllE222 L!-8JKL m^=OPQ !!# :99 ",SYY">SYYSYYLF :eU+#0 :"1:.!$QZ__

:",uzzlJ[-\"]]	: &,,eR[9:: #((* Qj().uc:99 ",SYY">SYYSYYLF L!-8JKL m^=OPQ !.611Q6M6 ./ 7s   
N5N5	input_appc                 N   g }g }t        | |      D ]R  \  }}|D ]H  }|j                  }t        |t              r 	 |j	                  |      }||   d   j                  |       J T |S # t
        $ r2 t        |      }|j                  |g f       |j                  |       Y Ww xY w)N)r"   r   )r?   r   r   r   indexr2   lenr   )	r@   r"   out	seen_appsr   registered_commandsr=   r   rB   s	            r   inverse_groups_from_apprG      s    
CI&5il&[ ("""5 
	($((C#{+&!,
 JqM  '
	(( J  &C

C9%  %&s   A))8B$#B$N)F)typingr   r   cyclopts.command_specr   cyclopts.groupr   cyclopts.utilsr   cyclopts.corer   r
   listr   r   r!   boolr?   rG   r   r   r   <module>rO      s    % -   !!   1eT#Y./01;1 1*s sd stE%QUVgQhJhDi?j slu D TRWX]_cdi_jXjRkMl r   