From 866bb5b48e4c9d4b0e5ee2ca7eb0a5ca8bafe424 Mon Sep 17 00:00:00 2001 From: David Friedli Date: Mon, 8 Apr 2024 09:45:35 +0200 Subject: [PATCH] Avoid toml import in blender version < 4.20 --- __init__.py | 1 + utilities/__init__.py | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index 2de44ef..0d1f6d5 100644 --- a/__init__.py +++ b/__init__.py @@ -3,6 +3,7 @@ from bpy.app import background, version_string from .utilities import get_min_blender_version +global bl_info bl_info = { "name": "CAD Sketcher", "author": "hlorus", diff --git a/utilities/__init__.py b/utilities/__init__.py index 0d4d0ac..d313726 100644 --- a/utilities/__init__.py +++ b/utilities/__init__.py @@ -1,19 +1,34 @@ -import pathlib, toml +from bpy.app import version +import pathlib -def get_addon_version(): +def get_bl_info(): + + from .. import bl_info + return bl_info + + +def get_addon_version() -> str: """Return addon version from manifest file""" + if version < (4, 20): + return str(get_bl_info()["version"]) + manifest = pathlib.Path(__file__).parent.parent / "blender_manifest.toml" try: - return toml.load(manifest)["version"] + import toml + return toml.load(manifest)["blender"] except Exception: return "" -def get_min_blender_version(): +def get_min_blender_version() -> str: """Returns the minimal required blender version from manifest file""" + if version < (4, 20): + return str(get_bl_info()["version"]) + manifest = pathlib.Path(__file__).parent.parent / "blender_manifest.toml" try: + import toml return toml.load(manifest)["blender_version_min"] except Exception: return "" \ No newline at end of file