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 '' if unavailable.""" try: return subprocess.check_output(["git", "rev-parse", "HEAD"], shell=False, encoding="utf-8").strip() except Exception: return "" def get_battlewords_version() -> str: """Read the __version__ variable from battlewords/__init__.py.""" try: from battlewords import __version__ return __version__ except Exception: return "" 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"""
Battlewords v{battlewords_version}  |  commit: {commit}  |  python: {python_version}  |  streamlit: {streamlit_version}
""" return html