[PATCH] releasenotes: add custom admonitions support for release notes

Yuya Nishihara yuya at tcha.org
Sun Jul 9 09:12:22 EDT 2017


On Fri, 07 Jul 2017 19:13:58 +0200, Rishabh Madan wrote:
> # HG changeset patch
> # User Rishabh Madan <rishabhmadan96 at gmail.com>
> # Date 1499447586 -7200
> #      Fri Jul 07 19:13:06 2017 +0200
> # Node ID 766932e4c2768577173f1bfaa10e919b9df739ec
> # Parent  e714159860fd0872ae0555bb07546aa7e9f700e0
> releasenotes: add custom admonitions support for release notes

>  class releasenotessections(object):
> -    def __init__(self, ui):
> -        # TODO support defining custom sections from config.
> -        self._sections = list(DEFAULT_SECTIONS)
> +    def __init__(self, repo, revs, ui):
> +        custom_sections = self.getcustomadmonitions(repo, revs, ui)
> +        if custom_sections:
> +            self._sections = custom_sections
> +        else:
> +            self._sections = list(DEFAULT_SECTIONS) + custom_sections
                                                         ^^^^^^^^^^^^^^^

Here custom_sections is empty, right?

> +    def getcustomadmonitions(self, repo, revs, ui):

Nit: this can be a free function since it doesn't depend on self.

> +        custom_sections = list()
> +        for rev in revs:
> +            ctx = repo[rev]

What do you want to do here? Processing all revs or just taking the last rev?

> +        p = config.config()
> +        repo = ctx.repo()
> +
> +        def read(f, sections=None, remap=None):
> +            if f in ctx:
> +                try:
> +                    data = ctx[f].data()
> +
> +                except IOError as err:
> +                    if err.errno != errno.ENOENT:
> +                        raise
> +                    ui.warn(_("warning: .hgadmonitions file \'%s\' not found\n") %
> +                            repo.pathto(f))
> +                    return
> +                p.parse(f, data, sections, remap, read)
> +                sectiondict = p.__getitem__(sections)
                                 ^^^^^^^^^^^^^^^^^^^^^^^
p[sections]

BTW, this sections should not be the same as the sections passed to parse().
Perhaps, you would just need to parse the all sections in config file, and
pick the one you want.

  p.parse(src, data)
  return p.items('releasenotes.sections')

> +                sectionlist = list()
> +                for key, value in sectiondict.iteritems():
> +                    temp = (key, value)
> +                    sectionlist.append(temp)
> +            else:
> +                raise error.Abort(_(".hgadmonitions file \'%s\' not found") %
> +                                  repo.pathto(f))
> +            return sectionlist
> +        if '.hgadmonitions' in ctx:
> +            custom_sections = read('.hgadmonitions', 'releasenotes.sections')

.hgadmonitions sounds too obscure. .hgreleasenotes is probably better, and
the section name could be just [sections] or [admonitions].

> +        return custom_sections
> +
>  def parsenotesfromrevisions(repo, directives, revs):
>      notes = parsedreleasenotes()
>  
> @@ -396,9 +432,9 @@
>      that file. A particular use case for this is to tweak the wording of a
>      release note after it has been added to the release notes file.
>      """
> -    sections = releasenotessections(ui)
> +    revs = scmutil.revrange(repo, [rev or 'not public()'])
>  
> -    revs = scmutil.revrange(repo, [rev or 'not public()'])
> +    sections = releasenotessections(repo, revs, ui)

I doubt it's correct to read all .hgadmonitions files. Maybe we would simply
want to use the latest config for the revision you're generating a release
note?

> -
> +    print(incoming)

:)

And, can you write some tests?


More information about the Mercurial-devel mailing list