def short_describe(): import os import subprocess with open(os.devnull, "r+") as devnull: proc = subprocess.Popen("git describe --abbrev=0", stdout=subprocess.PIPE, stderr=devnull, stdin=devnull, shell=True) return proc.communicate()[0].decode('utf-8').strip()[1:] MONGO_GIT_HASH="unknown" MONGO_VERSION=short_describe()