sequenceeditor: self.diffwidget -> self.diff typofix
[git-cola.git] / cola / version.py
blob7d702d592a9e818bf90ce92e61cdc003562d926c
1 """Provide git-cola's version number"""
2 from __future__ import absolute_import, division, print_function, unicode_literals
3 import os
4 import sys
6 if __name__ == '__main__':
7 srcdir = os.path.dirname(os.path.dirname(__file__))
8 sys.path.insert(1, srcdir)
10 from .git import STDOUT # noqa
11 from .decorators import memoize # noqa
12 from ._version import VERSION # noqa
14 # minimum version requirements
15 _versions = {
16 # git diff learned --patience in 1.6.2
17 # git mergetool learned --no-prompt in 1.6.2
18 # git difftool moved out of contrib in git 1.6.3
19 'git': '1.6.3',
20 'python': '2.6',
21 # new: git cat-file --filters --path=<path> SHA1
22 # old: git cat-file --filters blob SHA1:<path>
23 'cat-file-filters-path': '2.11.0',
24 # git diff --submodule was introduced in 1.6.6
25 'diff-submodule': '1.6.6',
26 # git check-ignore was introduced in 1.8.2, but did not follow the same
27 # rules as git add and git status until 1.8.5
28 'check-ignore': '1.8.5',
29 # git push --force-with-lease
30 'force-with-lease': '1.8.5',
31 # git submodule update --recursive was introduced in 1.6.5
32 'submodule-update-recursive': '1.6.5',
33 # git include.path pseudo-variable was introduced in 1.7.10
34 'config-includes': '1.7.10',
35 # git for-each-ref --sort=version:refname
36 'version-sort': '2.7.0',
37 # Qt support for QT_AUTO_SCREEN_SCALE_FACTOR and QT_SCALE_FACTOR
38 'qt-hidpi-scale': '5.6.0',
39 # git rev-parse --show-superproject-working-tree was added in 2.13.0
40 'show-superproject-working-tree': '2.13.0',
44 def get(key):
45 """Returns an entry from the known versions table"""
46 return _versions.get(key)
49 def version():
50 """Returns the current version"""
51 return VERSION
54 @memoize
55 def check_version(min_ver, ver):
56 """Check whether ver is greater or equal to min_ver"""
57 min_ver_list = version_to_list(min_ver)
58 ver_list = version_to_list(ver)
59 return min_ver_list <= ver_list
62 @memoize
63 def check(key, ver):
64 """Checks if a version is greater than the known version for <what>"""
65 return check_version(get(key), ver)
68 def check_git(context, key):
69 """Checks if Git has a specific feature"""
70 return check(key, git_version(context))
73 def version_to_list(value):
74 """Convert a version string to a list of numbers or strings"""
75 ver_list = []
76 for p in value.split('.'):
77 try:
78 n = int(p)
79 except ValueError:
80 n = p
81 ver_list.append(n)
82 return ver_list
85 @memoize
86 def git_version_str(context):
87 """Returns the current GIT version"""
88 git = context.git
89 return git.version()[STDOUT].strip()
92 @memoize
93 def git_version(context):
94 """Returns the current GIT version"""
95 parts = git_version_str(context).split()
96 if parts and len(parts) >= 3:
97 result = parts[2]
98 else:
99 # minimum supported version
100 result = '1.6.3'
101 return result
104 def cola_version():
105 suffix = version()
106 return 'cola version %s' % suffix
109 def print_version(brief=False):
110 if brief:
111 msg = version()
112 else:
113 msg = cola_version()
114 sys.stdout.write('%s\n' % msg)