From a72a38b278e6647a6f9ebb9d90640bfdaf6ab619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 16 Aug 2016 08:02:15 +0200 Subject: [PATCH] Add full Pungi version to log output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ář --- bin/pungi-koji | 5 +++-- pungi/__init__.py | 25 ++++++++++++++++++++++++- setup.py | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/bin/pungi-koji b/bin/pungi-koji index 46f2fdc5..632ab00a 100755 --- a/bin/pungi-koji +++ b/bin/pungi-koji @@ -18,7 +18,7 @@ if here != '/usr/bin': # Git checkout sys.path[0] = os.path.dirname(here) -from pungi import __version__ +from pungi import get_full_version # force C locales @@ -123,7 +123,7 @@ def main(): opts, args = parser.parse_args() if opts.version: - print("pungi %s" % __version__) + print("pungi %s" % get_full_version()) sys.exit(0) if opts.target_dir and opts.compose_dir: @@ -208,6 +208,7 @@ def run_compose(compose): compose.write_status("STARTED") compose.log_info("Host: %s" % socket.gethostname()) + compose.log_info("Pungi version: %s" % get_full_version()) compose.log_info("User name: %s" % getpass.getuser()) compose.log_info("Working directory: %s" % os.getcwd()) compose.log_info("Command line: %s" % " ".join([pipes.quote(arg) for arg in sys.argv])) diff --git a/pungi/__init__.py b/pungi/__init__.py index b777be95..328c61b8 100644 --- a/pungi/__init__.py +++ b/pungi/__init__.py @@ -1 +1,24 @@ -__version__ = "4.0" +# -*- 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' diff --git a/setup.py b/setup.py index 666fd436..171b762f 100755 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ packages = sorted(packages) setup( name = "pungi", - version = "4.1.8", # make sure it matches with pungi.__version__ + version = "4.1.8", description = "Distribution compose tool", url = "https://pagure.io/pungi", author = "Dennis Gilmore",