o
    헦i                     @   s   d dl Zd dlZd dlZd dlmZ d dlmZ dd Zde	de
fdd	Zde	fd
dZdde	dee	 de
fddZdd Zdd ZdS )    Nwraps)Optionalc                 C   sb   | t jvr|S t j| d}g d}g d}||v rdS ||vr/td|  d| d||  dS )	z-Check if environment varable has True-y value0)1trueTRUEonONyesYES)r   falseFALSEoffOFFnoNOTz'Unexpected environment variable value `=z`. Expected one of F)osenvirongetRuntimeError)vardefaultvaltruesfalses r   _/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/torchaudio/_internal/module_utils.pyeval_env   s   
r   modulesreturnc                  G   s   t dd | D S )aP  Returns if a top-level module with :attr:`name` exists *without**
    importing it. This is generally safer than try-catch block around a
    `import X`. It avoids third party libraries breaking assumptions of some of
    our tests, e.g., setting multiprocessing start method when imported
    (see librosa/#747, torchvision/#544).
    c                 s   s     | ]}t j|d uV  qd S N)	importlibutil	find_spec.0mr   r   r   	<genexpr>"   s    z&is_module_available.<locals>.<genexpr>)all)r    r   r   r   is_module_available   s   r+   c                     sR   dd | D }|sdd }|S t |dkrd|d  nd|   fd	d}|S )
zDecorate function to give error message if invoked without required optional modules.

    This decorator is to give better error message to users rather
    than raising ``NameError:  name 'module' is not defined`` at random places.
    c                 S   s   g | ]}t |s|qS r   )r+   r&   r   r   r   
<listcomp>+   s    z#requires_module.<locals>.<listcomp>c                 S      | S r"   r   funcr   r   r   	decorator/   s   z"requires_module.<locals>.decorator   zmodule: r   z	modules: c                       t   fdd}|S )Nc                        t  j d j d )N.z
 requires r   
__module____name__argskwargs)r/   reqr   r   wrapped6      z3requires_module.<locals>.decorator.<locals>.wrappedr   r/   r<   r;   r.   r   r0   5      )len)r    missingr0   r   r?   r   requires_module%   s   $rC   F	directionversionremovec                    s    fdd}|S )zDecorator to add deprecation message

    Args:
        direction (str): Migration steps to be given to users.
        version (str or int): The version when the object will be removed
        remove (bool): If enabled, append future removal message.
    c                    s^   t   fdd}d}r|dd u rdn d7 }d j d| d	 d
|_|S )Nc                     sT   j  dj d  }r|dd u rdn d7 }tj|dd | i |S )Nr4   z has been deprecated. z It will be removed from future
 release.    )
stacklevel)r6   r7   warningswarn)r9   r:   message)rD   r/   rF   rE   r   r   r<   I   s
   z.deprecated.<locals>.decorator.<locals>.wrappedz#This function has been deprecated. zIt will be removed from rG   rH   zDEPRECATED: z

    .. warning::

       z
       z	
        )r   __doc__)r/   r<   rM   rD   rF   rE   r.   r   r0   H   s   

zdeprecated.<locals>.decoratorr   )rD   rE   rF   r0   r   rO   r   
deprecated?   s   	rP   c                    s    fdd}|S )zLGenerate decorator to give users message about missing TorchAudio extension.c                    r2   )Nc                     r3   )Nr4    r5   r8   )r/   rM   r   r   r<   f   r=   z5fail_with_message.<locals>.decorator.<locals>.wrappedr   r>   rM   r.   r   r0   e   r@   z$fail_with_message.<locals>.decoratorr   )rM   r0   r   rR   r   fail_with_messageb   s   rS   c                 C   r-   )zlOp-op decorator. Used in place of fail_with_message when a functionality that requires extension works fine.r   r.   r   r   r   no_opo   s   rT   )NF)importlib.utilr#   r   rK   	functoolsr   typingr   r   strboolr+   rC   rP   rS   rT   r   r   r   r   <module>   s    
#