Commit 84e79c53 authored by Valentin Valls's avatar Valentin Valls
Browse files

Use class_name instead of klass_name

- For readability
parent 08a995d3
Pipeline #38824 passed with stages
in 94 minutes and 23 seconds
......@@ -22,33 +22,33 @@ def find_class(cfg_node, base_path="bliss.controllers"):
return find_class_and_node(cfg_node, base_path)[0]
def resolve_module_name(klass_name, node, base_path):
def resolve_module_name(class_name, node, base_path):
if "package" in node:
result = node["package"]
elif "module" in node:
module_name = node["module"]
result = "%s.%s" % (base_path, module_name)
elif base_path == "bliss.controllers" and klass_name in _ALIAS_TO_MODULE_NAME:
elif base_path == "bliss.controllers" and class_name in _ALIAS_TO_MODULE_NAME:
# For BLISS base class, there is alias to the right module
# In order to allow to move them without changing the configuration
result = _ALIAS_TO_MODULE_NAME.get(klass_name)
result = _ALIAS_TO_MODULE_NAME.get(class_name)
# discover module and class name
result = "%s.%s" % (base_path, klass_name.lower())
result = "%s.%s" % (base_path, class_name.lower())
return result
def find_class_and_node(cfg_node, base_path="bliss.controllers"):
klass_name, node = cfg_node.get_inherited_value_and_node("class")
if klass_name is None:
class_name, node = cfg_node.get_inherited_value_and_node("class")
if class_name is None:
raise KeyError("class")
module_name = resolve_module_name(klass_name, node, base_path)
module_name = resolve_module_name(class_name, node, base_path)
module = __import__(module_name, fromlist=[""])
except ModuleNotFoundError as e:
if find_spec(module_name) is not None:
raise e
module_name = "%s.%s" % (base_path, camel_case_to_snake_style(klass_name))
module_name = "%s.%s" % (base_path, camel_case_to_snake_style(class_name))
module = __import__(module_name, fromlist=[""])
......@@ -63,8 +63,8 @@ def find_class_and_node(cfg_node, base_path="bliss.controllers"):
raise ModuleNotFoundError(msg)
klass = getattr(module, klass_name)
klass = getattr(module, class_name)
except AttributeError:
klass = getattr(module, klass_name.title())
klass = getattr(module, class_name.title())
return klass, node
Supports Markdown
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