File: updateChangelog.py

package info (click to toggle)
psychopy 2020.2.10%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 44,056 kB
  • sloc: python: 119,649; javascript: 3,022; makefile: 148; sh: 125; xml: 9
file content (68 lines) | stat: -rw-r--r-- 2,031 bytes parent folder | download
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# this script replaces hashtags with a sphinx URL string (to the github issues or pull request)
# written by Jon with regex code by Jeremy

from __future__ import absolute_import, print_function
import re
from pathlib import Path
import os

thisFolder = Path(__file__).absolute().parent
rootFolder = thisFolder.parent
input_path = rootFolder / 'psychopy/CHANGELOG.txt'
output_path = thisFolder / 'source/changelog.rst'


def repl_issue(m):
    g = m.group(1)
    return g.replace('#', '`#') +  " <https://github.com/psychopy/psychopy/issues/" + g.strip(' (#') + ">`_"

def repl_commit(m):
    g = m.group(1)
    return g.replace('#', '`commit:')[:18] +  " <https://github.com/psychopy/psychopy/commit/" + g.strip(' (#') + ">`_"

def repl_noncompat(m):
    g = m.group(1)
    g = g.replace('`', "'")
    return g.replace('CHANGE', ':noncompat:`CHANGE') + "`\n"

print(thisFolder)
print(f"looking in {input_path.absolute()} from {os.getcwd()}")
# raw .txt form of changelog:
txt = open(input_path, "rU", encoding='utf8').read()

# programmatic replacements:
hashtag = re.compile(r"([ (]#\d{3,5})\b")
print("found %i issue tags" %(len(hashtag.findall(txt))))
txt_hash = hashtag.sub(repl_issue, txt)

hashtag = re.compile(r"([ (]#[0-9a-f]{6,})\b")
print("found %i commit tags" %(len(hashtag.findall(txt_hash))))
txt_hash = hashtag.sub(repl_commit, txt_hash)

noncompat = re.compile(r"(CHANGE.*)\n")
print("found %i CHANGE" %(len(noncompat.findall(txt_hash))))
txt_hash_noncompat = noncompat.sub(repl_noncompat, txt_hash)

# one-off specific .rst directives:
newRST = txt_hash_noncompat.replace('.. note::', """.. raw:: html

    <style> .noncompat {color:red} </style>

.. role:: noncompat

.. note::""", 1)

# add note about blue meaning a change?

with open(output_path, "w", encoding='utf8') as doc:
    doc.write(newRST)

print(f"generated {output_path}")

#test:
#text = "yes #123\n yes (#4567)\n; none of `#123, #3, #45, #12345 #123a"
#newText = expr.sub(repl, text)
#print newText