Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-03-26 12:46:26 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-03-26 12:46:26 +0300
commitd982ea9a9e449c1cb57d249cf7301956ae333930 (patch)
tree0a2ad7cfcffd0e3ab848e21d68be45bc6aeff675
parentfda50625cd099b4e65b5e82c7c9a48af256b45fd (diff)
Fix error when an addon has no `__init__.py`
When an addon has been removed, but its `.pyc` files are still there, the Python module can still be loaded. However, because `__init__.py` is missing, it becomes a namespace instead of a module, and its `__file__` will be set to `None`. As a result, it's impossible to get the mtime from the file (because there is none). This should not influence any regularly uninstalled add-on, as that would just remove the add-on's directory; I ran into the problem when switching Git branches caused an add-on's Python files to disappear while keeping the `__pycache__` directory around.
-rw-r--r--release/scripts/modules/addon_utils.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/release/scripts/modules/addon_utils.py b/release/scripts/modules/addon_utils.py
index 83bed69d8d2..387691f9f05 100644
--- a/release/scripts/modules/addon_utils.py
+++ b/release/scripts/modules/addon_utils.py
@@ -349,6 +349,10 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
# 1) try import
try:
mod = __import__(module_name)
+ if mod.__file__ is None:
+ # This can happen when the addon has been removed but there are
+ # residual `.pyc` files left behind.
+ raise ImportError(name=module_name)
mod.__time__ = os.path.getmtime(mod.__file__)
mod.__addon_enabled__ = False
except Exception as ex: