gws.lib.importer

Handle dynamic imports

Source code: gws.lib.importer

Package Contents

exception gws.lib.importer.Error

Bases: gws.Error

Custom error class for import-related exceptions.

gws.lib.importer.import_from_path(path: str, base_dir: str = gws.c.APP_DIR)

Imports a module from a given file path.

Parameters:
  • path – The relative or absolute path to the module file.

  • base_dir – The base directory to resolve relative paths. Defaults to gws.c.APP_DIR.

Returns:

The imported module.

Raises:

Error – If the module file is not found or a base directory cannot be located.

gws.lib.importer.load_file(path: str) dict

Load a python file and return its globals.

gws.lib.importer.load_string(text: str, path='') dict

Load a string as python code and return its globals.