-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[proposal] Implement simplified version of pyutilib #7976
Conversation
Implementation finished. Plugins that used only In addition, I made it possible to extend interfaces class Plugin(p.SingletonPlugin):
p.implements(p.IClick, inherit=True)
### or
class Plugin(p.SingletonPlugin, IClick):
pass The second form plays better with analysis tools because it does not perform any magic behind the scenes. You'll get a notification about incorrect method implementations from your IDE, as well as better autocompletion. There is a bad side. Extending the interface means you inherit all the default implementations of the methods from the interface. I.e, it's identical to Nevertheless, I'd recommend extending over our standard |
@@ -724,7 +724,7 @@ def _group_or_org_create(context: Context, | |||
group_type = data_dict.get('type', 'organization' if is_org else 'group') | |||
group_plugin = lib_plugins.lookup_group_plugin(group_type) | |||
try: | |||
schema: Schema = group_plugin.form_to_db_schema_options({ | |||
schema: Schema = getattr(group_plugin, "form_to_db_schema_options")({ |
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.
Just out of curiosity, why are these calls changed?
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.
Here group_plugin
is an instance of IGroupForm
according to the type signature of functions. This interface no longer has form_to_db_schema_options
and the whole try/except block that wraps the current change exists for backward compatibility.
With a simplified implementation of the plugin system, the type checker now can detect this issue and report a call to the non-existing method form_to_db_schema_options
. So I have to either add the type: ignore
directive or modify the line to verify, that I know what am I doing.
I decided to use getattr, because unlike type: ignore
, it highlights the unsafe expression and now it's more clear, what exactly can cause an AttributeError that we are catching in try/except
This looks good to me @smotornyuk did I get all the items in the changelog right? |
Yes, everything is there |
Replace PyUtilib dependency with the simplified version of its logic written inside CKAN.
It can help everyone to understand how plugins work(because I'm keeping only bare minimum that is actually used by CKAN plugins) and decide if we can profit from migration to existing plugin-framework, like pluggy
@EricSoroos, I know that you've started porting pyutilib.core into CKAN so I want you, as person who probably knows most of pyutilib internals, to decide if this PR has any sense. I spent just a couple of hours on it and I feel no regrets if it's closed:)