U
    %d                     @   sz   d dl Z d dlZd dlmZ d dlZd dlmZ eej	d Z
edddZeedd	d
Zdadd Zdd Ze  dS )    N)Path)module_utilslib)r   c                 C   s(   t jdkrdnd}t|  d|  }|S )NntZpydso.)osname_LIB_DIR)r   suffixpath r   9/tmp/pip-unpacked-wheel-lbdmvq91/torchaudio/_extension.py_get_lib_path   s    r   )r   returnc                 C   s0   t | }| sdS tj| tj| dS )a  Load extension module

    Note:
        In case `torchaudio` is deployed with `pex` format, the library file
        is not in a standard location.
        In this case, we expect that `libtorchaudio` is available somewhere
        in the search path of dynamic loading mechanism, so that importing
        `_torchaudio` will have library loader find and load `libtorchaudio`.
        This is the reason why the function should not raising an error when the library
        file is not found.

    Returns:
        bool:
            True if the library file is found AND the library loaded without failure.
            False if the library file is not found (like in the case where torchaudio
            is deployed with pex format, thus the shared library file is
            in a non-standard location.).
            If the library file is found but there is an issue loading the library,
            (such as missing dependency) then this function raises the exception as-is.

    Raises:
        Exception:
            If the library file is found, but there is an issue loading the library file,
            (when underlying `ctype.DLL` throws an exception), this function will pass
            the exception as-is, instead of catching it and returning bool.
            The expected case is `OSError` thrown by `ctype.DLL` when a dynamic dependency
            is not found.
            This behavior was chosen because the expected failure case is not recoverable.
            If a dependency is missing, then users have to install it.
    FT)r   existstorchopsZload_libraryclasses)r   r   r   r   r   	_load_lib   s    r   Fc               
   C   s   t rd S tjj stdztd W n, tk
rT }  ztd| W 5 d } ~ X Y nX dd l	}tjj
  tjj dkrtjjd da d S )Nzftorchaudio is not compiled with FFmpeg integration. Please set USE_FFMPEG=1 when compiling torchaudio.Zlibtorchaudio_ffmpegz6FFmpeg libraries are not found. Please install FFmpeg.r      T)_FFMPEG_INITIALIZEDr   r   
torchaudioZis_ffmpeg_availableRuntimeErrorr   OSErrorImportErrorZtorchaudio._torchaudio_ffmpegZffmpeg_initZffmpeg_get_log_levelZffmpeg_set_log_level)errr   r   r   r   _init_ffmpeg;   s    r   c                  C   sP   t dstd d S td ddlm}  z
t  W n tk
rJ   Y nX d S )Nztorchaudio._torchaudioz*torchaudio C++ extension is not available.Zlibtorchaudior   _torchaudio)	
_mod_utilsZis_module_availablewarningswarnr   r   r   r   	Exceptionr   r   r   r   _init_extensionS   s    


r$   )r   r!   pathlibr   r   Ztorchaudio._internalr   r    __file__parentr
   strr   boolr   r   r   r$   r   r   r   r   <module>   s   '