AIT-Core icon indicating copy to clipboard operation
AIT-Core copied to clipboard

extended FSWTabDict class

Open JimHofman opened this issue 3 years ago • 5 comments

JimHofman avatar Oct 20 '21 16:10 JimHofman

@JimHofman Looks like you still need to declare your newCmd as an extension in the config.yaml

See: https://ait-core.readthedocs.io/en/master/extensions.html

Config yaml would contain an entry that looks like:

....
extensions:
    ait.core.cmd.Cmd: ait.core.newCmd.NewCmd

Would presumably need something similar for the table extension.

nttoole avatar Oct 20 '21 16:10 nttoole

I'll check that out Nick. I was sure I had added those. Hmmm. Thanks Nick.

JimHofman avatar Oct 20 '21 16:10 JimHofman

Hey @JimHofman, replying here with regards to the issue(s) you're running into with the table extension support. Thanks for throwing this branch up so we have something to dig through.

It looks like you got the "general extension" stuff added and working correctly. That's why you can see log message indicating that the extension class has been added. However, it's not getting fully pulled in for a few reasons (I think).

def YAMLCtor_FSWColDefn(loader, node):  # noqa: N802
    fields = loader.construct_mapping(node, deep=True)
    return FSWColDefn(**fields)


def YAMLCtor_FSWTabDefn(loader, node):
    fields = loader.construct_mapping(node, deep=True)
    fields['fswheaderdefns'] = fields.pop('header', None)
    fields['coldefns'] = fields.pop('columns', None)
    return FSWTabDefn(**fields)

These functions are used by the custom YAML class handling stuff when processing the dictionary

yaml.add_constructor("!FSWTable", YAMLCtor_FSWTabDefn)
yaml.add_constructor("!FSWColumn", YAMLCtor_FSWColDefn)

So, if you import the table dictionary you'll see a message indicating that the extension was loaded but it's never going to actually load your class because the above functions (and others in the code) are calling explicit class names instead of the "extensions classes". These createXXX functions that should be used are (poorly) documented in the extension code: https://github.com/NASA-AMMOS/AIT-Core/blob/master/ait/core/util.py#L112

Looking through the table code really quickly (so you should sanity check that I'm not missing something) I think you need to make the following modifications:

MJJoyce avatar Oct 20 '21 20:10 MJJoyce

Table extensions now work. Created a newTable.py to override FSWTabDict. newTable.py from ait.core import table, log

class NewFSWTabDict(table.FSWTabDict): def init(self, *args, **kwargs): super().init(*args, **kwargs)

def load(self, fname):
    log.info('Starting the table load() from the extended 
    	     FSWTabDict class, using file: {}'.format(self.filename))
    return super(NewFSWTabDict, self).load(fname)

def custom():
    log.info('Test of a unique method defined in an extension.')

Used the following to instantiate and verify:

import ait.core.table as table

table_dict = table.getDefaultFSWTabDict()

JimHofman avatar Oct 28 '21 21:10 JimHofman

Correct, the createXxx() methods are implicitly added here: https://github.com/NASA-AMMOS/AIT-Core/blob/5b9a24792dc81d247ff59fdccbc53c77ebac25bc/ait/core/util.py#L148

nttoole avatar Mar 14 '22 17:03 nttoole