Mercurial > piecrust2
annotate garcon/changelog.py @ 890:f77f9dcba072
serve: Optionally run the admin panel with the server.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 02 Jul 2017 22:15:47 -0700 |
parents | be8b233cc69a |
children | 22cf13b86cc3 68f799dc4680 |
rev | line source |
---|---|
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import os |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import os.path |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 import re |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 import time |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 import argparse |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 import subprocess |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 hg_log_template = ("{if(tags, '>>{tags};{date|shortdate}\n')}" |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 "{desc|firstline}\n\n") |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 re_tag = re.compile('^\d+\.\d+\.\d+([ab]\d+)?(rc\d+)?$') |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 re_change = re.compile('^(\w+):') |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 re_clean_code_span = re.compile('([^\s])``([^\s]+)') |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 category_commands = [ |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 'chef', 'bake', 'find', 'help', 'import', 'init', 'paths', 'plugin', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 'plugins', 'prepare', 'purge', 'root', 'routes', 'serve', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 'showconfig', 'showrecord', 'sources', 'theme', 'themes', 'admin', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 'publish'] |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 category_core = [ |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
22 'internal', 'templating', 'formatting', 'performance', |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 'data', 'config', 'rendering', 'render', 'debug', 'reporting', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 'linker', 'pagination', 'routing', 'caching', 'cli'] |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
25 category_bugfixes = [ |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
26 'bug'] |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 category_project = ['build', 'cm', 'docs', 'tests', 'setup'] |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 categories = [ |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 ('commands', category_commands), |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 ('core', category_core), |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
31 ('bugfixes', category_bugfixes), |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 ('project', category_project), |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 ('miscellaneous', None)] |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 category_names = list(map(lambda i: i[0], categories)) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
36 re_add_tag_changeset = re.compile('^Added tag [^\s]+ for changeset [\w\d]+$') |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
37 re_merge_pr_changeset = re.compile('^Merge pull request') |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
38 re_merge_changes_changeset = re.compile('^Merge(d?) changes') |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
39 message_blacklist = [ |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
40 re_add_tag_changeset, |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
41 re_merge_pr_changeset, |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
42 re_merge_changes_changeset] |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
43 |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
44 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
45 def generate(out_file, last=None): |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
46 print("Generating %s" % out_file) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
47 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
48 if not os.path.exists('.hg'): |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
49 raise Exception("You must run this script from the root of a " |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
50 "Mercurial clone of the PieCrust repository.") |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
51 hglog = subprocess.check_output([ |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
52 'hg', 'log', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
53 '--rev', 'reverse(::master)', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
54 '--template', hg_log_template]) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 hglog = hglog.decode('utf8') |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 |
740
3ab6f7a3a2c7
cm: Add generation of Mardown changelog suitable for the online documentation.
Ludovic Chabant <ludovic@chabant.com>
parents:
649
diff
changeset
|
57 _, out_ext = os.path.splitext(out_file) |
3ab6f7a3a2c7
cm: Add generation of Mardown changelog suitable for the online documentation.
Ludovic Chabant <ludovic@chabant.com>
parents:
649
diff
changeset
|
58 templates = _get_templates(out_ext) |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 |
649
e6d9eed35c8e
cm: Fix CHANGELOG newlines on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
642
diff
changeset
|
60 with open(out_file, 'w', encoding='utf8', newline='') as fp: |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
61 fp.write(templates['header']) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
62 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
63 skip = False |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
64 in_desc = False |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
65 current_version = 0 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
66 current_version_info = None |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
67 current_changes = None |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
68 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
69 if last: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
70 current_version = 1 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
71 cur_date = time.strftime('%Y-%m-%d') |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
72 current_version_info = last, cur_date |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
73 current_changes = {} |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
74 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
75 for line in hglog.splitlines(): |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
76 if line == '': |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
77 skip = False |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
78 in_desc = False |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
79 continue |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
80 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
81 if not in_desc and line.startswith('>>'): |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
82 tags, tag_date = line[2:].split(';') |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
83 if re_tag.match(tags): |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
84 if current_version > 0: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
85 _write_version_changes( |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
86 templates, |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
87 current_version, current_version_info, |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
88 current_changes, fp, out_ext) |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
89 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
90 current_version += 1 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
91 current_version_info = tags, tag_date |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
92 current_changes = {} |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
93 in_desc = True |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
94 else: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
95 skip = True |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
96 continue |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
97 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
98 if skip or current_version == 0: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
99 continue |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
100 |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
101 for blre in message_blacklist: |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
102 if blre.match(line): |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
103 skip = True |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
104 break |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
105 |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
106 if skip: |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
107 continue |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
108 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
109 m = re_change.match(line) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
110 if m: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
111 ch_type = m.group(1) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
112 for cat_name, ch_types in categories: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
113 if ch_types is None or ch_type in ch_types: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
114 msgs = current_changes.setdefault(cat_name, []) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
115 msgs.append(line) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
116 break |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
117 else: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
118 assert False, ("Change '%s' should have gone in the " |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
119 "misc. bucket." % line) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
120 else: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
121 msgs = current_changes.setdefault('miscellaneous', []) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
122 msgs.append(line) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
123 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
124 if current_version > 0: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
125 _write_version_changes( |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
126 templates, |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
127 current_version, current_version_info, |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
128 current_changes, fp, out_ext) |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
129 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
130 |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
131 def _write_version_changes(templates, version, version_info, changes, fp, ext): |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
132 tokens = { |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
133 'num': str(version), |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
134 'version': version_info[0], |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
135 'date': version_info[1]} |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
136 tpl = _multi_replace(templates['version_title'], tokens) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
137 fp.write(tpl) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
138 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
139 for i, cat_name in enumerate(category_names): |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
140 msgs = changes.get(cat_name) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
141 if not msgs: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
142 continue |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
143 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
144 tokens = { |
740
3ab6f7a3a2c7
cm: Add generation of Mardown changelog suitable for the online documentation.
Ludovic Chabant <ludovic@chabant.com>
parents:
649
diff
changeset
|
145 'num': str(version), |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
146 'sub_num': str(i), |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
147 'category': cat_name.title()} |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
148 tpl = _multi_replace(templates['category_title'], tokens) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
149 fp.write(tpl) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
150 |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
151 msgs = list(sorted(msgs)) |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
152 for msg in msgs: |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
153 if ext == '.rst': |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
154 msg = msg.replace('`', '``').rstrip('\n') |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
155 msg = re_clean_code_span.sub(r'\1`` \2', msg) |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
156 fp.write('* ' + msg + '\n') |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
157 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
158 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
159 def _multi_replace(s, tokens): |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
160 for token in tokens: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
161 s = s.replace('%%%s%%' % token, tokens[token]) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
162 return s |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
163 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
164 |
740
3ab6f7a3a2c7
cm: Add generation of Mardown changelog suitable for the online documentation.
Ludovic Chabant <ludovic@chabant.com>
parents:
649
diff
changeset
|
165 def _get_templates(extension): |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
166 tpl_dir = os.path.join(os.path.dirname(__file__), 'changelog') |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
167 tpls = {} |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
168 for name in os.listdir(tpl_dir): |
740
3ab6f7a3a2c7
cm: Add generation of Mardown changelog suitable for the online documentation.
Ludovic Chabant <ludovic@chabant.com>
parents:
649
diff
changeset
|
169 if name.endswith(extension): |
3ab6f7a3a2c7
cm: Add generation of Mardown changelog suitable for the online documentation.
Ludovic Chabant <ludovic@chabant.com>
parents:
649
diff
changeset
|
170 tpl = _get_template(os.path.join(tpl_dir, name)) |
3ab6f7a3a2c7
cm: Add generation of Mardown changelog suitable for the online documentation.
Ludovic Chabant <ludovic@chabant.com>
parents:
649
diff
changeset
|
171 name_no_ext, _ = os.path.splitext(name) |
3ab6f7a3a2c7
cm: Add generation of Mardown changelog suitable for the online documentation.
Ludovic Chabant <ludovic@chabant.com>
parents:
649
diff
changeset
|
172 tpls[name_no_ext] = tpl |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
173 return tpls |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
174 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
175 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
176 def _get_template(filename): |
649
e6d9eed35c8e
cm: Fix CHANGELOG newlines on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
642
diff
changeset
|
177 with open(filename, 'r', encoding='utf8', newline='') as fp: |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
178 return fp.read() |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
179 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
180 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
181 if __name__ == '__main__': |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
182 parser = argparse.ArgumentParser(description='Generate CHANGELOG file.') |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
183 parser.add_argument( |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
184 'out_file', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
185 nargs='?', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
186 default='CHANGELOG.rst', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
187 help='The output file.') |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
188 parser.add_argument( |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
189 '--last', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
190 help="The version for the last few untagged changes.") |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
191 args = parser.parse_args() |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
192 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
193 generate(args.out_file, last=args.last) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
194 else: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
195 from invoke import task |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
196 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
197 @task |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
198 def genchangelog(out_file='CHANGELOG.rst', last=None): |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
199 generate(out_file, last) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
200 |