ramble.util.imp package

Consolidated module for all imports done by Ramble.

Many parts of Ramble have to import Python code. This utility package wraps Ramble’s interface with Python’s import system.

We do this because Python’s import system is confusing and changes from Python version to Python version, and we should be able to adapt our approach to the underlying implementation.

Currently, this uses importlib.machinery where available and imp when importlib is not completely usable.

Submodules

ramble.util.imp.imp_importer module

ramble.util.imp.importlib_importer module

Implementation of Ramble imports that uses importlib underneath.

importlib is only fully implemented in Python 3.

class ramble.util.imp.importlib_importer.PrependFileLoader(full_name, path, prepend=None)[source]

Bases: SourceFileLoader

get_data(path)[source]

Return the data from path as raw bytes.

path_stats(path)[source]

Return the metadata for the path.

ramble.util.imp.importlib_importer.load_source(full_name, path, prepend=None)[source]

Import a Python module from source.

Load the source file and add it to sys.modules.

Parameters:
  • full_name (str) – full name of the module to be loaded

  • path (str) – path to the file that should be loaded

  • prepend (str, optional) – some optional code to prepend to the loaded module; e.g., can be used to inject import statements

Returns:

the loaded module

Return type:

(ModuleType)