Skip to content

Commit

Permalink
autogenerate completion badge on appveyor (refs #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
swistakm committed Nov 3, 2016
1 parent 6c9768e commit ed3f8be
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ build_script:
on_success:
- if [%APPVEYOR_REPO_BRANCH%]==[master] (
python.exe -m pip install dropbox &&
python.exe ci/dropbox_upload.py)
python.exe ci/dropbox_upload.py &&
python.exe ci/completion.py imgui/cimgui.pxd dist/completion.svg)

artifacts:
- path: dist\*
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
completion.svg

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down Expand Up @@ -105,5 +106,8 @@ ENV/
# Rope project settings
.ropeproject

# Pycharm project settings
.idea/

# Bootstrap marker
.bootstrapped
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,4 @@ livedoc: build

.PHONY: completion
completion:
@# This escaping is crazy. But it works.
$(eval $@_ALL_METHODS := grep imgui/cimgui.pxd -ve '\(^\s*\#\)\|\(^$$$$\)' | wc -l | tr -d ' ' )
$(eval $@_DONE_METHODS := grep imgui/cimgui.pxd -ve '\(^\s*\#\)\|\(^$$$$\)' | grep ✓ | wc -l | tr -d ' ' )

@echo Heuristic completion status: $$(${$@_DONE_METHODS}) / $$(${$@_ALL_METHODS})

@python ci/completion.py imgui/cimgui.pxd
49 changes: 49 additions & 0 deletions ci/completion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
import sys
import re

try:
from urllib2 import urlopen, Request
from urllib import quote
from urllib2 import HTTPError
except ImportError:
from urllib.parse import quote
from urllib.request import urlopen, Request
from urllib.error import HTTPError


BASE_URL = 'https://img.shields.io/badge/completion-%s-blue.svg'
ALL_RE = re.compile(r'(?!(^\s*$)|(^\s*#))')
DONE_RE = re.compile(r'(?!(^\s*$)|(^\s*#)).*✓')


if __name__ == "__main__":
if len(sys.argv) == 2:
pxd_file_name, out_file_name = sys.argv[1], None
elif len(sys.argv) == 3:
pxd_file_name, out_file_name = sys.argv[1:]
else:
pxd_file_name, out_file_name = None, None
exit("Usage: python %s PXD_FILE [OUT_FILE]" % __file__)

with open(pxd_file_name) as pyx_file:
lines = pyx_file.readlines()

all_count = len(list(filter(ALL_RE.match, lines)))
done_count = len(list(filter(DONE_RE.match, lines)))
result = "%d %% (%s of %s)" % (
float(done_count)/all_count * 100,
done_count, all_count
)

if out_file_name:
with open(out_file_name, 'w') as out_file:
request = Request(
BASE_URL % quote(result),
# note: Shields.io does not allow Python-urllib/* user agent
headers={"User-Agent": "Spoofed"}
)
response = urlopen(request)
out_file.write(response.read())

print(result)

0 comments on commit ed3f8be

Please sign in to comment.