mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 18:57:17 +00:00
Display actual Bonsai version for live repo (reuse last commit date)
This commit is contained in:
@@ -252,6 +252,12 @@ if IN_BLENDER:
|
|||||||
|
|
||||||
ifcopenshell.api.add_pre_listener("*", "action_logger", log_api)
|
ifcopenshell.api.add_pre_listener("*", "action_logger", log_api)
|
||||||
|
|
||||||
|
def purge_cache():
|
||||||
|
"""Purge cache left from previous session (e.g. after reload or update)."""
|
||||||
|
import bonsai.tool as tool
|
||||||
|
|
||||||
|
tool.Blender.get_bonsai_version.cache_clear()
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
clean_up_dlls_safe_links()
|
clean_up_dlls_safe_links()
|
||||||
@@ -269,6 +275,7 @@ if IN_BLENDER:
|
|||||||
bonsai.REINSTALLED_BBIM_VERSION = current_version
|
bonsai.REINSTALLED_BBIM_VERSION = current_version
|
||||||
|
|
||||||
bonsai.bim.register()
|
bonsai.bim.register()
|
||||||
|
purge_cache()
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import contextlib
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
from ifcopenshell import entity_instance
|
from ifcopenshell import entity_instance
|
||||||
@@ -34,9 +35,10 @@ import bonsai.tool as tool
|
|||||||
import bonsai.bim
|
import bonsai.bim
|
||||||
import types
|
import types
|
||||||
import importlib
|
import importlib
|
||||||
|
from datetime import datetime
|
||||||
from mathutils import Vector
|
from mathutils import Vector
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from functools import lru_cache
|
from functools import lru_cache, cache
|
||||||
from bonsai.bim.ifc import IFC_CONNECTED_TYPE
|
from bonsai.bim.ifc import IFC_CONNECTED_TYPE
|
||||||
from typing import Any, Optional, Union, Literal, Iterable, Callable, TypeVar, Generator, TYPE_CHECKING
|
from typing import Any, Optional, Union, Literal, Iterable, Callable, TypeVar, Generator, TYPE_CHECKING
|
||||||
from typing_extensions import assert_never
|
from typing_extensions import assert_never
|
||||||
@@ -1246,9 +1248,27 @@ class Blender(bonsai.core.tool.Blender):
|
|||||||
return bonsai.get_last_commit_hash()
|
return bonsai.get_last_commit_hash()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@cache
|
||||||
def get_bonsai_version(cls) -> str:
|
def get_bonsai_version(cls) -> str:
|
||||||
bbim = cls.get_bbim_extension_package()
|
version = None
|
||||||
version = bbim.bbim_semver["version"]
|
|
||||||
|
# Try to retrieve actual version for live-dev environment.
|
||||||
|
with contextlib.suppress(Exception):
|
||||||
|
import git
|
||||||
|
|
||||||
|
path = Path(__file__).resolve().parent
|
||||||
|
repo = git.Repo(str(path), search_parent_directories=True)
|
||||||
|
repo_path = repo.working_tree_dir
|
||||||
|
assert repo_path
|
||||||
|
version_ = (Path(repo_path) / "VERSION").read_text().strip()
|
||||||
|
commit_date = bonsai.get_last_commit_date()
|
||||||
|
assert commit_date
|
||||||
|
commit_date = datetime.fromisoformat(commit_date)
|
||||||
|
version = f"{version_}-alpha{commit_date.strftime('%y%m%d')}"
|
||||||
|
|
||||||
|
if version is None:
|
||||||
|
bbim = cls.get_bbim_extension_package()
|
||||||
|
version = bbim.bbim_semver["version"]
|
||||||
if commit_hash := cls.get_last_commit_hash():
|
if commit_hash := cls.get_last_commit_hash():
|
||||||
version += f"-{commit_hash}"
|
version += f"-{commit_hash}"
|
||||||
return version
|
return version
|
||||||
|
|||||||
Reference in New Issue
Block a user