speechbrain.utils.superpowers module

Superpowers 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

Summary

Functions:

import_from_path

Import module from absolute path

run_shell

This function can be used to run a command in the bash shell.

Reference

speechbrain.utils.superpowers.import_from_path(path)[source]

Import module from absolute path

Parameters

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)

speechbrain.utils.superpowers.run_shell(cmd)[source]

This function can be used to run a command in the bash shell.

Parameters

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")