Fix "missing scripts" being unavailable in the extensions UI

Add-ons which were enabled but not found warn on startup
and were shown under "Missing scripts", where they can be ignored
(the user can choose to restore the paths) or disabled them to suppress
the warnings in future.

This is now available again, with a minor refactor.
This commit is contained in:
Campbell Barton 2024-05-16 22:46:05 +10:00
parent a926f5b67d
commit 64c4c939a9
2 changed files with 73 additions and 34 deletions

@ -115,6 +115,7 @@ def extensions_panel_draw_legacy_addons(
enabled_only,
installed_only,
used_addon_module_name_map,
addon_modules,
):
# NOTE: this duplicates logic from `USERPREF_PT_addons` eventually this logic should be used instead.
# Don't de-duplicate the logic as this is a temporary state - as long as extensions remains experimental.
@ -126,15 +127,11 @@ def extensions_panel_draw_legacy_addons(
pkg_info_check_exclude_filter_ex,
)
addons = [
(mod, addon_utils.module_bl_info(mod))
for mod in addon_utils.modules(refresh=False)
]
# Initialized on demand.
user_addon_paths = []
for mod, bl_info in addons:
for mod in addon_modules:
bl_info = addon_utils.module_bl_info(mod)
module_name = mod.__name__
is_extension = addon_utils.check_extension(module_name)
if is_extension:
@ -325,6 +322,7 @@ def extensions_panel_draw_impl(
"""
Show all the items... we may want to paginate at some point.
"""
import addon_utils
import os
from .bl_extension_ops import (
blender_extension_mark,
@ -359,6 +357,8 @@ def extensions_panel_draw_impl(
show_themes = filter_by_type in {"", "theme"}
if show_addons:
used_addon_module_name_map = {addon.module: addon for addon in prefs.addons}
addon_modules = [mod for mod in addon_utils.modules(refresh=False)]
if show_themes:
active_theme_info = pkg_repo_and_id_from_theme_path(repos_all, prefs.themes[0].filepath)
@ -634,6 +634,7 @@ def extensions_panel_draw_impl(
enabled_only=enabled_only,
installed_only=installed_only,
used_addon_module_name_map=used_addon_module_name_map,
addon_modules=addon_modules,
)
# Finally show any errors in a single panel which can be dismissed.
@ -641,6 +642,43 @@ def extensions_panel_draw_impl(
if errors_on_draw:
display_errors.draw(layout_topmost)
# Append missing scripts
# First collect scripts that are used but have no script file.
if show_addons:
module_names = {mod.__name__ for mod in addon_modules}
missing_modules = {
addon_module_name for addon_module_name in used_addon_module_name_map
if addon_module_name not in module_names
}
if missing_modules:
layout_topmost.column().label(text="Missing script files")
module_names = {mod.__name__ for mod in addon_modules}
for addon_module_name in sorted(missing_modules):
is_enabled = addon_module_name in used_addon_module_name_map
# Addon UI Code
box = layout_topmost.column().box()
colsub = box.column()
row = colsub.row(align=True)
row.label(text="", icon='ERROR')
if is_enabled:
row.operator(
"preferences.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False,
).module = addon_module_name
row.label(text=addon_module_name, translate=False)
row_right = row.row()
row_right.alignment = 'RIGHT'
row_right.label(text="Missing ")
row_right.active = False
layout_topmost.label(text="")
class USERPREF_PT_extensions_bl_pkg_filter(Panel):
bl_label = "Extensions Filter"

@ -2293,13 +2293,12 @@ class USERPREF_PT_addons(AddOnPanel, Panel):
)
# collect the categories that can be filtered on
addons = [
(mod, addon_utils.module_bl_info(mod))
for mod in addon_utils.modules(refresh=False)
]
addon_modules = [mod for mod in addon_utils.modules(refresh=False)]
self._draw_addon_header(layout, prefs, wm)
layout_topmost = layout.column()
col = layout.column()
# set in addon_utils.modules_refresh()
@ -2331,7 +2330,8 @@ class USERPREF_PT_addons(AddOnPanel, Panel):
# initialized on demand
user_addon_paths = []
for mod, bl_info in addons:
for mod in addon_modules:
bl_info = addon_utils.module_bl_info(mod)
addon_module_name = mod.__name__
is_enabled = addon_module_name in used_addon_module_name_map
@ -2460,34 +2460,35 @@ class USERPREF_PT_addons(AddOnPanel, Panel):
if (addon_preferences := used_addon_module_name_map[addon_module_name].preferences) is not None:
self.draw_addon_preferences(col_box, context, addon_preferences)
# Append missing scripts
# First collect scripts that are used but have no script file.
module_names = {mod.__name__ for mod, bl_info in addons}
missing_modules = {
addon_module_name for addon_module_name in used_addon_module_name_map
if addon_module_name not in module_names
}
if filter in {"All", "Enabled"}:
# Append missing scripts
# First collect scripts that are used but have no script file.
module_names = {mod.__name__ for mod in addon_modules}
missing_modules = {
addon_module_name for addon_module_name in used_addon_module_name_map
if addon_module_name not in module_names
}
if missing_modules and filter in {"All", "Enabled"}:
col.column().separator()
col.column().label(text="Missing script files")
if missing_modules:
layout_topmost.column().separator()
layout_topmost.column().label(text="Missing script files")
module_names = {mod.__name__ for mod, bl_info in addons}
for addon_module_name in sorted(missing_modules):
is_enabled = addon_module_name in used_addon_module_name_map
# Addon UI Code
box = col.column().box()
colsub = box.column()
row = colsub.row(align=True)
module_names = {mod.__name__ for mod in addon_modules}
for addon_module_name in sorted(missing_modules):
is_enabled = addon_module_name in used_addon_module_name_map
# Addon UI Code
box = layout_topmost.column().box()
colsub = box.column()
row = colsub.row(align=True)
row.label(text="", icon='ERROR')
row.label(text="", icon='ERROR')
if is_enabled:
row.operator(
"preferences.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False,
).module = addon_module_name
if is_enabled:
row.operator(
"preferences.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False,
).module = addon_module_name
row.label(text=addon_module_name, translate=False)
row.label(text=addon_module_name, translate=False)
# -----------------------------------------------------------------------------