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)]
评论列表
文章目录