-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
For example, with a handler named galyst.input_handler.ArepoHDFSubfindInputHandler,
tangos/tangos/input_handlers/__init__.py
Lines 209 to 221 in ddf42fd
| def get_named_handler_class(handler): | |
| """Get a HandlerBase identified by the given name. | |
| The name is of the format submodule.ClassName | |
| :rtype HandlerBase""" | |
| handler = _map_deprecated_handler_name(handler) | |
| try: | |
| output_module = importlib.import_module('.'+handler.split('.')[0],__name__) | |
| except ImportError: | |
| output_module = importlib.import_module(handler.split('.')[0]) | |
| output_class = getattr(output_module, handler.split('.')[1]) | |
| return output_class |
the current implementation attempts to import the module galyst and find a class named input_handler.
Here is the suggested change:
def get_named_handler_class(handler):
"""Get a HandlerBase identified by the given name.
The name is of the format submodule.ClassName or package.submodule.ClassName
:rtype HandlerBase"""
handler = _map_deprecated_handler_name(handler)
if '.' not in handler:
raise ValueError("Handler name must be in the format module.ClassName")
module_name, class_name = handler.rsplit('.', 1)
try:
# First, try a relative import within tangos.input_handlers
output_module = importlib.import_module('.' + module_name, __name__)
except (ImportError, ModuleNotFoundError):
# If that fails, try an absolute import
output_module = importlib.import_module(module_name)
output_class = getattr(output_module, class_name)
return output_classif input galyst.input_handler.ArepoHDFSubfindInputHandler, the output_module will be galyst.input_handler and the class_name will be ArepoHDFSubfindInputHandler.
This update will improve the flexibility of tangos by allowing users to better organize their custom handler modules.
Metadata
Metadata
Assignees
Labels
No labels