Page MenuHome

addon_utils: Function to check if addon is enabled in current workspace
Needs ReviewPublic

Authored by Demeter Dzadik (Mets) on Nov 5 2021, 4:15 PM.

Details

Summary

The current check() function doesn't account for workspace filtering, so for addons to reliably be able to integrate with each other, they have to add this extra check. Not anymore!
It might be better to add a 3rd boolean to the return tuple of the check() function instead. If that solution is deemed safe in backwards-compatibility terms then I'm happy to do that instead.

Diff Detail

Repository
rB Blender
Branch
arcpatch-D13129 (branched from master)
Build Status
Buildable 21981
Build 21981: arc lint + arc unit

Event Timeline

Demeter Dzadik (Mets) requested review of this revision.Nov 5 2021, 4:15 PM
Demeter Dzadik (Mets) created this revision.
Campbell Barton (campbellbarton) requested changes to this revision.May 5 2022, 12:55 PM
Campbell Barton (campbellbarton) added inline comments.
release/scripts/modules/addon_utils.py
258
  • Convention for this module is not to use annotation as there is no way to validate them.
  • Prefer is_active_in_workspace the term addon is redundant in this module.
260

Same for variable names enabled_in_prefs for eg is sufficient.

This revision now requires changes to proceed.May 5 2022, 12:55 PM

Address feedback.

This revision is now accepted and ready to land.May 5 2022, 2:47 PM
Campbell Barton (campbellbarton) requested changes to this revision.EditedMay 5 2022, 2:51 PM

This seems fine but marking as request changes because I'd like to consider a few things...

  • Have the ability to check an add-on is enabled (without the context).
  • Have the ability to check the add-on is enabled and active in the work-space.

Even though check provides this, it's mainly intended for internal use, (in fact this module is mainly for internal use).

Also, an add-on may be enabled without being enabled in the preferences, so I'd like to double check that this will work properly.

This revision now requires changes to proceed.May 5 2022, 2:51 PM
Demeter Dzadik (Mets) added a comment.EditedMay 5 2022, 7:12 PM

Also, an add-on may be enabled without being enabled in the preferences, so I'd like to double check that this will work properly.

If the addon is disabled in the user preferences, it cannot be enabled on a per workspace basis, because only addons that are enabled in the preferences show up at all in the workspace addon filter list. Maybe I misunderstand what you mean here.

Even though check provides this, it's mainly intended for internal use, (in fact this module is mainly for internal use).

Perhaps I should expose these functions in release/scripts/modules/bpy/utils/__init__.py, so they're available via bpy.utils.is_addon_active/enabled()?

I propose to leave the current is_addon_active() function in the patch as it is: Requires context, and uses that to check for workspace filtering.
But in addition, I can add an is_addon_enabled() function which is basically just

def is_addon_enabled(module_name):
    return addon_utils.check(module_name)[1]

LMK what you think about those ideas.

Demeter Dzadik (Mets) requested review of this revision.EditedMay 17 2022, 3:31 PM

Setting to Needs Review since I'm waiting for clarification.