Import 2017-06-07 23:51:09: master abe2f0bd

Author Committer Branch Timestamp Parent
ihnorton ihnorton master 2017-04-21 17:57:43 master be37d0a9
Changeset

ENH: add module to PYTHONPATH during instantiation

Allows python modules to depend on resources provided by other modules.

ref: https://github.com/Slicer/Slicer/pull/705
ref: https://discourse.slicer.org/t/scripted-module-dependency-loaded-too-late-for-one-module-but-for-another-one-not/142

from jcfr:

Instantiation is done in arbitrary order but the "loading" of each module is done based on the dependency graph captured by the dependencies property:

instantiateModules loops over the keys alphabetically,
Each module is instantiated in the order of the key,

foreach (const QString& moduleName, d->RegisteredModules.keys())
{

then instantiateModule for each module will collect the dependent modules

See https://github.com/Slicer/Slicer/blob/eefeac9286f48552e8418a11f412b2823a09b407/Base/QTCore/qSlicerAbstractModuleFactoryManager.cxx#L394-L424

which are later loaded in the right order:

  // Load the modules the module depends on.
  // There is no cycle check, so be careful
  foreach(const QString& dependency, instance->dependencies())
    {
    // no-op if the module is already loaded
    bool dependencyLoaded = this->loadModule(dependency, name);
    if (!dependencyLoaded)
      {
      qWarning() << "When loading module " << name << ", the dependency"
                 << dependency << "failed to be loaded.";
      return false;
      }
}

git-svn-id: http://svn.slicer.org/Slicer4/trunk@25941 3bd1e089-480b-0410-8dfb-8563597acbee

mod - Base/QTGUI/qSlicerScriptedLoadableModuleFactory.cxx Diff File