-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend parser to include specialized EntryData sections #131
base: main
Are you sure you want to change the base?
Conversation
4922265
to
7432c3f
Compare
@aalbino2 can you check if this works in your case? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will implement this solution in a parser that will be included in nomad-measurements soon. I think this can be merged. Thanks for figuring out a solution that will be useful for all the parsers.
hey @ka-sarthak, apparently @JonathanNoky cannot make this work. he need to call the function inside the parse function:
what do you think? shouldn't it be already executed without calling it? or do we need to really include it into the init method that is always run? Indeed the linter says "W0201:attribute-defined-outside-init" |
Hey @ka-sarthak , after looking into your example again I figured it out. I missed the part where the set_entrydata_definition is called at the beginning of parse(). |
The idea is to override the setter function that sets the entrydata definition. In a specialized @aalbino2 you are right, class XRDParser(MatchingParser):
entrydata_definition: str = ELNXRayDiffraction
def parse(self):
...
class SpecializedXRDParser(XRDParser):
def parse(self):
self.entrydata_definition = SpecializedELNXRayDiffraction
super().parse() |
okay, I think this alternative can make sense. @JonathanNoky will you try this solution in ppms instead of the one previously proposed? |
I haven't tested it, so please take it with a grain of salt |
Yes, this one also works. Its shorter than the other method, as there is just one line in the parse function. |
Actually, after some thinking about it, I think, the method of just setting the attribute in the parse function does not work for more nested parser classes like this:
Here, the EvenMoreSpecializedXRDParser would via the super().parse() function still get the SpecializedELNXRayDiffraction defintion, right? So I think, I will have to go back to the first proposed solution with the separate definition function. I will try it in my CPFSPPMSParser plugin, as this has this kind of deeper nested parsers when I let it depend on the nomad-measurements plugin. |
@JonathanNoky That's a good point. Having a setter function allows for more flexibility and deeper nesting. |
c57766e
to
e1f4237
Compare
e1f4237
to
131e9c2
Compare
The definition of the EntryData class that is generated by the MatchingParser has been abstracted out into an attribute
entrydata_definition
. This is set in theset_entrydata_definition
method.Benefit:
XRDParser
can be reused by overwritingset_entrydata_definition
method. For example: