pype.misc

pype.misc.import_module(module_name, module_path)[source]

Import a module from a specific path.

Args:

module_name: Name to give to the imported module module_path: Path to the module file

Returns:

Imported module object

Raises:

ImportError: If module cannot be loaded

Parameters:
  • module_name (str)

  • module_path (str)

Return type:

ModuleType

pype.misc.generate_uid(n=4, timestamp=True)[source]

Generate a unique identifier with timestamp and random chars.

Parameters:
Return type:

str

pype.misc.package_modules(package)[source]

Get all Python modules in a package directory.

Parameters:

package (ModuleType)

Return type:

Set[str]

pype.misc.package_files(package, extension)[source]

Get all files with specific extension in a package directory.

Parameters:
Return type:

Set[str]

pype.misc.try_import(path, module_name)[source]

Import a module, creating __init__.py if needed.

Args:

path: Directory path where the module should be located/created module_name: Name of the module to import

Returns:

Imported module object

Raises:

ImportError: If module cannot be created or loaded

Parameters:
  • path (str)

  • module_name (str)

Return type:

ModuleType

pype.misc.get_modules(parent, subparsers, progs)[source]

Get all modules and their parsers.

Parameters:
Return type:

Dict

pype.misc.get_modules_names(parent)[source]

Get names of all valid modules in parent.

Parameters:

parent (ModuleType)

Return type:

List[str]

pype.misc.get_module_method(parent, module, method)[source]

Get a specific method from a module.

Parameters:
Return type:

Any | None

pype.misc.xopen(filename, mode='r')[source]

Smart file opener that handles gzip and stdin/stdout.

Parameters:
Return type:

Any

pype.misc.check_exit_code(process, sting, results_dict, log)[source]
pype.misc.human_format(num, base=1000)[source]

Format numbers with human readable units.

Parameters:
Return type:

str

pype.misc.bases_format(string_unit, base=1000)[source]

Convert string with units to number of bases.

Parameters:
  • string_unit (str)

  • base (int)

Return type:

int

pype.misc.basename_no_extension(file_name)[source]

Get basename without extension.

Parameters:

file_name (str)

Return type:

str

class pype.misc.Tee(f1, f2)[source]

Bases: object

__init__(f1, f2)[source]
write(msg)[source]
class pype.misc.SubcommandHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]

Bases: RawDescriptionHelpFormatter

class pype.misc.DefaultHelpParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'pype.argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True)[source]

Bases: ArgumentParser

error(message: string)[source]

Prints a usage message incorporating the message to stderr and exits.

If you override this in a subclass, it should not return – it should either exit or raise an exception.