Spaces:
Running
Running
File size: 1,565 Bytes
85779ec e63d029 85779ec e63d029 85779ec e63d029 85779ec e63d029 85779ec e63d029 85779ec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
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>
|
<span>commit: <code>{commit}</code></span>
|
<span>python: <span title="{full_python}">{python_version}</span></span>
|
<span>streamlit: {streamlit_version}</span>
</div>
"""
return html
|