BattleWords / battlewords /version_info.py
Surn's picture
Add version info, scrollable sidebar, and radar fix
e63d029
import sys
import subprocess
try:
import streamlit as st
except Exception: # pragma: no cover
st = None
def commit_hash() -> str:
"""Return current git commit hash or '<none>' if unavailable."""
try:
return subprocess.check_output(["git", "rev-parse", "HEAD"], shell=False, encoding="utf-8").strip()
except Exception:
return "<none>"
def get_battlewords_version() -> str:
"""Read the __version__ variable from battlewords/__init__.py."""
try:
from battlewords import __version__
return __version__
except Exception:
return "<unknown>"
def versions_html() -> str:
"""Return a small HTML snippet with runtime and app environment info.
Includes: git commit, Python version, Streamlit version, and Battlewords version.
"""
python_version = ".".join(str(x) for x in sys.version_info[:3])
full_python = sys.version.replace("\n", " ")
commit = commit_hash()
streamlit_version = getattr(st, "__version__", "not installed")
battlewords_version = get_battlewords_version()
html = f"""
<div style="font-size: 0.85rem; color: #b7c3d0; margin-top: 1.5rem; padding-top: 0.5rem; border-top: 1px solid rgba(255,255,255,0.15);">
<span>Battlewords v{battlewords_version}</span>
&nbsp;|&nbsp;
<span>commit: <code>{commit}</code></span>
&nbsp;|&nbsp;
<span>python: <span title="{full_python}">{python_version}</span></span>
&nbsp;|&nbsp;
<span>streamlit: {streamlit_version}</span>
</div>
"""
return html