o
    㥵i!                     @   s   d dl mZ d dlm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mZ d dlmZ d dlmZ e
			
	
ddedee dededdf
ddZe
ddededdfddZdS )    )Path)SequenceN)HydraConfig)rank_zero_only)
DictConfig	OmegaConf	open_dict)Prompt)loggerdatamodel	callbacksr
   trainerpathsextrasFcfgprint_orderresolvesave_to_filereturnc                 C   s"  d}t jjd||d}g }|D ]}|| v r||ntd| dd| d  q| D ]}||vr7|| q,|D ])}|j|||d}| | }	t|	trUt	j
|	|d}
nt|	}
|t j|
d	 q:t | |rtt| jjd
d}t j||d W d   dS 1 sw   Y  dS dS )a  Prints content of DictConfig using Rich library and its tree structure.

    Args:
        cfg (DictConfig): Configuration composed by Hydra.
        print_order (Sequence[str], optional): Determines in what order config components are printed.
        resolve (bool, optional): Whether to resolve reference fields of DictConfig.
        save_to_file (bool, optional): Whether to export config to the hydra output folder.
    dimCONFIG)styleguide_stylezField 'z' not found in config. z
Skipping 'z' config printing...)r   yamlzconfig_tree.logwfileN)richtreeTreeappendlogwarningadd
isinstancer   r   to_yamlstrsyntaxSyntaxprintopenr   r   
output_dir)r   r   r   r   r   r    queuefieldbranchconfig_groupbranch_contentr    r3   P/home/ubuntu/.local/lib/python3.10/site-packages/fish_speech/utils/rich_utils.pyprint_config_tree   s:   





"r5   c                 C   s   |  dsGdt jjjv rtdtd tj	ddd}dd	 |
d
D }t|  || _W d   n1 s9w   Y  td| j  |rntt| jjdd}tj| j|d W d   dS 1 sgw   Y  dS dS )zOPrompts user to input tags from command line if no tags are provided in config.tagsidz)Specify tags before launching a multirun!z;No tags provided in config. Prompting user to input tags...z$Enter a list of comma separated tagsdev)defaultc                 S   s   g | ]
}|d kr|  qS ) )strip).0tr3   r3   r4   
<listcomp>[   s    z enforce_tags.<locals>.<listcomp>,NzTags: ztags.logr   r   )getr   r   hydrajob
ValueErrorr#   r$   r	   asksplitr   r6   infor,   r   r   r-   r   r+   )r   r   r6   r   r3   r3   r4   enforce_tagsQ   s   


"rG   )r   FF)F)pathlibr   typingr   r   rich.syntax	rich.treehydra.core.hydra_configr   lightning.pytorch.utilitiesr   	omegaconfr   r   r   rich.promptr	   fish_speech.utilsr
   r#   r(   boolr5   rG   r3   r3   r3   r4   <module>   s6    	A