<reponame>TobiasWinchen/mpikat
"""
Determine the version of the code from git
"""

# if hard coded version froms etup.py use this
# ToDo, not implemented as no setup.py here
import logging
import os
_log = logging.getLogger("mpikat.core.version")
_log.debug("imported version")

VERSION = 'UNKNOWN'


try:
    import git

    path = os.path.dirname(os.path.realpath(__file__))
    _log.debug("code file located in {}".format(path))
    rroot = os.path.join(path, "../..")
    _log.debug("repository root {}".format(rroot))

    repo = git.Repo(rroot)

    # Check if current version is a tag, use shaidx otherwise 
    TAG = next((tag for tag in repo.tags if tag.commit == repo.head.commit), None)
    if TAG:
        VERSION = "{}".format(TAG)
    else:
        VERSION = "{}-{}".format(repo.head.object.hexsha, repo.head.object.authored_datetime.isoformat())

    # Add modification note
    if repo.is_dirty():
        VERSION += "+MODIFICATIONS"

except Exception as E:
    _log.debug("Error determin version from git:\n{}".format(E))
    VERSION = "UNKNOWN"

_log.debug("VERSION: {}".format(VERSION))

if __name__ == "__main__":
    print("Version: {}".format(VERSION))

"""
Determine the version of the code from git
"""

# if hard coded version froms etup.py use this
# ToDo, not implemented as no setup.py here
import logging
import os
_log = logging.getLogger("mpikat.core.version")
_log.debug("imported version")

VERSION = 'UNKNOWN'


try:
    import git

    path = os.path.dirname(os.path.realpath(__file__))
    _log.debug("code file located in {}".format(path))
    rroot = os.path.join(path, "../..")
    _log.debug("repository root {}".format(rroot))

    repo = git.Repo(rroot)

    # Check if current version is a tag, use shaidx otherwise 
    TAG = next((tag for tag in repo.tags if tag.commit == repo.head.commit), None)
    if TAG:
        VERSION = "{}".format(TAG)
    else:
        VERSION = "{}-{}".format(repo.head.object.hexsha, repo.head.object.authored_datetime.isoformat())

    # Add modification note
    if repo.is_dirty():
        VERSION += "+MODIFICATIONS"

except Exception as E:
    _log.debug("Error determin version from git:\n{}".format(E))
    VERSION = "UNKNOWN"

_log.debug("VERSION: {}".format(VERSION))

if __name__ == "__main__":
    print("Version: {}".format(VERSION))
Determine the version of the code from git # if hard coded version froms etup.py use this # ToDo, not implemented as no setup.py here # Check if current version is a tag, use shaidx otherwise # Add modification note