From 58895acbb0a3c708c981227af61f6b9eabfe095b Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Wed, 5 Mar 2025 21:53:18 -0600 Subject: [PATCH] bug fixes --- plugin_ix/loader.py | 22 ++++++++++++++++--- plugin_ix/registry.py | 50 +++++++++++++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/plugin_ix/loader.py b/plugin_ix/loader.py index 6830ea7..5020045 100644 --- a/plugin_ix/loader.py +++ b/plugin_ix/loader.py @@ -21,6 +21,7 @@ class Loader : # self._names = _names if type(_names) == list else [_names] self._modules = {} self._names = [] + self._alias = {} #-- synonyms if 'file' in _args : self.load(**_args) # self._registry = _args['registry'] @@ -43,6 +44,9 @@ class Loader : for _name in dir(module) : if self.isplugin(module,_name,_decoratorName) : self._modules[_name] = getattr(module,_name) + if hasattr(self._modules[_name],'name') : + _alt = getattr(self._modules[_name],'name') + self._alias[_alt] = _name return self._modules is not None # self._names [_name] # def format (self,**_args): @@ -85,16 +89,28 @@ class Loader : """ This will determine if the module name is loaded or not """ - return _name in self._modules + return _name in self._modules or _name in self._alias def names (self): return list(self._modules.keys()) def get (self,_name=None): """ This functiion determines how many modules loaded vs unloaded given the list of names """ - return self._modules.get(_name,None) if _name else self._modules + if _name in self._alias : + _name = self._alias[_name] + if _name in self._modules : + return self._modules[_name] + def apply(self,_name,**_args): _pointer = self.get(_name) if _pointer : return _pointer (**_args) if _args else _pointer() - + def visitor(self,_args,logger=None) : + for _name in self._names : + _pointer = self.get(_name) + _kwargs = _pointer(_args) + if (type(_kwargs) == pd.DataFrame and not _kwargs.empty) or _kwargs is not None : + _args = _kwargs + # _args = _caller(_pointer,_args) + return _args + \ No newline at end of file diff --git a/plugin_ix/registry.py b/plugin_ix/registry.py index 4adf41b..71c6ec9 100644 --- a/plugin_ix/registry.py +++ b/plugin_ix/registry.py @@ -14,19 +14,20 @@ from . import loader class Registry : - def __init__(self,folder=None,reader = None) : + def __init__(self,folder=None,reader = None,plugin_folder=None) : """ """ self._folder = folder if folder else os.environ.get('REGISTRY_FOLDER',None) self._filename = os.sep.join([self._folder,'plugins-registry.json']) + self._plugin_folder = os.sep.join([self._folder,'code']) if not plugin_folder else os.sep.join([self._folder,plugin_folder]) # # Let us refactor this in case the user decided to provide a file name instead if os.path.isfile(self._folder) : _name = self._folder.split(os.sep)[-1].strip() self._folder = os.sep.join(self._folder.split(os.sep)[:-1]).strip() self._filename = os.sep.join([self._folder,_name]) - print (' *** ',_name,self._folder) + # print (' *** ',_name,self._folder) # self._context = self._folder.split(os.sep)[-1] self._reader = reader self._data = {} @@ -35,7 +36,6 @@ class Registry : # self.make(os.sep.join([self._folder,'code'])) self.load() - def set(self,filename,names) : """ :filename this is the python file @@ -43,14 +43,23 @@ class Registry : """ if os.path.exists(filename) and names: _file = filename.split(os.sep)[-1].split('.')[0] - _newlocation = os.sep.join([self._folder,'code',filename.split(os.sep)[-1]]) + _newlocation = os.sep.join([self._plugin_folder,filename.split(os.sep)[-1]]) + if _file in self._data : + names += self._data[_file]['content'] + names = list(set(names)) + self._data[_file] = {"content":names,"path":_newlocation} + # + # @TODO: + # Makes sure the names exist in the file, use the loader to do this + # + # # we need to copy the file to the new location # shutil.copyfile(filename, _newlocation) self.write() - return 1 + return len(self._data[_file]['content']) else: return 0 def stats (self): @@ -85,20 +94,20 @@ class Registry : """ _key can be formatted as _name@file with """ - if '@' in _key : - _name,_file = _key.split('@') - else: - _name = _key - _file = None - if len(self._data.keys()) == 1 : - _file = list(self._data.keys())[0] + # if '@' in _key : + # _name,_file = _key.split('@') + # elif '.' in _key : + # _file,_name = _key.split('.') + # else: + # _name = _key + # _file = None + # if len(self._data.keys()) == 1 : + # _file = list(self._data.keys())[0] + _file,_name = self.getref(_key) if _file in self._data : return _name in self._data[_file]['content'] return False - def get(self,_key): - """ - _key is either file.funcName, _funcName@file - """ + def getref (self,_key): if '@' in _key : _name,_file = _key.split('@') elif '.' in _key : @@ -108,7 +117,15 @@ class Registry : _file = None if len(self._data.keys()) == 1 : _file = list(self._data.keys())[0] + return _file, _name + + def get(self,_key): + """ + _key is either file.funcName, _funcName@file + """ + _file,_name = self.getref(_key) filename = self._data[_file]['path'] + _loader = loader.Loader(file=filename) return _loader.get(_name) def write (self): @@ -118,3 +135,4 @@ class Registry : f.write(json.dumps(self._data)) f.close() pass + \ No newline at end of file