From 53d1d46838ad88e4ee4d4d37469aa88d98e93fb1 Mon Sep 17 00:00:00 2001 From: Hugo Wang Date: Wed, 2 Nov 2016 12:24:43 +0800 Subject: [PATCH] added commit date in xonfig --- news/xonfig-commit-date.rst | 14 ++++++++++++++ setup.py | 11 ++++++++++- xonsh/platform.py | 10 +++++----- xonsh/xonfig.py | 10 ++++++++-- 4 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 news/xonfig-commit-date.rst diff --git a/news/xonfig-commit-date.rst b/news/xonfig-commit-date.rst new file mode 100644 index 000000000..ad5783992 --- /dev/null +++ b/news/xonfig-commit-date.rst @@ -0,0 +1,14 @@ +**Added:** None + +* xonfig now contains the latest git commit date if xonsh installed + from source. + +**Changed:** None + +**Deprecated:** None + +**Removed:** None + +**Fixed:** None + +**Security:** None diff --git a/setup.py b/setup.py index f43a1b89f..dc1671a2b 100755 --- a/setup.py +++ b/setup.py @@ -129,8 +129,17 @@ def dirty_version(): return False sha = sha.strip('g') replace_version(N) + _cmd = ['git', 'show', '--format=%cd', '--date=local', sha] + try: + _date = subprocess.check_output(_cmd) + _date = _date.decode('ascii') + # remove weekday name for a shorter string + _date = ' '.join(_date.split()[1:]) + except: + _date = '' + print('failed to get commit date', file=sys.stderr) with open('xonsh/dev.githash', 'w') as f: - f.write(sha) + f.write('{}|{}'.format(sha, _date)) print('wrote git version: ' + sha, file=sys.stderr) return True diff --git a/xonsh/platform.py b/xonsh/platform.py index 5dee72aa0..1d09c7829 100644 --- a/xonsh/platform.py +++ b/xonsh/platform.py @@ -173,14 +173,14 @@ def pathbasename(p): @functools.lru_cache(1) def githash(): install_base = os.path.dirname(__file__) + sha = None + date_ = None try: with open('{}/dev.githash'.format(install_base), 'r') as f: - sha = f.read().strip() - if not sha: - sha = None + sha, date_ = f.read().strip().split('|') except FileNotFoundError: - sha = None - return sha + pass + return sha, date_ # diff --git a/xonsh/xonfig.py b/xonsh/xonfig.py index df918efb6..8cc37276f 100644 --- a/xonsh/xonfig.py +++ b/xonsh/xonfig.py @@ -345,7 +345,12 @@ def _info(ns): ply.__version__ = '3.8' data = [ ('xonsh', XONSH_VERSION), - ('Git SHA', githash()), + ] + hash_, date_ = githash() + if hash_: + data.append(('Git SHA', hash_)) + data.append(('Commit Date', date_)) + data.extend([ ('Python', '{}.{}.{}'.format(*PYTHON_VERSION_INFO)), ('PLY', ply.__version__), ('have readline', is_readline_available()), @@ -353,7 +358,8 @@ def _info(ns): ('shell type', env.get('SHELL_TYPE')), ('pygments', pygments_version()), ('on posix', bool(ON_POSIX)), - ('on linux', ON_LINUX)] + ('on linux', ON_LINUX), + ]) if ON_LINUX: data.append(('distro', linux_distro())) data.extend([