From 4897cb74b763f2e312b5b818c51f592127ada7f0 Mon Sep 17 00:00:00 2001 From: Stefan Klut Date: Tue, 14 Nov 2023 11:29:14 +0100 Subject: [PATCH] move version to function --- core/setup.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/setup.py b/core/setup.py index 28eb324..9f5f814 100644 --- a/core/setup.py +++ b/core/setup.py @@ -48,6 +48,17 @@ def setup_logging(cfg: Optional[CfgNode] = None, save_log: bool = True) -> loggi return logger +def get_git_hash() -> str: + version_path = Path("version_info") + + if version_path.is_file(): + with version_path.open(mode="r") as file: + git_hash = file.read() + else: + git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=Path(__file__).resolve().parent).strip().decode() + return git_hash + + # TODO Replace with LazyConfig def setup_cfg(args, cfg: Optional[CfgNode] = None) -> CfgNode: """ @@ -89,12 +100,7 @@ def setup_cfg(args, cfg: Optional[CfgNode] = None) -> CfgNode: version_path = Path("version_info") - if version_path.is_file(): - with version_path.open(mode="r") as file: - git_hash = file.read() - else: - git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=Path(__file__).resolve().parent).strip().decode() - cfg.LAYPA_GIT_HASH = git_hash + cfg.LAYPA_GIT_HASH = get_git_hash() cfg.CONFIG_PATH = str(Path(args.config).resolve())