util.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:adaptivemd 作者: markovmodel 项目源码 文件源码
def get_function_source(func):
    """
    Determine the source file of a function

    Parameters
    ----------
    func : function

    Returns
    -------
    str
        the module name
    list of str
        a list of filenames necessary to be copied

    """
    installed_packages = pip.get_installed_distributions()
    inpip = func.__module__.split('.')[0] in [p.key for p in installed_packages]
    insubdir = os.path.realpath(
        func.__code__.co_filename).startswith(os.path.realpath(os.getcwd()))
    is_local = not inpip and insubdir

    if not is_local:
        return func.__module__, []
    else:
        return func.__module__.split('.')[-1], \
               [os.path.realpath(func.__code__.co_filename)]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号