diff --git a/setup.py b/setup.py index 1081b5aa..83317401 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,7 @@ import shutil from setuptools import setup, Extension from setuptools.command.install import install +from setuptools.command.sdist import sdist from src.version import softwareVersion @@ -45,6 +46,16 @@ class InstallCmd(install): return install.run(self) +class SdistCmd(sdist): + def run(self): + """Write last commit into version.py""" + from src.paths import lastCommit + last_commit = lastCommit() + with open('src/version.py', 'ab') as out: + out.write('commit = %s' % last_commit) + return sdist.run(self) + + if __name__ == "__main__": here = os.path.abspath(os.path.dirname(__file__)) with open(os.path.join(here, 'README.md')) as f: @@ -146,5 +157,8 @@ if __name__ == "__main__": # ] }, scripts=['src/pybitmessage'], - cmdclass={'install': InstallCmd} + cmdclass={ + 'install': InstallCmd, + 'sdist': SdistCmd + } ) diff --git a/src/bitmessageqt/dialogs.py b/src/bitmessageqt/dialogs.py index 3d92b776..48118349 100644 --- a/src/bitmessageqt/dialogs.py +++ b/src/bitmessageqt/dialogs.py @@ -1,4 +1,6 @@ -import paths +from datetime import datetime + +import version import widgets from address_dialogs import ( AddAddressDialog, NewAddressDialog, NewSubscriptionDialog, @@ -8,7 +10,6 @@ from newchandialog import NewChanDialog from PyQt4 import QtGui from retranslateui import RetranslateMixin from tr import _translate -from version import softwareVersion __all__ = [ @@ -22,22 +23,29 @@ class AboutDialog(QtGui.QDialog, RetranslateMixin): def __init__(self, parent=None): super(AboutDialog, self).__init__(parent) widgets.load('about.ui', self) - last_commit = paths.lastCommit() - version = softwareVersion + + # Adjusting version, commit and year info + full_version = version.softwareVersion + try: # commit written by sdist setuptools command + last_commit = version.commit + except AttributeError: + import paths + last_commit = paths.lastCommit() commit = last_commit.get('commit') if commit: - version += '-' + commit[:7] + full_version += '-' + commit[:7] self.labelVersion.setText( self.labelVersion.text().replace( - ':version:', version - ).replace(':branch:', commit or 'v%s' % version) + ':version:', full_version + ).replace(':branch:', commit or 'v%s' % full_version) ) self.labelVersion.setOpenExternalLinks(True) - try: + try: # last copyright year from last commit self.label_2.setText( self.label_2.text().replace( - '2017', str(last_commit.get('time').year) + '2017', + str(datetime.fromtimestamp(last_commit.get('time')).year) )) except AttributeError: pass diff --git a/src/paths.py b/src/paths.py index c68701b4..54aafad6 100644 --- a/src/paths.py +++ b/src/paths.py @@ -1,7 +1,6 @@ import os import re import sys -from datetime import datetime # When using py2exe or py2app, the variable frozen is added to the sys # namespace. This can be used to setup a different code path for @@ -126,9 +125,9 @@ def lastCommit(): try: with open(githeadfile, 'rt') as githead: line = tail(githead, 1) - result['commit'] = line.split()[1] - result['time'] = datetime.fromtimestamp( - float(re.search(r'>\s*(.*?)\s', line).group(1)) + result.update( + commit=line.split()[1], + time=float(re.search(r'>\s*(.*?)\s', line).group(1)) ) except (IOError, AttributeError, TypeError): pass