o
    i?                     @   sV   d Z ddl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 dZdS )z9Lazy-loadable command specification for deferred imports.    N)TYPE_CHECKINGAny)FactorydefinefieldAppc                   @   s   e Zd ZU dZeed< dZeeedf B dB ed< ee	Z
e	eef ed< eddddZd	ed
< dddZedefd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                 C   s  | j dur| j S | jd\}}}|r|std| jdzt|}W n ty= } ztd|d| j|d}~ww zt||}W n tya } ztd|d|d	| jd
|d}~ww ddl	m
} t||r| jr}td| jd| jd| jdur|jd | jkrtd| jd|jd d| jd| j d|jd  dddl	m}	 |	|| || _ | j S t| j}
ddl	m} |
d|j |
d|j d|
vr|jdur|j|
d< ||
| |dd| ji|
| _ | 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    )r   r
   
rpartition
ValueError	importlibimport_moduleImportErrorgetattrAttributeErrorcyclopts.corer   
isinstancer   r   r   dictr   
setdefaultr   r   r   r   )selfr   module_path_	attr_namemoduleetargetr   r   r   r   r   r   [/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/cyclopts/command_spec.pyresolve/   sz   

		



zCommandSpec.resolvec                 C   s
   | j duS )z9Check if this command has been imported and resolved yet.N)r   )r&   r   r   r-   is_resolved   s   
zCommandSpec.is_resolved)r   r   r   r   )__name__
__module____qualname____doc__str__annotations__r   tupler   r$   r   r   r   r   r.   propertyboolr/   r   r   r   r-   r	      s   
 
_r	   )r3   r   typingr   r   attrsr   r   r   r"   r   r	   r   r   r   r-   <module>   s    