Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.1 KiB
Python
Raw Permalink Normal View History

Extensions: detect external changes on startup & loading preferences Changes to an extensions manifest weren't accounted for. This was particularly a problem for "System" extensions which aren't intended to be managed inside Blender however the problem existed for any changes made outside of Blender. Now enabled extensions are checked on startup to ensure: - They are compatible with Blender. - The Python wheels are synchronized. Resolves #123645. Details: - Any extension incompatibilities prevent the add-on being enabled with a message printing the reason for it being disabled. - Incompatible add-ons are kept enabled in the preferences to avoid loosing their own preferences and allow for an upgrade to restore compatibility. - To avoid slowing down Blender's startup: - Checks are skipped when no extensions are enabled (as is the case for `--factory-startup` & running tests). - Compatibility data is cached so in common case, the cache is loaded and all enabled extensions `stat` their manifests to detect changes without having to parse them. - The cache is re-generated if any extensions change or the Blender/Python version changes. - Compatibility data is updated: - On startup (when needed). - On an explicit "Refresh Local" (mainly for developers who may edit the manifest). - When refreshing extensions after install/uninstall etc. since an incompatible extensions may become compatible after an update. - When reloading preferences. - Additional info is shown when the `--debug-python` is enabled, if there are ever issues with the extension compatibility cache generation not working as expected. - The behavior for Python wheels has changed so they are only setup when the extension is enabled. This was done to simplify startup checks and has the benefit that an installed but disabled extension never runs code - as the ability to install wheels means it could have been imported from other scripts. It also means users can disable an extension to avoid wheel version conflicts. This does add the complication however that enabling add-on which is an extension must first ensure it's wheels are setup. See `addon_utils.extensions_refresh(..)`. See code-comments for further details.
2024-07-01 15:08:14 +10:00
# SPDX-FileCopyrightText: 2017-2023 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later
"""
Implementation of blender's command line ``--addons`` argument,
e.g. ``--addons a,b,c`` to enable add-ons.
"""
__all__ = (
"set_from_cli",
)
def set_from_cli(addons_as_string):
from addon_utils import (
check,
check_extension,
enable,
extensions_refresh,
)
addon_modules = addons_as_string.split(",")
addon_modules_extensions = [m for m in addon_modules if check_extension(m)]
addon_modules_extensions_has_failure = False
if addon_modules_extensions:
extensions_refresh(
ensure_wheels=True,
addon_modules_pending=addon_modules_extensions,
)
for m in addon_modules:
if check(m)[1] is False:
if enable(m, persistent=True, refresh_handled=True) is None:
Extensions: detect external changes on startup & loading preferences Changes to an extensions manifest weren't accounted for. This was particularly a problem for "System" extensions which aren't intended to be managed inside Blender however the problem existed for any changes made outside of Blender. Now enabled extensions are checked on startup to ensure: - They are compatible with Blender. - The Python wheels are synchronized. Resolves #123645. Details: - Any extension incompatibilities prevent the add-on being enabled with a message printing the reason for it being disabled. - Incompatible add-ons are kept enabled in the preferences to avoid loosing their own preferences and allow for an upgrade to restore compatibility. - To avoid slowing down Blender's startup: - Checks are skipped when no extensions are enabled (as is the case for `--factory-startup` & running tests). - Compatibility data is cached so in common case, the cache is loaded and all enabled extensions `stat` their manifests to detect changes without having to parse them. - The cache is re-generated if any extensions change or the Blender/Python version changes. - Compatibility data is updated: - On startup (when needed). - On an explicit "Refresh Local" (mainly for developers who may edit the manifest). - When refreshing extensions after install/uninstall etc. since an incompatible extensions may become compatible after an update. - When reloading preferences. - Additional info is shown when the `--debug-python` is enabled, if there are ever issues with the extension compatibility cache generation not working as expected. - The behavior for Python wheels has changed so they are only setup when the extension is enabled. This was done to simplify startup checks and has the benefit that an installed but disabled extension never runs code - as the ability to install wheels means it could have been imported from other scripts. It also means users can disable an extension to avoid wheel version conflicts. This does add the complication however that enabling add-on which is an extension must first ensure it's wheels are setup. See `addon_utils.extensions_refresh(..)`. See code-comments for further details.
2024-07-01 15:08:14 +10:00
if check_extension(m):
addon_modules_extensions_has_failure = True
# Re-calculate wheels if any extensions failed to be enabled.
if addon_modules_extensions_has_failure:
extensions_refresh(
ensure_wheels=True,
)