ObjectLoader

An utility to load modules and objects in DIRAC and extensions, being sure that the extensions are considered

class DIRAC.Core.Utilities.ObjectLoader.ObjectLoader(*args, **kwargs)

Bases: object

Class for loading objects. Example:

from DIRAC.Core.Utilities.ObjectLoader import ObjectLoader ol = ObjectLoader() ol.loadObject(‘TransformationSystem.Client.TransformationClient’)

__init__(baseModules=False)

init

getObjects(modulePath, reFilter=None, parentClass=None, recurse=False, continueOnError=False)

Search for modules under a certain path

modulePath is the import string needed to access the parent module. Root modules will be included automatically (like DIRAC). For instance “ConfigurationSystem.Service”

reFilter is a regular expression to filter what to load. For instance “.*Handler” parentClass is a class object from which the loaded modules have to import from. For instance RequestHandler

Parameters:

continueOnError – if True, continue loading further module even if one fails

instance = <DIRAC.Core.Utilities.ObjectLoader.ObjectLoader object>
loadModule(importString, hideExceptions=False)

Load a module from an import string

loadObject(importString, objName=False, hideExceptions=False)

Load an object from inside a module

reloadRootModules()

Retrigger the initialization of the rootModules.

This should be used with care. Currently, its only use is (and should stay) to retrigger the initialization after the CS has been fully initialized in LocalConfiguration.enableCS

DIRAC.Core.Utilities.ObjectLoader.loadObjects(path, reFilter=None, parentClass=None)

Note: this does not work for editable install because it hardcodes DIRAC.__file__ It is better to use ObjectLoader().getObjects()

Parameters:
  • path (str) – the path to the syetem for example: DIRAC/AccountingSystem

  • reFilter (object) – regular expression used to found the class

  • parentClass (object) – class instance

Returns:

dictionary containing the name of the class and its instance