import json
import pandas as pd
import importlib
import importlib.util
import os

#
# Defining the decorator to be used in plugins, this will enable simple loading and assigning mimetype to the output (if any)
#

    
# def stats (_config) :
#     """
#     Returns the statistics of the plugins
#     """
#     _data = []
#     for _name in _config :
#         _log = {"files":_name,"loaded":len(_config[_name]),"logs":json.dumps(_config[_name])}
#         _data.append(_log)
#     return pd.DataFrame(_data)
#     pass
# def load(_path,_filename,_name) :
#     """
#     This function will load external module form a given location and return a pointer to a function in a given module
#     :path   absolute path of the file (considered plugin) to be loaded
#     :name   name of the function to be applied
#     """
#     # _path = _args['path'] #os.sep.join([_args['root'],'plugin'])
    
#     if os.path.isdir(_path):
#         files = os.listdir(_path)
#         if files :
#             files = [name for name in files if name.endswith('.py') and name == _filename]
#             if files:
#                 _path = os.sep.join([_path,files[0]])
#             else:
#                 return None
#         else:
#             return None
#     #-- We have a file ...  
#     # _name = _args['name']
#     spec = importlib.util.spec_from_file_location(_filename, _path)
#     module = importlib.util.module_from_spec(spec)
#     spec.loader.exec_module(module)
#     #
#     # we need to make sure we have the plugin decorator here to make sure 
    
#     return getattr(module,_name) if hasattr(module,_name) else None


