diff --git a/src/bonsai/bonsai/__init__.py b/src/bonsai/bonsai/__init__.py index 6ea48885b3..561b76f67e 100644 --- a/src/bonsai/bonsai/__init__.py +++ b/src/bonsai/bonsai/__init__.py @@ -28,6 +28,10 @@ IN_BLENDER = sys.modules.get("bpy", None) if IN_BLENDER: import bpy +# This file is executed twice - first as a bonsai-extension +# and then as a bonsai-package. +IN_PACKAGE = __package__ == "bonsai" + import re import platform import traceback @@ -218,17 +222,21 @@ if IN_BLENDER: info["binary_python_version"] = version return info - try: - import git + def update_commit_data() -> None: + try: + import git - # We can't just use __file__ as bonsai/__init__.py is typically not symlinked - # as Blender have errors symlinking main addon package file. - path = Path(__file__).resolve().parent - repo = git.Repo(str(path), search_parent_directories=True) - last_commit_hash = repo.head.object.hexsha - last_commit_date = repo.head.object.committed_datetime.isoformat() - except: - pass + global last_commit_hash + global last_commit_date + path = Path(__file__).resolve().parent + repo = git.Repo(str(path), search_parent_directories=True) + last_commit_hash = repo.head.object.hexsha + last_commit_date = repo.head.object.committed_datetime.isoformat() + except: + pass + + if IN_PACKAGE: + update_commit_data() try: import ifcopenshell.api diff --git a/src/bonsai/bonsai/tool/blender.py b/src/bonsai/bonsai/tool/blender.py index 1bcc6a7663..463d621174 100644 --- a/src/bonsai/bonsai/tool/blender.py +++ b/src/bonsai/bonsai/tool/blender.py @@ -1243,16 +1243,7 @@ class Blender(bonsai.core.tool.Blender): @classmethod def get_last_commit_hash(cls) -> Union[str, None]: - """Get 8 symbols of last commit hash if it's present or return None otherwise.""" - bbim = cls.get_bbim_extension_package() - commit_hash = bbim.last_commit_hash - - # Commit hash is unset - user is using __init__ from repo - # without setting up git repository. - if commit_hash == "8888888": - return None - - return commit_hash[:7] + return bonsai.get_last_commit_hash() @classmethod def get_bonsai_version(cls) -> str: