o
    #im                     @   s   d dl Zd dlZd dlZd dlmZmZ d dlmZ dd Z	de
defdd	Zde
fd
dZg Zd"de
dee
 defddZd"de
dee
 defddZdZdZeedddZefddZedfddZeeedZeedddZdd Zd d! ZdS )#    N)partial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/veenaModal/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>.wrappedr   r/   r<   r;   r.   r   r0   5      )len)r    missingr0   r   r@   r   requires_module%   s   $rD   F	directionversionremovec                    s    t  fdd}|S )Nc                     sR    d  }r|dd u rdndt   d7 }tj|dd | i |S )Nz has been deprecated. z It will be removed from za futurezthe 
 release.    )
stacklevel)strwarningswarn)r9   r:   messagerE   r/   namerG   rF   r   r   r<   C   s
   $z wrap_deprecated.<locals>.wrappedr>   )r/   rP   rE   rF   rG   r<   r   rO   r   wrap_deprecatedB   s   rQ   c                    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                    sd   t | | j d| j  d}d}r"|dd u rdn d7 }d| d  d	| j d
|_|S )Nr4   rF   rG   z#This function has been deprecated. zIt will be removed from futurerH   z%DEPRECATED

    .. warning::

       z
       z

    
    )rQ   r6   r7   __doc__)r/   r<   rN   rE   rG   rF   r   r   r0   W   s    

zdeprecated.<locals>.decoratorr   )rE   rF   rG   r0   r   rV   r   
deprecatedN   s   	rW   zThis deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information.a*  This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information.2.9TrR   c                 C   sH   t | j| j d| j |ddd| _d| d| j d| _t|  | S )Nr4   rX   TrR   ztDEPRECATED

.. warning::

    This class is deprecated from version 2.8. It will be removed in the 2.9 release.
    
)rQ   __init__r6   r7   rU   UNSUPPORTEDappend)cmsgr   r   r   dropping_class_support|   s   $

	r_   c                 C   s   d| d| j  d| _ | S )Nz[DEPRECATED]

.. warning::

    This object is deprecated deprecated from version 2.8. It will be removed in the 2.9 release.
    rY   rT   )rU   )r]   r^   rP   r   r   r   dropping_const_support   s   
r`   )r^   c                    s    fdd}|S )zLGenerate decorator to give users message about missing TorchAudio extension.c                    r2   )Nc                     r3   )Nr4    r5   r8   )r/   rN   r   r   r<      r=   z5fail_with_message.<locals>.decorator.<locals>.wrappedr>   r?   rN   r.   r   r0      rA   z$fail_with_message.<locals>.decoratorr   )rN   r0   r   rb   r   fail_with_message   s   rc   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_op   s   rd   )NF)importlib.utilr#   r   rL   	functoolsr   r   typingr   r   rK   boolr+   rD   r[   rQ   rW   DEPRECATION_MSGIO_DEPRECATION_MSGdropping_supportr_   r`   dropping_class_io_supportdropping_io_supportrc   rd   r   r   r   r   <module>   s,    
 