o
    x¡·i<  ã                   @  sà   d dl mZ d dlZd dlZd dl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 d dlmZ d dlmZ ejdd	G d
d„ dƒƒZd&dd„Zd'dd„Zd(dd„Zd)dd„Zd*dd „Zd+d"d#„Zd,d$d%„ZdS )-é    )ÚannotationsN)ÚNever)Ú
get_sentry)Úerror_reporting_enabledÚis_debug)Úwandb_setup)Úget_core_pathT)Úfrozenc                   @  s&   e Zd ZU dZded< dZded< dS )ÚLaunchConfigz!Configuration for launching LEET.ÚstrÚ	wandb_dirNú
str | NoneÚrun_file)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   © r   r   úG/home/ubuntu/.local/lib/python3.10/site-packages/wandb/cli/beta_leet.pyr
      s   
 r
   Úmessager   Úreturnr   c                 C  s"   t jd| › dd t d¡ dS )z,Print an error message and exit with code 1.zError: T)Úerré   N)ÚclickÚechoÚsysÚexit)r   r   r   r   Ú_fatal   s   r   Údir_pathúpathlib.Pathúpathlib.Path | Nonec                 C  s&   t |  d¡ƒ}t|ƒdkr|d S dS )zfFind a run-*.wandb file in the given directory.

    Returns None if not found or multiple found.
    zrun-*.wandbr   r   N)ÚlistÚglobÚlen)r   Úwandb_filesr   r   r   Ú_find_wandb_file_in_dir    s   r&   Úpathr   c                 C  sº   | st  ¡ jj}tt|ƒdS t | ¡ ¡ }| 	¡ r6|j
dkr/|j}|j}tt|ƒt|ƒdS td|› ƒ | ¡ rTt|ƒ}|rM|j}tt|ƒt|ƒdS tt|ƒdS td|› ƒ dS )aE  Resolve the given path into a LaunchConfig.

    Behavior:
        - No path: Use default wandb_dir (workspace mode)
        - .wandb file: Parent's parent as wandb_dir, file as run_file
        - Run directory: Parent as wandb_dir, found .wandb as run_file
        - Other directory: Treat as wandb_dir (workspace mode)
    )r   z.wandb)r   r   zNot a .wandb file: zPath does not exist: N)r   Ú	singletonÚsettingsr   r
   r   ÚpathlibÚPathÚresolveÚis_fileÚsuffixÚparentr   Úis_dirr&   )r'   r   ÚresolvedÚrun_dirÚ
wandb_filer   r   r   Ú_resolve_path+   s"   	
r4   ú	list[str]c                  C  s6   t ƒ dg} tƒ s|  d¡ tddr|  ddg¡ | S )z=Build the common base arguments for wandb-core leet commands.Úleetz--no-observabilityÚFalse)Údefaultz--log-levelz-4)r   r   Úappendr   Úextend©Úargsr   r   r   Ú
_base_argsM   s   


r=   r<   c              
   C  sX   zt j| tjdd}t |j¡ W dS  ty+ } ztƒ  	|¡ W Y d}~dS d}~ww )zFRun wandb-core with the given arguments and exit with its return code.T)ÚenvÚ	close_fdsN)
Ú
subprocessÚrunÚosÚenvironr   r   Ú
returncodeÚ	Exceptionr   Úreraise)r<   ÚresultÚer   r   r   Ú	_run_coreZ   s   €ÿrI   Úpprofc                 C  s\   t ƒ jdd t| ƒ}tƒ }|jr| d|jg¡ |r"| d|g¡ | |j¡ t|ƒ dS )zLaunch the LEET TUI.r6   ©Úprocess_contextz
--run-filez--pprofN)	r   Úconfigure_scoper4   r=   r   r:   r9   r   rI   )r'   rJ   Úconfigr<   r   r   r   Úlaunchc   s   rO   c                  C  s*   t ƒ jdd tƒ } |  d¡ t| ƒ dS )z%Launch the LEET configuration editor.zleet-configrK   z--configN)r   rM   r=   r9   rI   r;   r   r   r   Úlaunch_configu   s   
rP   )r   r   r   r   )r   r    r   r!   )r'   r   r   r
   )r   r5   )r<   r5   r   r   )r'   r   rJ   r   r   r   )r   r   )Ú
__future__r   ÚdataclassesrB   r*   r@   r   r   Útyping_extensionsr   Úwandb.analyticsr   Ú	wandb.envr   r   Ú	wandb.sdkr   Ú
wandb.utilr   Ú	dataclassr
   r   r&   r4   r=   rI   rO   rP   r   r   r   r   Ú<module>   s*    




"

	