(bump:minor) Feat: Add mechanism for user-site update and auto creating releases (#56)

* move flowsettings.py and launch.py to root

* update docs

* sync sub package versions

* rename launch.py to app.py and make run scripts work with installation package

* add update scripts

* auto version for root package

* rename authors and update doc dir

* Update auto-bump-and-release.yaml to trigger on push to main branch

* latest as branch instead of tag

* pin deps versions

* cache the changelogs
This commit is contained in:
ian_Cin
2024-05-15 16:34:50 +07:00
committed by GitHub
parent eb198e0ff3
commit 654501e01c
20 changed files with 596 additions and 145 deletions

View File

@@ -1,25 +1,83 @@
from importlib.metadata import version
from pathlib import Path
import gradio as gr
import requests
from theflow.settings import settings
CHANGELOG_CACHE_DIR = Path(settings.KH_APP_DATA_DIR) / "changelogs"
def get_remote_doc(url):
try:
res = requests.get(url)
return res.text
except Exception as e:
print(f"Failed to fetch document from {url}: {e}")
return ""
def get_changelogs(version):
# try retrieve from cache
if (CHANGELOG_CACHE_DIR / f"{version}.md").exists():
with open(CHANGELOG_CACHE_DIR / f"{version}.md", "r") as fi:
return fi.read()
release_url = f"https://api.github.com/repos/Cinnamon/kotaemon/releases/{version}"
try:
res = requests.get(release_url).json()
changelogs = res.get("body", "")
# cache the changelogs
with open(CHANGELOG_CACHE_DIR / f"{version}.md", "w") as fi:
fi.write(changelogs)
return changelogs
except Exception as e:
print(f"Failed to fetch changelogs from {release_url}: {e}")
return ""
class HelpPage:
def __init__(self, app):
self._app = app
self.md_dir = Path(__file__).parent.parent / "assets" / "md"
self.doc_dir = Path(__file__).parents[4] / "docs"
self.doc_dir = Path(settings.KH_DOC_DIR)
self.remote_content_url = "https://raw.githubusercontent.com/Cinnamon/kotaemon"
with gr.Accordion("About"):
with (self.md_dir / "about.md").open(encoding="utf-8") as fi:
gr.Markdown(fi.read())
self.app_version = None
try:
# Caution: This might produce the wrong version
# https://stackoverflow.com/a/59533071
self.app_version = version(settings.KH_PACKAGE_NAME)
except Exception as e:
print(f"Failed to get app version: {e}")
with gr.Accordion("User Guide"):
about_md_dir = self.doc_dir / "about.md"
if about_md_dir.exists():
with (self.doc_dir / "about.md").open(encoding="utf-8") as fi:
about_md = fi.read()
else: # fetch from remote
about_md = get_remote_doc(
f"{self.remote_content_url}/v{self.app_version}/docs/about.md"
)
if about_md:
with gr.Accordion("About"):
gr.Markdown(about_md)
user_guide_md_dir = self.doc_dir / "usage.md"
if user_guide_md_dir.exists():
with (self.doc_dir / "usage.md").open(encoding="utf-8") as fi:
gr.Markdown(fi.read())
user_guide_md = fi.read()
else: # fetch from remote
user_guide_md = get_remote_doc(
f"{self.remote_content_url}/v{self.app_version}/docs/usage.md"
)
if user_guide_md:
with gr.Accordion("User Guide"):
gr.Markdown(user_guide_md)
with gr.Accordion("Changelogs"):
gr.Markdown(self.get_changelogs())
def get_changelogs(self):
with (self.md_dir / "changelogs.md").open(encoding="utf-8") as fi:
return fi.read()
if self.app_version:
changelogs = get_changelogs("tags/v" + self.app_version)
if changelogs:
with gr.Accordion(f"Changelogs (v{self.app_version})"):
gr.Markdown(changelogs)