a
    h                     @   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	e
edddZe
d	d
dZg Zd e
ee
 edddZd!e
ee
 ed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)wrapspartial)Optionalc                 C   sb   | t jvr|S t j| d}g d}g d}||v r8dS ||vr^td|  d| d||  dS )	z-Check if environment varable has True-y value0)1trueTRUEonONyesZYES)r   falseFALSEoffZOFFnoNOTz'Unexpected environment variable value `=z`. Expected one of F)osenvirongetRuntimeError)vardefaultvalZtruesZfalses r   O/var/www/auris/lib/python3.9/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>"       z&is_module_available.<locals>.<genexpr>)allr   r   r   r   is_module_available   s    r)   r(   c                     sP   dd | D }|sdd }n0t |dkr6d|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>+   r&   z#requires_module.<locals>.<listcomp>c                 S   s   | S r   r   funcr   r   r   	decorator/   s    z"requires_module.<locals>.decorator   zmodule: r   z	modules: c                    s   t   fdd}|S )Nc                     s    t  j d j d d S )N.z
 requires r   
__module____name__argskwargs)r,   reqr   r   wrapped6   s    z3requires_module.<locals>.decorator.<locals>.wrappedr   r,   r7   r6   r+   r   r-   5   s    )len)r   missingr-   r   r:   r   requires_module%   s    
$r=   F)	directionversionremovec                    s    t  fdd}|S )Nc                     sR    d  }r6|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)r4   r5   messager>   r,   namer@   r?   r   r   r7   A   s
    $z wrap_deprecated.<locals>.wrappedr8   )r,   rI   r>   r?   r@   r7   r   rH   r   wrap_deprecated@   s    rJ   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                    sn   t | | j d| j  d}d}rD|dd u r8dn d7 }d| d  d	| j d
|_t| |S )Nr/   r?   r@   z#This function has been deprecated. zIt will be removed from futurerA   z%DEPRECATED

    .. warning::

       z
       z

    
    )rJ   r1   r2   __doc__UNSUPPORTEDappend)r,   r7   rG   r>   r@   r?   r   r   r-   S   s     


zdeprecated.<locals>.decoratorr   )r>   r?   r@   r-   r   rQ   r   
deprecatedJ   s    	rR   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.9TrK   c                 C   sH   t | j| j d| j |ddd| _d| d| j d| _t|  | S )Nr/   rS   TrK   ztDEPRECATED

.. warning::

    This class is deprecated from version 2.8. It will be removed in the 2.9 release.
    
)rJ   __init__r1   r2   rN   rO   rP   )cmsgr   r   r   dropping_class_supportv   s    $
	
rX   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.
    rT   rM   )rN   )rV   rW   rI   r   r   r   dropping_const_support   s    
rY   )rW   c                    s    fdd}|S )zLGenerate decorator to give users message about missing TorchAudio extension.c                    s   t   fdd}|S )Nc                     s    t  j d j d d S )Nr/    r0   r3   )r,   rG   r   r   r7      s    z5fail_with_message.<locals>.decorator.<locals>.wrappedr8   r9   rG   r+   r   r-      s    z$fail_with_message.<locals>.decoratorr   )rG   r-   r   r[   r   fail_with_message   s    r\   c                 C   s   | S )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    r]   )NF)NF)importlib.utilr   r   rE   	functoolsr   r   typingr   r   rD   boolr)   r=   rO   rJ   rR   ZDEPRECATION_MSGZIO_DEPRECATION_MSGZdropping_supportrX   rY   Zdropping_class_io_supportZdropping_io_supportr\   r]   r   r   r   r   <module>   s*   

 