Commit 3406b794 authored by payno's avatar payno

[node] extract class and module name function. To be used outside

parent fed57846
......@@ -153,6 +153,19 @@ class Node(object):
"""
return len(self.upstream_nodes) is 0
def get_class_name_and_module_name(self) -> tuple:
"""
:retruns: (class name, module name)
"""
sname = self._process_pt.rsplit('.')
if not (len(sname) > 1):
raise ValueError(
self._process_pt + ' is not recognized as a valid name')
class_name = sname[-1]
del sname[-1]
mod_name = '.'.join(sname)
return class_name, mod_name
def load_handlers(self) -> None:
"""
load handlers from the `processing_pt` defined.
......@@ -175,12 +188,7 @@ class Node(object):
if not type(self._process_pt) is str:
raise ValueError('process_pt should be a callable or path to a class or function')
else:
sname = self._process_pt.rsplit('.')
if not (len(sname) > 1):
raise ValueError(self._process_pt + ' is not recognized as a valid name')
class_name = sname[-1]
del sname[-1]
module_name = '.'.join(sname)
class_name, module_name = self.get_class_name_and_module_name()
if module_name.endswith('.py'):
# warning: in this case the file should not have any relative
module = SourceFileLoader(module_name,
......@@ -201,7 +209,7 @@ class Node(object):
for input_ in self.__process_instance.inputs:
input_name, input_type, input_handler = input_[:3]
_logger.debug('[node: %s] add input_name: %s, '
'input_type: %s, input_handler: %s' % (self._process_pt, input_name, input_type, input_handler))
'input_type: %s, input_handler: %s' % (self._process_pt, input_name, input_type, input_handler))
if str(input_type) in self._input_type_to_name:
raise ValueError('Several input name found for the '
'same input type. This case is not managed.')
......
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