import os

from pyramid.view import view_config

VERSION = "1.1.5"

# Read git hash baked in by setup.py at install time.
_hash_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), "GIT_HASH")
try:
    with open(_hash_file) as f:
        GIT_HASH = f.read().strip()
except Exception:
    GIT_HASH = "unknown"


@view_config(route_name="version", renderer="json")
def version(request):
    return {"version": VERSION, "hash": GIT_HASH}
