#!/usr/bin/env python# -*- coding: utf-8 -*-## This file is part of the `pypath` python module## Copyright 2014-2023# EMBL, EMBL-EBI, Uniklinik RWTH Aachen, Heidelberg University## Authors: see the file `README.rst`# Contact: Dénes Türei (turei.denes@gmail.com)## Distributed under the GPLv3 License.# See accompanying file LICENSE.txt or copy at# https://www.gnu.org/licenses/gpl-3.0.html## Website: https://pypath.omnipathdb.org/#importimportlibimportpypath.share.sessionassession_logger=session.Logger(name='inputs')_log=_logger._log
[docs]defget_method(module_name,method_name=None):""" Retrieves a method from a submodule of this module (``inputs``) by its name. E.g. for ``'uniprot_db.all_uniprots'`` it returns the ``all_uniprots`` method from the ``pypath.inputs.uniprot_db`` module. """_log('Selecting input method (step 1): module `%s`, method `%s`.'%(module_name,method_name,))ifcallable(module_name):returnmodule_nameifnotmethod_name:module_method=module_name.rsplit('.',maxsplit=1)method_name=module_method[-1]module_name=module_method[-2]iflen(module_method)>1else'main'module_name=module_name.rsplit('.',maxsplit=1)[-1]module_name='pypath.inputs.%s'%module_name_log('Selecting input method (step 2): module `%s`, method `%s`.'%(module_name,method_name,))try:_log('Importing module `%s`.'%module_name)mod=importlib.import_module(module_name)except:session.log().msg(msg='Could not import module `%s`.'%module_name,label='inputs',)try:method=getattr(mod,method_name)returnmethodexcept:session.log().msg(msg='Could not find method `%s` in module `%s`.'%(method_name,module_name,),label='inputs',)