Skip to content

Commit

Permalink
Add version
Browse files Browse the repository at this point in the history
  • Loading branch information
nsubiron committed Oct 21, 2014
1 parent ab3e3a7 commit 21f7c26
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SOURCE = source
default: run

run: dist
python bin/$(APPNAME).pyz -h
python bin/$(APPNAME).pyz --version

dist: bin/$(APPNAME).pyz

Expand Down
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]'))
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions source/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import json
import logging
import os
import pkgutil
import re
import sys

Expand All @@ -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]*$)'
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 21f7c26

Please sign in to comment.