diff --git a/Makefile b/Makefile index b546d15..f855852 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ SOURCE = source default: run run: dist - python bin/$(APPNAME).pyz -h + python bin/$(APPNAME).pyz --version dist: bin/$(APPNAME).pyz diff --git a/setup.py b/setup.py index dcb04f7..3e2b727 100644 --- a/setup.py +++ b/setup.py @@ -7,8 +7,13 @@ import logging import os import re +import subprocess import zipfile +def get_version(): + command = ['git', 'describe', '--tags', '--dirty', '--always'] + return subprocess.check_output(command).decode('utf-8') + def source_walk(root): root = os.path.abspath(root) regex = re.compile(fnmatch.translate('*.py[co]')) @@ -45,6 +50,7 @@ def setup(): args.output = args.source + '.zip' with zipfile.ZipFile(args.output, 'w', zipfile.ZIP_DEFLATED) as fzip: + fzip.writestr('version.txt', get_version()) for path, relpath in source_walk(args.source): fzip.write(path, relpath) diff --git a/source/configure.py b/source/configure.py index 9f94575..213ce56 100644 --- a/source/configure.py +++ b/source/configure.py @@ -16,6 +16,7 @@ import json import logging import os +import pkgutil import re import sys @@ -31,6 +32,9 @@ def critical_error(message, *args): logging.critical(message, *args) sys.exit(1) +def get_resource(filename): + return pkgutil.get_data('__main__', filename).decode('utf-8') + def remove_comments(string): """Remove C comments from string. See http://stackoverflow.com/a/18381470""" pattern = r'(\".*?\"|\'.*?\')|(/\*.*?\*/|//[^\r\n]*$)' @@ -213,6 +217,10 @@ def iterate_targets(root): def main(): argparser = ArgumentParser(description=__doc__) + argparser.add_argument( + '-v', '--version', + action='version', + version='%(prog)s ' + get_resource('version.txt')) argparser.add_argument( '-d', '--debug', action='store_true',