Mercurial > piecrust2
annotate garcon/changelog.py @ 1051:971b4d67e82a
serve: Fix problems with assets disappearing between servings.
When an asset file changes, its source's pipeline is re-run. But that created
a bake record that only had that pipeline's output, so the other outputs were
incorrectly considered empty and therefore any stray files were removed. Now we
copy over bake records for the pipelines we don't run.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 26 Jan 2018 18:05:02 -0800 |
parents | 2e5c5d33d62c |
children |
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 |
1000
68f799dc4680
cm: Generate CHANGELOG from the current branch instead of always master. Fix encoding problems.
Ludovic Chabant <ludovic@chabant.com>
parents:
797
diff
changeset
|
5 import codecs |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 import argparse |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 import subprocess |
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 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 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
|
11 "{desc|firstline}\n\n") |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 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
|
14 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
|
15 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
|
16 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 category_commands = [ |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 '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
|
19 '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
|
20 '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
|
21 'publish'] |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 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
|
23 '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
|
24 '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
|
25 '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
|
26 category_bugfixes = [ |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
27 'bug'] |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 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
|
29 categories = [ |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 ('commands', category_commands), |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 ('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
|
32 ('bugfixes', category_bugfixes), |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 ('project', category_project), |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 ('miscellaneous', None)] |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 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
|
36 |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
37 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
|
38 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
|
39 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
|
40 message_blacklist = [ |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
41 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
|
42 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
|
43 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
|
44 |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
45 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
46 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
|
47 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
|
48 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
49 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
|
50 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
|
51 "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
|
52 hglog = subprocess.check_output([ |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
53 'hg', 'log', |
1000
68f799dc4680
cm: Generate CHANGELOG from the current branch instead of always master. Fix encoding problems.
Ludovic Chabant <ludovic@chabant.com>
parents:
797
diff
changeset
|
54 '--rev', 'reverse(::.)', |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 '--template', hg_log_template]) |
1000
68f799dc4680
cm: Generate CHANGELOG from the current branch instead of always master. Fix encoding problems.
Ludovic Chabant <ludovic@chabant.com>
parents:
797
diff
changeset
|
56 hglog = codecs.decode(hglog, encoding='utf-8', errors='replace') |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
57 |
740
3ab6f7a3a2c7
cm: Add generation of Mardown changelog suitable for the online documentation.
Ludovic Chabant <ludovic@chabant.com>
parents:
649
diff
changeset
|
58 _, 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
|
59 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
|
60 |
649
e6d9eed35c8e
cm: Fix CHANGELOG newlines on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
642
diff
changeset
|
61 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
|
62 fp.write(templates['header']) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
63 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
64 skip = False |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
65 in_desc = False |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
66 current_version = 0 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
67 current_version_info = None |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
68 current_changes = None |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
69 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
70 if last: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
71 current_version = 1 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
72 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
|
73 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
|
74 current_changes = {} |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
75 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
76 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
|
77 if line == '': |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
78 skip = False |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
79 in_desc = False |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
80 continue |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
81 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 if current_version > 0: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
86 _write_version_changes( |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
87 templates, |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
88 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
|
89 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
|
90 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
91 current_version += 1 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
92 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
|
93 current_changes = {} |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
94 in_desc = True |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
95 else: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
96 skip = True |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
97 continue |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
98 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
99 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
|
100 continue |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
101 |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
102 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
|
103 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
|
104 skip = True |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
105 break |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
106 |
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
107 if skip: |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
108 continue |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
109 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
110 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
|
111 if m: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 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
|
116 msgs.append(line) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
117 break |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
118 else: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
119 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
|
120 "misc. bucket." % line) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
121 else: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
122 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
|
123 msgs.append(line) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
124 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
125 if current_version > 0: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
126 _write_version_changes( |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
127 templates, |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
128 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
|
129 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
|
130 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
131 |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
132 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
|
133 tokens = { |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
134 'num': str(version), |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
135 'version': version_info[0], |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
136 'date': version_info[1]} |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
137 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
|
138 fp.write(tpl) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
139 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
140 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
|
141 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
|
142 if not msgs: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
143 continue |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
144 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
145 tokens = { |
740
3ab6f7a3a2c7
cm: Add generation of Mardown changelog suitable for the online documentation.
Ludovic Chabant <ludovic@chabant.com>
parents:
649
diff
changeset
|
146 'num': str(version), |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
147 'sub_num': str(i), |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
148 'category': cat_name.title()} |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
149 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
|
150 fp.write(tpl) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
151 |
797
be8b233cc69a
cm: Add a "Bugfixes" section to the CHANGELOG and order things alphabetically.
Ludovic Chabant <ludovic@chabant.com>
parents:
740
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 fp.write('* ' + msg + '\n') |
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 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
160 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
|
161 for token in tokens: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
162 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
|
163 return s |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
164 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
165 |
740
3ab6f7a3a2c7
cm: Add generation of Mardown changelog suitable for the online documentation.
Ludovic Chabant <ludovic@chabant.com>
parents:
649
diff
changeset
|
166 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
|
167 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
|
168 tpls = {} |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 return tpls |
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 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
177 def _get_template(filename): |
649
e6d9eed35c8e
cm: Fix CHANGELOG newlines on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
642
diff
changeset
|
178 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
|
179 return fp.read() |
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 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
182 if __name__ == '__main__': |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
183 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
|
184 parser.add_argument( |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
185 'out_file', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
186 nargs='?', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
187 default='CHANGELOG.rst', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
188 help='The output file.') |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
189 parser.add_argument( |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
190 '--last', |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
191 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
|
192 args = parser.parse_args() |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
193 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
194 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
|
195 else: |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
196 from invoke import task |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
197 |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
198 @task |
990
22cf13b86cc3
cm: Upgrade Garcon tasks to the latest PyInvoke version.
Ludovic Chabant <ludovic@chabant.com>
parents:
797
diff
changeset
|
199 def genchangelog(ctx, out_file='CHANGELOG.rst', last=None): |
642
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
200 generate(out_file, last) |
79aefe82c6b6
cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
201 |