
    !<io                     |    d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	m
Z
 erddlmZ e	 G d d                      ZdS )	z9Lazy-loadable command specification for deferred imports.    N)chain)TYPE_CHECKINGAny)FactorydefinefieldAppc                       e Zd ZU dZeed<   dZeeedf         z  dz  ed<    ee	          Z
e	eef         ed<    eddd          Zd	ed
<   ddZedefd            ZdS )CommandSpeca  Specification for a command that will be lazily loaded on first access.

    This allows registering commands via import path strings (e.g., "myapp.commands:create")
    without importing them until they're actually used, improving CLI startup time.

    Parameters
    ----------
    import_path : str
        Import path in the format "module.path:attribute_name".
        The attribute should be either a function or an App instance.
    name : str | tuple[str, ...] | None
        CLI command name. If None, will be derived from the attribute name via name_transform.
        For function imports: used as the name of the wrapper App.
        For App imports: must match the App's internal name, or ValueError is raised at resolution.
    app_kwargs : dict
        Keyword arguments to pass to App() if wrapping a function.
        Raises ValueError if used with App imports (Apps should be configured in their own definition).

    Examples
    --------
    >>> from cyclopts import App
    >>> app = App()
    >>> # Lazy load - doesn't import myapp.commands until "create" is executed
    >>> app.command("myapp.commands:create_user", name="create")
    >>> app()
    import_pathN.name
app_kwargsF)initdefaultreprz
App | None	_resolved
parent_appr
   returnc                    | j         | j         S | j                            d          \  }}}|r|st          d| j        d          	 t	          j        |          }n-# t          $ r }t          d|d| j                  |d}~ww xY w	 t          ||          }n1# t          $ r$}t          d|d|d	| j        d
          |d}~ww xY wddl	m
} t          ||          r| j        r t          d| j        d| j        d          | j        Z|j        d         | j        k    rDt          d| j        d|j        d         d| j        d| j         d|j        d          d          ddl	m}	  |	||           || _         nt          | j                  }
ddl	m} |
                    d|j                   |
                    d|j                   d|
vr|j        
|j        |
d<    ||
|            |dd| j        i|
| _         | j                             |           t-          | j         j        | j         j                  D ]}d| j         |         _        | j         S )a  Import and resolve the command on first access.

        Parameters
        ----------
        parent_app : App
            Parent app to inherit defaults from (help_flags, version_flags, groups).
            Required to match the behavior of direct command registration.

        Returns
        -------
        App
            The resolved App instance, either imported directly or wrapping a function.

        Raises
        ------
        ValueError
            If import_path is not in the correct format "module.path:attribute_name".
        ImportError
            If the module cannot be imported.
        AttributeError
            If the attribute doesn't exist in the module.
        N:zInvalid import path: z/. Expected format: 'module.path:attribute_name'zCannot import module z from zModule z has no attribute z (from import path )r   r	   z8Cannot apply configuration to imported App. Import path z0 resolves to an App, but kwargs were specified: z.. Configure the App in its definition instead.z(Imported App name mismatch. Import path z resolves to an App with name=z., but it was registered with CLI command name=z. Either use app.command('z	', name='z%') or change the App's name to match.)_apply_parent_defaults_to_app)_apply_parent_groups_to_kwargs
help_flagsversion_flagsversionr   F )r   r   
rpartition
ValueError	importlibimport_moduleImportErrorgetattrAttributeErrorcyclopts.corer
   
isinstancer   r   r   dictr   
setdefaultr   r   r   r   r   show)selfr   module_path_	attr_namemoduleetargetr
   r   r   r   flags                /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/cyclopts/command_spec.pyresolvezCommandSpec.resolve0   se   . >%>! %)$4$?$?$D$D!Q	 	) 	k(8kkk  
	h,[99FF 	h 	h 	h_k__4K[__``fgg	h	VY//FF 	 	 	 p+pp9pp[_[kppp 	 	&%%%%%fc"" *	+  D#'#3D D26/D D D   y$Q49)D)D :#'#3: :U[U`abUc: :CG9: : 04/?: : KQ+VW.: : :   DCCCCC))&*===#DNN do..JDDDDDD!!,
0EFFF!!/:3KLLL
**z/A/M(2(:
9%**:zBBB S>>di>:>>DNN""6*** $.3T^5QRR 	. 	.D(-DN4 %%~s0   
A 
B	)BB	B 
C(CCc                     | j         duS )z9Check if this command has been imported and resolved yet.N)r   )r+   s    r3   is_resolvedzCommandSpec.is_resolved   s     ~T))    )r   r
   r   r
   )__name__
__module____qualname____doc__str__annotations__r   tupler   r(   r   r   r   r   r4   propertyboolr6   r   r7   r3   r   r      s          6 )-D#c3h
$
&---!(JS#X...#e5IIII|IIIb b b bH *T * * * X* * *r7   r   )r;   r!   	itertoolsr   typingr   r   attrsr   r   r   r&   r
   r   r   r7   r3   <module>rD      s    ? ?           % % % % % % % % ( ( ( ( ( ( ( ( ( ( "!!!!!! I* I* I* I* I* I* I* I* I* I*r7   