diff options
author | Frederick Muriuki Muriithi | 2023-07-05 11:12:30 +0300 |
---|---|---|
committer | zsloan | 2023-07-05 11:51:55 -0500 |
commit | e9640394e0e7c28d54cdd8c7a805c7dffa3f0be0 (patch) | |
tree | 985795a48aa3c3fb9d5144f7d50f6e97c6ed3aa1 /wqflask | |
parent | 93939248fdaaa89a9e3b74027addd8ea64d1a8e9 (diff) | |
download | genenetwork2-e9640394e0e7c28d54cdd8c7a805c7dffa3f0be0.tar.gz |
Compute the GN_VERSION in setup code not shell script
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/utility/tools.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 2b1f4b8f..aa5bdb04 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -4,6 +4,8 @@ import os import sys import json +import socket +from pathlib import Path from wqflask import app @@ -255,9 +257,27 @@ def show_settings(): print(("%s: %s%s%s%s" % (k, GREEN, BOLD, app.config[k], ENDC)), file=sys.stderr) +def gn_version_repo_info(root_dir): + """retrieve the branch name and abbreviated commit hash.""" + try: + from git import Repo + repo = Repo(root_dir) + return f"{repo.head.ref.name}-{repo.head.commit.hexsha[0:9]}" + except: + return "" + +def gn_version(): + """Compute and return the version of the application.""" + hostname = socket.gethostname() + basedir = Path(__file__).absolute().parent.parent.parent + with open(Path(basedir, "etc", "VERSION"), encoding="utf8") as version_file: + version_contents = version_file.read().strip() + base_version = f"{hostname}:{basedir.name}:{version_contents}" + repo_info = gn_version_repo_info(basedir) + return f"{base_version}-{repo_info}" if bool(repo_info) else base_version # Cached values -GN_VERSION = get_setting('GN_VERSION') +GN_VERSION = gn_version() HOME = get_setting('HOME') SERVER_PORT = get_setting('SERVER_PORT') WEBSERVER_MODE = get_setting('WEBSERVER_MODE') |