Reuse get_last_commit_hash

Noticed that hash wasn't updating from live git repo because of this.
Also update commit data only when running the package, not extension.
This commit is contained in:
Andrej730
2025-05-02 10:54:58 +05:00
parent 839b2c9c1f
commit 7a5e5fe602
2 changed files with 19 additions and 20 deletions
+18 -10
View File
@@ -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
+1 -10
View File
@@ -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: