diff options
author | toonn <toonn@toonn.io> | 2018-06-06 00:07:05 +0200 |
---|---|---|
committer | toonn <toonn@toonn.io> | 2018-06-06 00:44:31 +0200 |
commit | 9edc595440e6e64467d36d2f0f60ce8eee8450f8 (patch) | |
tree | 4f80279c223c215aa98f487db3a1e1dd6c05737a | |
parent | 81e1070f91ddc139f1a6abdfda962da3b1bb4c60 (diff) | |
download | ranger-9edc595440e6e64467d36d2f0f60ce8eee8450f8.tar.gz |
Introduce a helper function for versioning
The `version_helper` function should make version changes simpler, upon a release simple bump `__version__` and change `__release__` to `True`, afterwards change `__release__` back to `False`. It also tries to call `git describe` so `ranger --version` reports a commit hash if available. This should prevent slip-ups where released versions report ambiguously as being `ranger-master x.y.z` which is what we use for non-release versions. Fixes #1197, which was a misunderstanding caused by a slip-up.
-rw-r--r-- | ranger/__init__.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/ranger/__init__.py b/ranger/__init__.py index 0d7c8fdc..ae1ecc48 100644 --- a/ranger/__init__.py +++ b/ranger/__init__.py @@ -12,9 +12,28 @@ from __future__ import (absolute_import, division, print_function) import os + +# Version helper +def version_helper(): + if __release__: + version_string = 'ranger {0}'.format(__version__) + else: + import subprocess + version_string = 'ranger-master {0}' + try: + git_describe = subprocess.check_output(['git', 'describe'], + universal_newlines=True, + stderr=subprocess.PIPE) + version_string = version_string.format(git_describe.strip('\n')) + except (OSError, subprocess.CalledProcessError): + version_string = version_string.format(__version__) + return version_string + + # Information __license__ = 'GPL3' __version__ = '1.9.1' +__release__ = False __author__ = __maintainer__ = 'Roman Zimbelmann' __email__ = 'hut@hut.pm' @@ -27,7 +46,7 @@ MACRO_DELIMITER = '%' MACRO_DELIMITER_ESC = '%%' DEFAULT_PAGER = 'less' USAGE = '%prog [options] [path]' -VERSION = 'ranger-master {0}'.format(__version__) +VERSION = version_helper() # These variables are ignored if the corresponding # XDG environment variable is non-empty and absolute |