diff --git a/configure.ac b/configure.ac index 014495caaab75b9f89b524a7598e5cd7c710bf84..898cedd3157798285cd836810c2d2ce4b83a1091 100644 --- a/configure.ac +++ b/configure.ac @@ -37,4 +37,7 @@ AC_SUBST([zshcompdir], [$with_zshcompdir]) AC_PROG_SED +AM_CONDITIONAL([ISGIT],[test -d .git]) +AM_COND_IF([ISGIT],[VERSION=$VERSION+git]) + AC_OUTPUT diff --git a/installsystems/__init__.py.in b/installsystems/__init__.py.in index 7c2757cecb562dd212b66d7d8680b4243a0f6bf7..1b868ec31b03c1564aa7b8656b12caf0c476835e 100644 --- a/installsystems/__init__.py.in +++ b/installsystems/__init__.py.in @@ -24,4 +24,26 @@ canonical_name="installsystems" version = "@VERSION@" verbosity = 1 # 0: quiet, 1: normal, 2: debug +def git_version(): + import os + import sys + from subprocess import check_output, CalledProcessError + version = "" + cwd = os.getcwd() + try: + os.chdir(os.path.dirname(sys.argv[0])) + version = check_output(["git", "describe", "--tags", "--always" ], + stdin=open(os.devnull, 'rb'), + stderr=open(os.devnull, "wb")).strip() + if len(version) > 0: + version = "-" + version + except (OSError, CalledProcessError): + pass + finally: + os.chdir(cwd) + return version + +if version.find("+git") >= 0: + version += git_version() + __all__ = []