Modules Importer¶
Module Imports.
This file contains the ModulesImporter class.
- class modules_importer.ModulesImporter(modules, filenames=None)¶
ModulesImporter class.
This class has the goal of loading the modules which are specified in the given rules.
- __init__(modules, filenames=None)¶
It initializes the class.
- Parameters
modules (list) – modules (str) which should be loaded after.
filenames (list) – modules filenames (str). The default value is None, and if this value remains, modules will be used as filename.
- __weakref__¶
list of weak references to the object (if defined)
- get_instance(module_name, class_name)¶
It returns an instance of the class of a module.
- Parameters
module_name (str) – module name which should contains class_name.
class_name (str) – class name which is attempted to return.
- Returns
Module instance if module is loaded; None otherwise
- get_module(module_name)¶
It returns an already loaded module.
- Parameters
module_name (str) – module name which is attempted to return.
- Raises
BOAModuleNotLoaded – when it is attempted to get a module which is not loaded.
Exception – when a module is detected as loaded but it is not loaded in sys.modules. It should not happen.
- Returns
Module if loaded; None otherwise
- get_nloaded()¶
It returns the number of loaded modules at the moment of the calling.
- Returns
loaded modules
- Return type
int
- get_nmodules()¶
It returns the number of modules which were suplied to the class to be loaded.
A different variable is being used instead of len() method because the variable which contains the methods to be loaded mutates through the execution of the class methods.
- Returns
initial modules to be loaded
- Return type
int
- get_not_loaded_modules()¶
It returns the modules which have not been loaded.
- Returns
not loaded modules
- Return type
list
- is_module_loaded(module_name)¶
It checks if a concrete module is already loaded.
- Parameters
module_name (str) – module to check if it is loaded.
- Returns
module_name is loaded
- Return type
bool
- load(module_subdir=None)¶
It attempts to load all the modules which were specified.
This method iterates through self.modules to attempt to loading the modules. First, it checks if the module is already loaded. Then, it attempts to load the module and if it is not able to, it skips the current module to next.
The modules must be in Other.modules_directory directory.
- Parameters
module_subdir (str) – subdir of Other.modules_directory where the module will be looked for instead of directly look for in Other.modules_directory
- classmethod load_and_get_instance(module, absolute_file_path, class_name, verbose=True)¶
Class method which attempts to load a module and return an instance of it.
If the module is already loaded, it will skip the loading part and it will continue to next phase: get the instance.
- Parameters
module (str) – module name to be loaded.
absolute_file_path (str) – full path to the file which contains the module to be loaded.
class_name (str) – class name inside the module which is going to be instantiated.
verbose (bool) – if True, a message will be displayed if the loading success.
- Returns
an instance of “module.class” which has been specified or None if could not.
- Return type
instance