Debian Codegraph @

3rdparty/catch2/tools/scripts/extractFeaturesFromReleaseNotes.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 #
4 # extractFeaturesFromReleaseNotes.py
5 #
6 # Read the release notes - docs/release-notes.md - and generate text
7 # for pasting in to individual documentation pages, to indicate which
8 # versions recent features were released in.
9 #
10 # Using the output of the file is easier than manually constructing
11 # the text to paste in to documentation pages.
12 #
13 # One way to use this:
14 # - run this script, saving the output to some temporary file
15 # - diff this output with the actual release notes page
16 # - the differences are Markdown text that can be pasted in to the
17 # appropriate documentation pages in the docs/ directory.
18 # - each release also has a github link to show which documentation files
19 # were changed in it.
20 # This can be helpful to see which documentation pages
21 # to add the 'Introduced in Catch ...' snippets to the relevant pages.
22 #
23
24 import re
25
26
27 def create_introduced_in_text(version, bug_number = None):
28 """Generate text to paste in to documentation file"""
29 if bug_number:
30 return '> [Introduced](https://github.com/catchorg/Catch2/issues/%s) in Catch %s.' % (bug_number, version)
31 else:
32 # Use this text for changes that don't have issue numbers
33 return '> Introduced in Catch %s.' % version
34
35
36 def link_to_changes_in_release(release, releases):
37 """
38 Markdown text for a hyperlink showing all edits in a release, or empty string
39
40 :param release: A release version, as a string
41 :param releases: A container of releases, in descending order - newest to oldest
42 :return: Markdown text for a hyperlink showing the differences between the give release and the prior one,
43 or empty string, if the previous release is not known
44 """
45
46 if release == releases[-1]:
47 # This is the earliest release we know about
48 return ''
49 index = releases.index(release)
50 previous_release = releases[index + 1]
51 return '\n[Changes in %s](https://github.com/catchorg/Catch2/compare/v%s...v%s)' % (release, previous_release, release)
52
53
54 def write_recent_release_notes_with_introduced_text():
55 current_version = None
56 release_toc_regex = r'\[(\d.\d.\d)\]\(#\d+\)<br>'
57 issue_number_regex = r'#[0-9]+'
58 releases = []
59 with open('../docs/release-notes.md') as release_notes:
60 for line in release_notes:
61 line = line[:-1]
62 print(line)
63
64 # Extract version number from table of contents
65 match = re.search(release_toc_regex, line)
66 if match:
67 release_name = match.group(1)
68 releases.append(release_name)
69
70 if line.startswith('## '):
71 # It's a section with version number
72 current_version = line.replace('## ', '')
73
74 # We decided not to add released-date info for older versions
75 if current_version == 'Older versions':
76 break
77
78 print(create_introduced_in_text(current_version))
79 print(link_to_changes_in_release(current_version, releases))
80
81 # Not yet found a version number, so to avoid picking up hyperlinks to
82 # version numbers in the index, keep going
83 if not current_version:
84 continue
85
86 for bug_link in re.findall(issue_number_regex, line):
87 bug_number = bug_link.replace('#', '')
88 print(create_introduced_in_text(current_version, bug_number))
89
90
91 if __name__ == '__main__':
92 write_recent_release_notes_with_introduced_text()