forked from psychopy/psychopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changelogUpdate.py
executable file
·49 lines (34 loc) · 1.26 KB
/
changelogUpdate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# this script replaces hashtags with a sphinx URL string (to the github issues or pull request)
# written by Jon with regex code by Jeremy
import re
input_path = 'psychopy/CHANGELOG.txt'
output_path = 'docs/source/changelog.rst'
def repl_hash(m):
g = m.group(1)
return g.replace('#', '`#') + " <https://github.com/psychopy/psychopy/issues/" + g.strip(' (#') + ">`_"
def repl_blue(m):
g = m.group(1)
g = g.replace('`', "'")
return g.replace('CHANGE', ':blue:`CHANGE') + "`\n"
# raw .txt form of changelog:
txt = open(input_path, "rU").read()
# programmatic replacements:
hashtag = re.compile(r"([ (]#\d{3,4})\b")
print "found %i hashtags" %(len(hashtag.findall(txt)))
txt_hash = hashtag.sub(repl_hash, txt)
blue = re.compile(r"(CHANGE.*)\n")
print "found %i CHANGE" %(len(blue.findall(txt_hash)))
txt_hashblue = blue.sub(repl_blue, txt_hash)
# one-off specific .rst directives:
newRST = txt_hashblue.replace('.. note::', """.. raw:: html
<style> .blue {color:blue} </style>
.. role:: blue
.. note::""", 1)
# add note about blue meaning a change?
with open(output_path, "wb") as doc:
doc.write(newRST)
#test:
#text = "yes #123\n yes (#4567)\n; none of `#123, #3, #45, #12345 #123a"
#newText = expr.sub(repl, text)
#print newText