From cde57f260446809e097f0a2ae50197de42f43f0b Mon Sep 17 00:00:00 2001 From: SouthFox Date: Sat, 18 Mar 2023 13:08:17 +0800 Subject: [PATCH] feat/show version close #5 --- app/config.py | 17 ++++++++++++++++- app/main.py | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/config.py b/app/config.py index b1704de..a36075a 100644 --- a/app/config.py +++ b/app/config.py @@ -4,6 +4,8 @@ import tomli import pydantic DEBUG = True +MAIN_VERSION = "0.0.1" + ROOT_DIR = Path().parent.resolve() DB_PATH = ROOT_DIR / "data" / "database.db" SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_PATH}" @@ -39,6 +41,18 @@ def load_config() -> Config: f"{_CONFIG_FILE} is missing" ) +def get_version_commit() -> str: + import subprocess + try: + return ( + '+' + + subprocess.check_output(["git", "rev-parse", "--short=8", "HEAD"]) + .split()[0] + .decode() + ) + except Exception: + return "+dev" + CONFIG = load_config() DOMAIN = CONFIG.domain _SCHEME = "https" if CONFIG.https else "http" @@ -47,7 +61,8 @@ BASE_URL = ID USERNAME = CONFIG.username KEY_PATH = (ROOT_DIR / "data" / "key.pem") -USER_AGENT = "Fediverse Application/Foxhole-0.0.1" +VERSION = "Foxhole-"+ MAIN_VERSION + get_version_commit() +USER_AGENT = "Fediverse Application/" + VERSION AP_CONTENT_TYPE = "application/activity+json" MANUALLY_APPROVES_FOLLOWERS = CONFIG.manually_approves_followers diff --git a/app/main.py b/app/main.py index bae220d..e24aeee 100644 --- a/app/main.py +++ b/app/main.py @@ -24,6 +24,7 @@ from app.config import BASE_URL from app.config import DOMAIN from app.config import ID from app.config import USERNAME +from app.config import VERSION from app.database import AsyncSession from app.database import get_db_session from app.boxes import save_incoming @@ -109,7 +110,7 @@ async def nodeinfo( "version": "2.0", "software": { "name": "foxhole", - "version": "0.0.1", + "version": VERSION, }, "protocols": ["activitypub"], "services": {"inbound": [], "outbound": []},