/ src / evidently / legacy / ui / api / service.py
service.py
 1  import os
 2  from typing import Optional
 3  
 4  from litestar import Router
 5  from litestar import get
 6  
 7  import evidently
 8  from evidently.legacy.ui.api.models import Version
 9  
10  EVIDENTLY_APPLICATION_NAME = "Evidently UI"
11  
12  
13  @get("/version")
14  async def version() -> Version:
15      return Version(
16          application=EVIDENTLY_APPLICATION_NAME,
17          version=evidently.__version__,
18          commit=get_git_revision_short_hash(os.path.dirname(evidently.__file__)) or "-",
19      )
20  
21  
22  def get_git_revision_short_hash(path: str) -> Optional[str]:
23      from_env = os.environ.get("GIT_COMMIT")
24      if from_env is not None:
25          return from_env
26      import subprocess
27  
28      try:
29          return subprocess.check_output(["git", "rev-parse", "--short", "HEAD"], cwd=path).decode("ascii").strip()
30      except Exception:
31          return None
32  
33  
34  def service_api():
35      return Router("", route_handlers=[version])