Commits

Mike Bayer  committed f82268e

render "backports"/ "forward ports" automatically, only write out
changelog once

  • Participants
  • Parent commits 5a68954

Comments (0)

Files changed (4)

File doc/build/builder/changelog.py

     def env(self):
         return self.state.document.settings.env
 
+    @classmethod
+    def changes(cls, env):
+        return env.temp_data['ChangeLogDirective_changes']
+
 class ChangeLogDirective(EnvDirective, Directive):
     has_content = True
 
-    type_ = "change"
-
     default_section = 'misc'
 
     def _organize_by_section(self, changes):
         bysection = collections.defaultdict(list)
         all_sections = set()
         for rec in changes:
+            if self.version not in rec['versions']:
+                continue
             inner_tag = rec['tags'].intersection(self.inner_tag_sort)
             if inner_tag:
                 inner_tag = inner_tag.pop()
                     bysection[(self.default_section, inner_tag)].append(rec)
         return bysection, all_sections
 
-    @classmethod
-    def changes(cls, env):
-        return env.temp_data['ChangeLogDirective_%s_changes' % cls.type_]
-
     def _setup_run(self):
         self.sections = self.env.config.changelog_sections
         self.inner_tag_sort = self.env.config.changelog_inner_tag_sort + [""]
-        self.env.temp_data['ChangeLogDirective_%s_changes' % self.type_] = []
+        if 'ChangeLogDirective_changes' not in self.env.temp_data:
+            self.env.temp_data['ChangeLogDirective_changes'] = []
         self._parsed_content = _parse_content(self.content)
 
+        self.version = version = self._parsed_content.get('version', '')
+        self.env.temp_data['ChangeLogDirective_version'] = version
+
         p = nodes.paragraph('', '',)
         self.state.nested_parse(self.content[1:], 0, p)
 
     def run(self):
         self._setup_run()
+
+        if 'ChangeLogDirective_includes' in self.env.temp_data:
+            return []
+
         changes = self.changes(self.env)
         output = []
 
-        self.version = version = self._parsed_content.get('version', '')
-        id_prefix = "%s-%s" % (self.type_, version)
+        id_prefix = "change-%s" % (self.version, )
         topsection = self._run_top(id_prefix)
         output.append(topsection)
 
         text = _text_rawsource_from_node(para)
 
         to_hash = "%s %s" % (self.version, text[0:100])
-        targetid = "%s-%s" % (self.type_,
+        targetid = "change-%s" % (
                         md5.md5(to_hash.encode('ascii', 'ignore')
                             ).hexdigest())
         targetnode = nodes.target('', '', ids=[targetid])
                     )
         para.append(permalink)
 
+        if len(rec['versions']) > 1:
+
+            backported_changes = rec['sorted_versions'][rec['sorted_versions'].index(self.version) + 1:]
+            if backported_changes:
+                backported = nodes.paragraph('')
+                backported_text = "This change is also backported: %s" % (
+                        ", ".join(backported_changes))
+                backported.append(nodes.Text(backported_text, backported_text))
+                para.append(backported)
+
         insert_ticket = nodes.paragraph('')
         para.append(insert_ticket)
 
             )
         )
 
+class ChangeLogImportDirective(EnvDirective, Directive):
+    has_content = True
+
+    def _setup_run(self):
+        if 'ChangeLogDirective_changes' not in self.env.temp_data:
+            self.env.temp_data['ChangeLogDirective_changes'] = []
+
+    def run(self):
+        self._setup_run()
+
+        # tell ChangeLogDirective we're here, also prevent
+        # nested .. include calls
+        if 'ChangeLogDirective_includes' not in self.env.temp_data:
+            self.env.temp_data['ChangeLogDirective_includes'] = True
+            p = nodes.paragraph('', '',)
+            self.state.nested_parse(self.content, 0, p)
+            del self.env.temp_data['ChangeLogDirective_includes']
+
+        return []
 
 class ChangeDirective(EnvDirective, Directive):
     has_content = True
 
-    type_ = "change"
-    parent_cls = ChangeLogDirective
-
     def run(self):
         content = _parse_content(self.content)
         p = nodes.paragraph('', '',)
         sorted_tags = _comma_list(content.get('tags', ''))
+        declared_version = self.env.temp_data['ChangeLogDirective_version']
+        versions = set(_comma_list(content.get("versions", ""))).difference(['']).\
+                            union([declared_version])
+
+        def int_ver(ver):
+            out = []
+            for dig in ver.split("."):
+                try:
+                    out.append(int(dig))
+                except ValueError:
+                    out.append(0)
+            return tuple(out)
+
         rec = {
             'tags': set(sorted_tags).difference(['']),
             'tickets': set(_comma_list(content.get('tickets', ''))).difference(['']),
             'pullreq': set(_comma_list(content.get('pullreq', ''))).difference(['']),
             'changeset': set(_comma_list(content.get('changeset', ''))).difference(['']),
             'node': p,
-            'type': self.type_,
+            'type': "change",
             "title": content.get("title", None),
-            'sorted_tags': sorted_tags
+            'sorted_tags': sorted_tags,
+            "versions": versions,
+            "sorted_versions": list(reversed(sorted(versions, key=int_ver)))
         }
 
         if "declarative" in rec['tags']:
             rec['tags'].add("orm")
 
         self.state.nested_parse(content['text'], 0, p)
-        self.parent_cls.changes(self.env).append(rec)
+        ChangeLogDirective.changes(self.env).append(rec)
 
         return []
 
 def setup(app):
     app.add_directive('changelog', ChangeLogDirective)
     app.add_directive('change', ChangeDirective)
+    app.add_directive('changelog_imports', ChangeLogImportDirective)
     app.add_config_value("changelog_sections", [], 'env')
     app.add_config_value("changelog_inner_tag_sort", [], 'env')
     app.add_config_value("changelog_render_ticket",

File doc/build/changelog/changelog_07.rst

     .. change::
         :tags: bug, orm
         :tickets: 2807
+        :versions: 0.8.3, 0.9.0
 
         Fixed bug where list instrumentation would fail to represent a
         setslice of ``[0:0]`` correctly, which in particular could occur

File doc/build/changelog/changelog_08.rst

 0.8 Changelog
 ==============
 
+.. changelog_imports::
+
+    .. include:: changelog_07.rst
+
 .. changelog::
     :version: 0.8.3
 
     .. change::
         :tags: bug, orm
         :tickets: 2818
+        :versions: 0.9.0
 
         Fixed bug where :meth:`.Query.exists` failed to work correctly
         without any WHERE criterion.  Courtesy Vladimir Magamedov.
 
     .. change::
         :tags: bug, orm
-        :tickets: 2807
-
-        Fixed bug where list instrumentation would fail to represent a
-        setslice of ``[0:0]`` correctly, which in particular could occur
-        when using ``insert(0, item)`` with the association proxy.  Due
-        to some quirk in Python collections, the issue was much more likely
-        with Python 3 rather than 2.  Also in 0.7.11.
-
-    .. change::
-        :tags: bug, orm
         :tickets: 2779
 
         Backported a change from 0.9 whereby the iteration of a hierarchy

File doc/build/changelog/changelog_09.rst

 0.9 Changelog
 ==============
 
-.. changelog::
-    :version: 0.9.0
+.. changelog_imports::
 
-    .. change::
-        :tags: bug, orm
-        :tickets: 2818
+    .. include:: changelog_08.rst
 
-        Fixed bug where :meth:`.Query.exists` failed to work correctly
-        without any WHERE criterion.  Courtesy Vladimir Magamedov.
-        Also in 0.8.3.
+    .. include:: changelog_07.rst
+
+.. changelog::
+    :version: 0.9.0
 
     .. change::
         :tags: bug, sql
 
     .. change::
         :tags: bug, orm
-        :tickets: 2807
-
-        Fixed bug where list instrumentation would fail to represent a
-        setslice of ``[0:0]`` correctly, which in particular could occur
-        when using ``insert(0, item)`` with the association proxy.  Due
-        to some quirk in Python collections, the issue was much more likely
-        with Python 3 rather than 2.  Also in 0.8.3, 0.7.11.
-
-    .. change::
-        :tags: bug, orm
         :tickets: 2794
 
         Fixed a potential issue in an ordered sequence implementation used