From 7ef038aacc1acca8a4b452a89bbe96a524251e77 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Wed, 26 May 2021 12:45:57 -0400 Subject: [PATCH] Make git hash check more robust to errors --- src/bioregistry/version.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bioregistry/version.py b/src/bioregistry/version.py index 9a594f866..c34e6e3e1 100644 --- a/src/bioregistry/version.py +++ b/src/bioregistry/version.py @@ -4,6 +4,7 @@ import os from subprocess import CalledProcessError, check_output # noqa: S404 +from typing import Optional __all__ = [ 'VERSION', @@ -14,7 +15,7 @@ VERSION = '0.1.7-dev' -def get_git_hash() -> str: +def get_git_hash() -> Optional[str]: """Get the bioregistry git hash.""" with open(os.devnull, 'w') as devnull: try: @@ -23,8 +24,10 @@ def get_git_hash() -> str: cwd=os.path.dirname(__file__), stderr=devnull, ) + except OSError: # git isn't available + return None except CalledProcessError: - return 'UNHASHED' + return None else: return ret.strip().decode('utf-8')[:8]