-
Notifications
You must be signed in to change notification settings - Fork 192
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
Add type checks to all plugin factories #3456
Add type checks to all plugin factories #3456
Conversation
Few questions to be discussed/answered:
|
225a519
to
0396e10
Compare
I would say yes. A factory should spit out what it is designed to produce.
I would prefer to do it as a warning rather than an exception at this point (to be turned into an exception in version ...), exactly because it might break something.
I would say yes.
I would say it's good to keep the test if it still checks things that aren't checked by the factories. I would strongly vote against entry point validation at import of aiida. |
OK, I will add it for all factories.
After adding type checking to all factories, the unit test should really just try and load all registered entry points. The type checking it is currently doing will then already be done by the factory.
I agree. |
Sounds like a good idea! We might eventually want to add more validation functionalities, so perhaps think about whether you want to add a verdi command already now or just have a function in the python API. P.S. Could e.g. be a "devel" command at this point. Up to you. |
WorkflowFactory
and CalculationFactory
97c8112
to
930915b
Compare
The various entry point factories, based on the base class `aiida.plugins.factories.BaseFactory` would simply return the resource that the given entry point corresponds to if it could be loaded. There were no additional checks if the type of the loaded entry point corresponds to what is expected for that particular entry point group. It was possible, for example, to add `CalcJob` implementations and calculation functions to the `aiida.workflows` entry point group, as well as `WorkChain` and work functions to `aiida.calculations`. The respective factories would load these entry points without complaining. However, to keep consistency it is better to raise if an entry point is loaded from the incorrect entry point group. The functionality to check that all registered plugins can be loaded through their respective factories has been abstracted to a utility in `aiida.plugins.entry_point.validate_registered_entry_points`. It is also exposed on the command line through `verdi devel validate-plugins`.
930915b
to
6244868
Compare
@ltalirz this should be good for review. Tests are now running, although I had to add the |
Note that we decided to keep the behavior that the factories will raise instead of a warning. The reason is that even if a plugin has an entry point with an incorrect type (which is highly unlikely, probably only calcfcuntion in |
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.
Good for me!
After merging, let's just ping developers here, to make sure they double check they didn't register things in the wrong place
Hm... I don't think this is a valid argument. |
Fixes #3455
It was possible to add
CalcJob
implementations and calculationfunctions to the
aiida.workflows
entry point group, as well asWorkChain
and work functions toaiida.calculations
. The respectivefactories would load these entry points without complaining. However, to
keep consistency it is better to raise if an entry point is loaded from
the incorrect entry point group.
The various entry point factories, based on the base class
aiida.plugins.factories.BaseFactory
would simply return the resourcethat the given entry point corresponds to if it could be loaded. There
were no additional checks if the type of the loaded entry point
corresponds to what is expected for that particular entry point group.
It was possible, for example, to add
CalcJob
implementations andcalculation functions to the
aiida.workflows
entry point group, as wellas
WorkChain
and work functions toaiida.calculations
. The respectivefactories would load these entry points without complaining. However, to
keep consistency it is better to raise if an entry point is loaded from
the incorrect entry point group.