import os
import subprocess


def get_current_version(debug=True):
    if "VERSION" in os.environ:
        return os.environ["VERSION"]

    if debug:
        try:
            output = subprocess.check_output(
                ["git", "show", "--no-patch", "--format=%H"], universal_newlines=True
            )
            return output.strip()
        except (subprocess.CalledProcessError, OSError):
            return ""

    try:
        output = subprocess.check_output(
            ["git", "describe", "--tags"], universal_newlines=True
        )
        return output.strip()
    except (subprocess.CalledProcessError, OSError):
        return ""
