-
Notifications
You must be signed in to change notification settings - Fork 3
/
essentials.py
62 lines (43 loc) · 1.66 KB
/
essentials.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# SPDX-FileCopyrightText: 2021-2024 Mikhail Rachinskiy
# SPDX-License-Identifier: GPL-3.0-or-later
# v1.2.0
from pathlib import Path
from typing import Any
import bpy
def reload_recursive(path: Path, mods: dict[str, Any]) -> None:
import importlib
for child in path.iterdir():
if child.is_file() and child.suffix == ".py" and not child.name.startswith("__") and child.stem in mods:
importlib.reload(mods[child.stem])
elif child.is_dir() and not child.name.startswith((".", "__")):
if child.name in mods:
reload_recursive(child, mods[child.name].__dict__)
importlib.reload(mods[child.name])
continue
reload_recursive(child, mods)
def check(*args: Path | str) -> None:
for arg in args:
if isinstance(arg, Path):
if not arg.exists():
raise FileNotFoundError("Incorrect package, follow installation guide")
elif isinstance(arg, str):
if tuple([int(x) for x in arg.split(".")]) > bpy.app.version:
raise RuntimeError(f"Blender {arg} is required")
def get_classes(modules: tuple[Any]) -> tuple[type]:
bases = {
bpy.types.AddonPreferences,
bpy.types.Menu,
bpy.types.Operator,
bpy.types.Panel,
bpy.types.PropertyGroup,
bpy.types.UIList,
}
classes = []
for module in modules:
for cls in module.__dict__.values():
if isinstance(cls, type):
for base in cls.__bases__:
if base in bases:
classes.append(cls)
break
return tuple(classes)