Skip to content

Commit

Permalink
Make git hash check more robust to errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed May 26, 2021
1 parent 9c7ec01 commit 7ef038a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/bioregistry/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
from subprocess import CalledProcessError, check_output # noqa: S404
from typing import Optional

__all__ = [
'VERSION',
Expand All @@ -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:
Expand All @@ -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]

Expand Down

0 comments on commit 7ef038a

Please sign in to comment.