o
    %ݫi                     @   s0   d Z ddlZddlZddlZdd Zdd ZdS )zSuperpowers which should be sparingly used.

This library contains functions for importing python files and
for running shell commands. Remember, with great power comes great
responsibility.

Authors
 * Mirco Ravanelli 2020
 * Aku Rouhe 2021
    Nc                 C   s@   t | } | dj}tj|| }tj|}|j	| |S )a<  Import module from absolute path

    Arguments
    ---------
    path : str, pathlib.Path
        The path to the module to import

    Returns
    -------
    module
        The loaded module

    Implementation taken from:
    https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
     )
pathlibPathwith_suffixname	importlibutilspec_from_file_locationmodule_from_specloaderexec_module)path
modulenamespecmodule r   Q/home/ubuntu/.local/lib/python3.10/site-packages/speechbrain/utils/superpowers.pyimport_from_path   s   
r   c                 C   s   ddl m} |t}tj| tjtjdd}| \}}|jdkr(t|j	dd|j	ddd |j	dd }|
| |||jfS )a  This function can be used to run a command in the bash shell.

    Arguments
    ---------
    cmd : str
        Shell command to run.

    Returns
    -------
    bytes
        The captured standard output.
    bytes
        The captured standard error.
    int
        The returncode.

    Raises
    ------
    OSError
        If returncode is not 0, i.e., command failed.

    Example
    -------
    >>> out, err, code = run_shell("echo 'hello world'")
    >>> _ = out.decode(errors="ignore")
    r   )
get_loggerT)stdoutstderrshellreplace)errors
)speechbrain.utils.loggerr   __name__
subprocessPopenPIPEcommunicate
returncodeOSErrordecodedebug)cmdr   loggerpoutputerrmsgr   r   r   	run_shell)   s   

r+   )__doc__r   r   r   r   r+   r   r   r   r   <module>   s    