o
    ‰ôj“  ã                   @   sæ   U d dl Z d dlZd dlmZ d dlmZmZ d dlm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 d d
lmZ defdd„Zdedefdd„Zeƒ Zeed< G dd„ dƒZG dd„ dƒZG dd„ dƒZdS )é    N)Údedent)ÚAnyÚOptional)Úversion)Údeprecation_warning)ÚHydra)Úcreate_config_search_pathÚ.detect_calling_file_or_module_from_stack_frameÚdetect_task_name)ÚGlobalHydra)Ú	Singleton)ÚHydraExceptionÚreturnc                   C   s   t tjv rt tjt  ¡S d S ©N)r   r   Ú
_instancesÚcopyÚdeepcopy© r   r   úc/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/hydra/initialize.pyÚget_gh_backup   s   
r   Ú
_gh_backupc                 C   s"   | d u r
t jt= d S | t jt< d S r   )r   r   r   )r   r   r   r   Úrestore_gh_from_backup   s   r   Ú_UNSPECIFIED_c                   @   s‚   e Zd ZdZeddefdee dee dedee ddf
d	d
„Zde	de	ddfdd„Z
de	de	de	ddfdd„Zdefdd„ZdS )Ú
initializea:  
    Initializes Hydra and add the config_path to the config search path.
    config_path is relative to the parent of the caller.
    Hydra detects the caller type automatically at runtime.

    Supported callers:
    - Python scripts
    - Python modules
    - Unit tests
    - Jupyter notebooks.
    :param config_path: path relative to the parent of the caller
    :param job_name: the value for hydra.job.name (By default it is automatically detected based on the caller)
    :param caller_stack_depth: stack depth of the caller, defaults to 1 (direct caller).
    Né   Úconfig_pathÚjob_nameÚcaller_stack_depthÚversion_baser   c                 C   s®   t ƒ | _t |¡ |tu r,t d¡rd }n|tu r*d}ttd|› d�ƒdd� d}nd}|d ur:tj	 
|¡r:tdƒ‚t|d	 ƒ\}}|d u rLt||d
�}tj||||d� d S )Nz1.2zOhttps://hydra.cc/docs/1.2/upgrades/1.0_to_1.1/changes_to_hydra_main_config_pathz`                    config_path is not specified in hydra.initialize().
                    See z for more information.é   )ÚmessageÚ
stacklevelÚ.z,config_path in initialize() must be relativer   )Úcalling_fileÚcalling_module©r#   r$   r   r   )r   r   r   Úsetbaser   Úbase_at_leastr   r   ÚosÚpathÚisabsr   r	   r
   r   Ú create_main_hydra_file_or_module)Úselfr   r   r   r   Úurlr#   r$   r   r   r   Ú__init__5   s@   

þÿúÿÿ
üzinitialize.__init__ÚargsÚkwargsc                 O   ó   d S r   r   ©r,   r/   r0   r   r   r   Ú	__enter__b   ó   zinitialize.__enter__Úexc_typeÚexc_valÚexc_tbc                 C   ó   t | jƒ d S r   ©r   r   ©r,   r5   r6   r7   r   r   r   Ú__exit__e   ó   zinitialize.__exit__c                 C   ó   dS )Nzhydra.initialize()r   ©r,   r   r   r   Ú__repr__h   r4   zinitialize.__repr__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚstrÚintr.   r   r3   r;   r?   r   r   r   r   r   %   s(    ûþýüû
ú-r   c                   @   sn   e Zd ZdZdefdededee fdd„Zded	ed
dfdd„Z	dededed
dfdd„Z
d
efdd„ZdS )Úinitialize_config_modulea7  
    Initializes Hydra and add the config_module to the config search path.
    The config module must be importable (an __init__.py must exist at its top level)
    :param config_module: absolute module name, for example "foo.bar.conf".
    :param job_name: the value for hydra.job.name (default is 'app')
    ÚappÚconfig_moduler   r   c                 C   s2   t ƒ | _t |¡ tjd |› d|› �d |d� d S )Nr"   r%   )r   r   r   r&   r   r+   )r,   rH   r   r   r   r   r   r.   t   s   

üz!initialize_config_module.__init__r/   r0   r   Nc                 O   r1   r   r   r2   r   r   r   r3   …   r4   z"initialize_config_module.__enter__r5   r6   r7   c                 C   r8   r   r9   r:   r   r   r   r;   ˆ   r<   z!initialize_config_module.__exit__c                 C   r=   )Nz hydra.initialize_config_module()r   r>   r   r   r   r?   ‹   r4   z!initialize_config_module.__repr__©r@   rA   rB   rC   r   rD   r   r.   r   r3   r;   r?   r   r   r   r   rF   l   s    
üþý
ürF   c                	   @   sr   e Zd ZdZdefdededee ddfdd	„Zd
ededdfdd„Z	dedededdfdd„Z
defdd„ZdS )Úinitialize_config_diraV  
    Initializes Hydra and add an absolute config dir to the to the config search path.
    The config_dir is always a path on the file system and is must be an absolute path.
    Relative paths will result in an error.
    :param config_dir: absolute file system path
    :param job_name: the value for hydra.job.name (default is 'app')
    rG   Ú
config_dirr   r   r   Nc                 C   sB   t ƒ | _t |¡ tj |¡stdƒ‚t|d�}t	j
||d� d S )Nz@initialize_config_dir() requires an absolute config_dir as input)Úsearch_path_dir)Ú	task_nameÚconfig_search_path)r   r   r   r&   r(   r)   r*   r   r   r   Úcreate_main_hydra2)r,   rK   r   r   Zcspr   r   r   r.   ˜   s   
ÿ
zinitialize_config_dir.__init__r/   r0   c                 O   r1   r   r   r2   r   r   r   r3   ¬   r4   zinitialize_config_dir.__enter__r5   r6   r7   c                 C   r8   r   r9   r:   r   r   r   r;   ¯   r<   zinitialize_config_dir.__exit__c                 C   r=   )Nzhydra.initialize_config_dir()r   r>   r   r   r   r?   ²   r4   zinitialize_config_dir.__repr__rI   r   r   r   r   rJ   �   s     üþýü
ûrJ   )r   r(   Útextwrapr   Útypingr   r   Úhydrar   Z#hydra._internal.deprecation_warningr   Úhydra._internal.hydrar   Úhydra._internal.utilsr   r	   r
   Úhydra.core.global_hydrar   Zhydra.core.singletonr   Úhydra.errorsr   r   r   Úobjectr   Ú__annotations__r   rF   rJ   r   r   r   r   Ú<module>   s"   
G#