Commit b244f2c9 authored by eric pellegrini's avatar eric pellegrini

Merge branch 'hotfix-1.0.3.e'

parents a0efd1bf bf2f8ec4
Pipeline #1170 passed with stages
in 9 minutes and 51 seconds
version 1.0.3.c: version 1.0.3.e:
----------------
* bug fix relative to REGISTRY update
version 1.0.3.d:
---------------- ----------------
* redirected the sys.stdout and sys.stderr to the LOGGER * redirected the sys.stdout and sys.stderr to the LOGGER
* implemented a write method so as ConsoleHandler behaves as a file-like object * implemented a write method so as ConsoleHandler behaves as a file-like object
...@@ -16,7 +20,7 @@ version 1.0.3.c: ...@@ -16,7 +20,7 @@ version 1.0.3.c:
* removed unused imports * removed unused imports
* removed white spaces * removed white spaces
version 1.0.3.b: version 1.0.3.c:
---------------- ----------------
* bug fix with JobControllerPanel in case of crashing jobs * bug fix with JobControllerPanel in case of crashing jobs
* regression fixed due to trials to get rid of relative imports MDANSE/Externals/pubsub package * regression fixed due to trials to get rid of relative imports MDANSE/Externals/pubsub package
......
...@@ -34,10 +34,24 @@ import glob ...@@ -34,10 +34,24 @@ import glob
import imp import imp
import inspect import inspect
import os import os
import sys
from MDANSE.Core.Singleton import Singleton from MDANSE.Core.Singleton import Singleton
def path_to_module(path,stop=""):
path, _ = os.path.splitext(path)
splittedPath = path.split(os.sep)
try:
idx = splittedPath.index(stop)
except ValueError:
idx = 0
finally:
module = ".".join(splittedPath[idx:])
return module
class ClassRegistry(object): class ClassRegistry(object):
''' '''
Metaclass that registers the classes that make the MDANSE framework. Metaclass that registers the classes that make the MDANSE framework.
...@@ -87,7 +101,7 @@ class ClassRegistry(object): ...@@ -87,7 +101,7 @@ class ClassRegistry(object):
return self._registry.get(name,{}) return self._registry.get(name,{})
def update(self,packageDir): def update(self,packageDir, macros=False):
''' '''
Update the classes registry by importing all the modules contained in a given package. Update the classes registry by importing all the modules contained in a given package.
...@@ -103,19 +117,21 @@ class ClassRegistry(object): ...@@ -103,19 +117,21 @@ class ClassRegistry(object):
if moduleFile == '__init__.py': if moduleFile == '__init__.py':
continue continue
moduleName, _ = os.path.splitext(moduleFile)
# Any error that may occur here has to be caught. In such case the module is skipped. # Any error that may occur here has to be caught. In such case the module is skipped.
try: try:
filehandler,path,description = imp.find_module(moduleName, [moduleDir]) if macros:
mod = imp.load_module(moduleName,filehandler,path,description) moduleName,_ = os.path.splitext(moduleFile)
filehandler,path,description = imp.find_module(moduleName, [moduleDir])
imp.load_module(moduleName,filehandler,path,description)
filehandler.close()
else:
moduleName, _ = os.path.splitext(moduleFile)
module = path_to_module(module,stop="MDANSE")
__import__(module)
except: except:
continue continue
else:
if os.path.abspath(os.path.dirname(mod.__file__)) != os.path.abspath(moduleDir):
print "A module with name %s is already present in your distribution with %s path." % (moduleName,moduleDir)
def info(self, interface): def info(self, interface):
''' '''
Returns informations about the subclasses of a given base class stored in the registry. Returns informations about the subclasses of a given base class stored in the registry.
......
...@@ -2,8 +2,8 @@ import os ...@@ -2,8 +2,8 @@ import os
from MDANSE import PLATFORM, REGISTRY from MDANSE import PLATFORM, REGISTRY
REGISTRY.update(os.path.join(os.path.dirname(__file__),"*")) REGISTRY.update(os.path.join(os.path.dirname(__file__),"*"),False)
macrosDirectories = sorted([x[0] for x in os.walk(PLATFORM.macros_directory())][0:]) macrosDirectories = sorted([x[0] for x in os.walk(PLATFORM.macros_directory())][0:])
for d in macrosDirectories: for d in macrosDirectories:
REGISTRY.update(d) REGISTRY.update(d,True)
__version__ = "1.0.3.d" __version__ = "1.0.3.e"
__date__ = "18-11-2016" __date__ = "18-11-2016"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment