pungi/pungi/__init__.py
Lubomír Sedlář a72a38b278 Add full Pungi version to log output
This should help with debugging by providing better information on which
Pungi version created the compose. In development, the version will show
output of git describe, in production it asks which version is installed
in site-packages/. The egg-info directory must be installed for this to
work.

It is no longer necessary to synchronize version in `setup.py` with
`pungi/__init__.py`.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
2016-08-16 08:12:40 +02:00

25 lines
852 B
Python

# -*- coding: utf-8 -*-
import os
import re
def get_full_version():
"""
Find full version of Pungi: if running from git, this will return cleaned
output of `git describe`, otherwise it will look for installed version.
"""
location = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')
if os.path.isdir(os.path.join(location, '.git')):
import subprocess
proc = subprocess.Popen(['git', '-C', location, 'describe', '--tags'],
stdout=subprocess.PIPE)
output, _ = proc.communicate()
return re.sub(r'-1.fc\d\d?', '', output.strip().replace('pungi-', ''))
else:
import pkg_resources
try:
return pkg_resources.get_distribution('pungi').version
except pkg_resources.DistributionNotFound:
return 'unknown'