.. _fbf.utils.source: source ~~~~~~ .. automodule:: fbf.utils.source :show-inheritance: :members: :undoc-members: CODE ---- :: # fbf/utils/source.py # # """ get the location of a source """ .. _fbf.utils.source_fbf_imports: fbf imports -------------- :: from fbf.utils.exception import handle_exception .. _fbf.utils.source_basic_imports: basic imports ---------------- :: import os import os.path import logging import sys .. _fbf.utils.source_getsource_function: getsource function --------------------- :: def getsource(mod): if not os.getcwd() in sys.path: sys.path.insert(0, os.getcwd()) source = None splitted = mod.split(".") if len(splitted) == 1: splitted.append("") thedir = os.path.abspath(mod.replace(".", os.sep)) if os.path.isdir(thedir): source = thedir if source and os.path.exists(source): logging.info("source is %s" % source) return source if not source: try: import pkg_resources source = pkg_resources.resource_filename(".".join(splitted[:len(splitted)-1]), splitted[-1]) except ImportError: try: import fbf.contrib.pkg_resources as pkg_resources source = pkg_resources.resource_filename(".".join(splitted[:len(splitted)-1]), splitted[-1]) except ImportError: pass logging.info("source is %s" % source) return source