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

2017-07-17 Thread Yuya Nishihara
On Sun, 16 Jul 2017 11:58:28 -0400, Augie Fackler wrote:
> 
> > On Jul 16, 2017, at 10:30 AM, Yuya Nishihara  wrote:
> > 
> > On Sun, 16 Jul 2017 14:25:28 +0200, Rishabh Madan wrote:
> >> On Sun, Jul 16, 2017 at 2:20 PM, Rishabh Madan 
> >> wrote:
> >>> On Sat, Jul 15, 2017 at 4:13 AM, Yuya Nishihara  wrote:
>  On Sun, 09 Jul 2017 19:04:33 +0200, Rishabh Madan wrote:
> > # HG changeset patch
> > # User Rishabh Madan 
> > # Date 1499619850 -7200
> > #  Sun Jul 09 19:04:10 2017 +0200
> > # Node ID 5f22d3d43d36d46cea98c86b2a49eee2d323fd9e
> > # Parent  4672db164c986da4442bd864cd044512d975c3f2
> > releasenotes: add custom admonitions support for release notes
>  
>  Do you have time to make V4 in this weekend? If you don't, I'll queue 
>  this
>  version as it seems good enough.
>  
> >>> 
> >>> Really sorry. I am travelling back home so I guess I won't be able to
> >>> complete v4 by the weekend. I'll reach on Monday and I can submit the new
> >>> patch by then if it is okay.
> >> 
> >> Actually, I already have the patch for custom admonitions. But I was
> >> planning to send the similarity function patches along with it as a series.
> > 
> > Okay then, it's probably better to not take the current version. Thanks for
> > the status updates.
> 
> It’s also fine with me to keep iterating on this during the freeze, given 
> that it’s still experimental and I don’t want to take two weeks of 
> productivity away from a GSoC student.

+1
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2017-07-16 Thread Augie Fackler

> On Jul 16, 2017, at 10:30 AM, Yuya Nishihara  wrote:
> 
> On Sun, 16 Jul 2017 14:25:28 +0200, Rishabh Madan wrote:
>> On Sun, Jul 16, 2017 at 2:20 PM, Rishabh Madan 
>> wrote:
>>> On Sat, Jul 15, 2017 at 4:13 AM, Yuya Nishihara  wrote:
 On Sun, 09 Jul 2017 19:04:33 +0200, Rishabh Madan wrote:
> # HG changeset patch
> # User Rishabh Madan 
> # Date 1499619850 -7200
> #  Sun Jul 09 19:04:10 2017 +0200
> # Node ID 5f22d3d43d36d46cea98c86b2a49eee2d323fd9e
> # Parent  4672db164c986da4442bd864cd044512d975c3f2
> releasenotes: add custom admonitions support for release notes
 
 Do you have time to make V4 in this weekend? If you don't, I'll queue this
 version as it seems good enough.
 
>>> 
>>> Really sorry. I am travelling back home so I guess I won't be able to
>>> complete v4 by the weekend. I'll reach on Monday and I can submit the new
>>> patch by then if it is okay.
>> 
>> Actually, I already have the patch for custom admonitions. But I was
>> planning to send the similarity function patches along with it as a series.
> 
> Okay then, it's probably better to not take the current version. Thanks for
> the status updates.

It’s also fine with me to keep iterating on this during the freeze, given that 
it’s still experimental and I don’t want to take two weeks of productivity away 
from a GSoC student.

AF
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2017-07-16 Thread Yuya Nishihara
On Sun, 16 Jul 2017 14:25:28 +0200, Rishabh Madan wrote:
> On Sun, Jul 16, 2017 at 2:20 PM, Rishabh Madan 
> wrote:
> > On Sat, Jul 15, 2017 at 4:13 AM, Yuya Nishihara  wrote:
> >> On Sun, 09 Jul 2017 19:04:33 +0200, Rishabh Madan wrote:
> >> > # HG changeset patch
> >> > # User Rishabh Madan 
> >> > # Date 1499619850 -7200
> >> > #  Sun Jul 09 19:04:10 2017 +0200
> >> > # Node ID 5f22d3d43d36d46cea98c86b2a49eee2d323fd9e
> >> > # Parent  4672db164c986da4442bd864cd044512d975c3f2
> >> > releasenotes: add custom admonitions support for release notes
> >>
> >> Do you have time to make V4 in this weekend? If you don't, I'll queue this
> >> version as it seems good enough.
> >>
> >
> > Really sorry. I am travelling back home so I guess I won't be able to
> > complete v4 by the weekend. I'll reach on Monday and I can submit the new
> > patch by then if it is okay.
> 
> Actually, I already have the patch for custom admonitions. But I was
> planning to send the similarity function patches along with it as a series.

Okay then, it's probably better to not take the current version. Thanks for
the status updates.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2017-07-16 Thread Rishabh Madan
On Sun, Jul 16, 2017 at 2:20 PM, Rishabh Madan 
wrote:

> On Sat, Jul 15, 2017 at 4:13 AM, Yuya Nishihara  wrote:
>
>> On Sun, 09 Jul 2017 19:04:33 +0200, Rishabh Madan wrote:
>> > # HG changeset patch
>> > # User Rishabh Madan 
>> > # Date 1499619850 -7200
>> > #  Sun Jul 09 19:04:10 2017 +0200
>> > # Node ID 5f22d3d43d36d46cea98c86b2a49eee2d323fd9e
>> > # Parent  4672db164c986da4442bd864cd044512d975c3f2
>> > releasenotes: add custom admonitions support for release notes
>>
>> Do you have time to make V4 in this weekend? If you don't, I'll queue this
>> version as it seems good enough.
>>
>
> Really sorry. I am travelling back home so I guess I won't be able to
> complete v4 by the weekend. I'll reach on Monday and I can submit the new
> patch by then if it is okay.
> ᐧ
>

Actually, I already have the patch for custom admonitions. But I was
planning to send the similarity function patches along with it as a series.
ᐧ
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2017-07-16 Thread Rishabh Madan
On Sat, Jul 15, 2017 at 4:13 AM, Yuya Nishihara  wrote:

> On Sun, 09 Jul 2017 19:04:33 +0200, Rishabh Madan wrote:
> > # HG changeset patch
> > # User Rishabh Madan 
> > # Date 1499619850 -7200
> > #  Sun Jul 09 19:04:10 2017 +0200
> > # Node ID 5f22d3d43d36d46cea98c86b2a49eee2d323fd9e
> > # Parent  4672db164c986da4442bd864cd044512d975c3f2
> > releasenotes: add custom admonitions support for release notes
>
> Do you have time to make V4 in this weekend? If you don't, I'll queue this
> version as it seems good enough.
>

Really sorry. I am travelling back home so I guess I won't be able to
complete v4 by the weekend. I'll reach on Monday and I can submit the new
patch by then if it is okay.
ᐧ
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2017-07-14 Thread Yuya Nishihara
On Sun, 09 Jul 2017 19:04:33 +0200, Rishabh Madan wrote:
> # HG changeset patch
> # User Rishabh Madan 
> # Date 1499619850 -7200
> #  Sun Jul 09 19:04:10 2017 +0200
> # Node ID 5f22d3d43d36d46cea98c86b2a49eee2d323fd9e
> # Parent  4672db164c986da4442bd864cd044512d975c3f2
> releasenotes: add custom admonitions support for release notes

Do you have time to make V4 in this weekend? If you don't, I'll queue this
version as it seems good enough.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2017-07-12 Thread Rishabh Madan
>
> > @@ -111,9 +112,25 @@
> >  self.addnontitleditem(section, paragraphs)
> >
> >  class releasenotessections(object):
> > -def __init__(self, ui):
> > -# TODO support defining custom sections from config.
> > -self._sections = list(DEFAULT_SECTIONS)
> > +def __init__(self, ui, repo=None):
> > +if repo:
> > +custom_sections = getcustomadmonitions(repo)
> > +if custom_sections:
> > +self._sections = custom_sections
> > +for default_name, default_value in DEFAULT_SECTIONS:
> > +duplicate_key = False
> > +for name, value in custom_sections:
> > +if name == default_name:
> > +duplicate_key = True
> > +break
> > +if duplicate_key:
> > +continue
> > +else:
> > +self._sections.append((default_name,
> default_value))
> > +else:
> > +self._sections = list(DEFAULT_SECTIONS)
> > +else:
> > +self._sections = list(DEFAULT_SECTIONS)
>
> You can use a dict (or util.sortdict() if the order matters) to deduplicate
> items.
>
>   sections = dict(DEFAULT_SECTIONS)
>   sections.update(getcustomadmonitions(repo))
>   self._sections = list(sections.iteritems())
>
This is a really nice way to override dictionary. Thanks!

>
> > +def getcustomadmonitions(repo):
> > +custom_sections = list()
> > +ctx = repo['.']
> > +p = config.config()
> > +repo = ctx.repo()
> > +
> > +def read(f, sections=None, remap=None):
> > +if f in ctx:
> > +data = ctx[f].data()
> > +p.parse(f, data, sections, remap, read)
> > +sectiondict = p['sections']
> > +sectionlist = list()
> > +for key, value in sectiondict.iteritems():
> > +temp = (key, value)
> > +sectionlist.append(temp)
> > +return sectionlist
>
> Since read() is the callback to handle %include syntax, it should do just
> p.parse() and nothing else.
>
> > +else:
> > +return
>
> And probably better to raise an error if an %include file not found.
> subrepo.state() has a good example.
>
> > +if '.hgreleasenotes' in ctx:
> > +custom_sections = read('.hgreleasenotes')
> > +return custom_sections
>



-- 
Rishabh Madan
Second Year Undergraduate student
Indian Institute of Technology, Kharagpur
ᐧ
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2017-07-11 Thread Yuya Nishihara
On Tue, 11 Jul 2017 19:31:41 +0530, Pulkit Goyal wrote:
> > And probably better to raise an error if an %include file not found.
> > subrepo.state() has a good example.
> 
> IMO that will make it kind of necessary to have .hgadmonitions file,
> something which we should not enforce as some user might rely on the
> predefined sections.

It's for an %include file referenced explicitly by .hgadmonitions.
.hgadmonitions should stay as optional.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2017-07-11 Thread Pulkit Goyal
> And probably better to raise an error if an %include file not found.
> subrepo.state() has a good example.

IMO that will make it kind of necessary to have .hgadmonitions file,
something which we should not enforce as some user might rely on the
predefined sections.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2017-07-10 Thread Yuya Nishihara
On Sun, 09 Jul 2017 19:04:33 +0200, Rishabh Madan wrote:
> # HG changeset patch
> # User Rishabh Madan 
> # Date 1499619850 -7200
> #  Sun Jul 09 19:04:10 2017 +0200
> # Node ID 5f22d3d43d36d46cea98c86b2a49eee2d323fd9e
> # Parent  4672db164c986da4442bd864cd044512d975c3f2
> releasenotes: add custom admonitions support for release notes

Generally looks good. A couple of nits follow.

> --- a/hgext/releasenotes.py   Sat Jun 24 15:29:42 2017 -0700
> +++ b/hgext/releasenotes.py   Sun Jul 09 19:04:10 2017 +0200
> @@ -20,6 +20,7 @@
>  
>  from mercurial.i18n import _
>  from mercurial import (
> +config,
>  error,
>  minirst,
>  registrar,
> @@ -111,9 +112,25 @@
>  self.addnontitleditem(section, paragraphs)
>  
>  class releasenotessections(object):
> -def __init__(self, ui):
> -# TODO support defining custom sections from config.
> -self._sections = list(DEFAULT_SECTIONS)
> +def __init__(self, ui, repo=None):
> +if repo:
> +custom_sections = getcustomadmonitions(repo)
> +if custom_sections:
> +self._sections = custom_sections
> +for default_name, default_value in DEFAULT_SECTIONS:
> +duplicate_key = False
> +for name, value in custom_sections:
> +if name == default_name:
> +duplicate_key = True
> +break
> +if duplicate_key:
> +continue
> +else:
> +self._sections.append((default_name, default_value))
> +else:
> +self._sections = list(DEFAULT_SECTIONS)
> +else:
> +self._sections = list(DEFAULT_SECTIONS)

You can use a dict (or util.sortdict() if the order matters) to deduplicate
items.

  sections = dict(DEFAULT_SECTIONS)
  sections.update(getcustomadmonitions(repo))
  self._sections = list(sections.iteritems())

> +def getcustomadmonitions(repo):
> +custom_sections = list()
> +ctx = repo['.']
> +p = config.config()
> +repo = ctx.repo()
> +
> +def read(f, sections=None, remap=None):
> +if f in ctx:
> +data = ctx[f].data()
> +p.parse(f, data, sections, remap, read)
> +sectiondict = p['sections']
> +sectionlist = list()
> +for key, value in sectiondict.iteritems():
> +temp = (key, value)
> +sectionlist.append(temp)
> +return sectionlist

Since read() is the callback to handle %include syntax, it should do just
p.parse() and nothing else.

> +else:
> +return

And probably better to raise an error if an %include file not found.
subrepo.state() has a good example.

> +if '.hgreleasenotes' in ctx:
> +custom_sections = read('.hgreleasenotes')
> +return custom_sections
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2017-07-09 Thread Rishabh Madan
# HG changeset patch
# User Rishabh Madan 
# Date 1499619850 -7200
#  Sun Jul 09 19:04:10 2017 +0200
# Node ID 5f22d3d43d36d46cea98c86b2a49eee2d323fd9e
# Parent  4672db164c986da4442bd864cd044512d975c3f2
releasenotes: add custom admonitions support for release notes

By default, the extension has default sections like fix, feature, perf etc.. 
This
patch allow user to add support for custom admonition. In order to add a custom
admonition, one needs to have a .hgreleasenotes file inside the repository. All 
the
custom directive with name specified under the tag [sections] will be
usable by the extension. One important thing to keep in mind is if there exists 
any
custom admonitions with same key as default then they will override the default 
ones.

diff -r 4672db164c98 -r 5f22d3d43d36 hgext/releasenotes.py
--- a/hgext/releasenotes.py Sat Jun 24 15:29:42 2017 -0700
+++ b/hgext/releasenotes.py Sun Jul 09 19:04:10 2017 +0200
@@ -20,6 +20,7 @@
 
 from mercurial.i18n import _
 from mercurial import (
+config,
 error,
 minirst,
 registrar,
@@ -111,9 +112,25 @@
 self.addnontitleditem(section, paragraphs)
 
 class releasenotessections(object):
-def __init__(self, ui):
-# TODO support defining custom sections from config.
-self._sections = list(DEFAULT_SECTIONS)
+def __init__(self, ui, repo=None):
+if repo:
+custom_sections = getcustomadmonitions(repo)
+if custom_sections:
+self._sections = custom_sections
+for default_name, default_value in DEFAULT_SECTIONS:
+duplicate_key = False
+for name, value in custom_sections:
+if name == default_name:
+duplicate_key = True
+break
+if duplicate_key:
+continue
+else:
+self._sections.append((default_name, default_value))
+else:
+self._sections = list(DEFAULT_SECTIONS)
+else:
+self._sections = list(DEFAULT_SECTIONS)
 
 def __iter__(self):
 return iter(self._sections)
@@ -128,6 +145,29 @@
 
 return None
 
+def getcustomadmonitions(repo):
+custom_sections = list()
+ctx = repo['.']
+p = config.config()
+repo = ctx.repo()
+
+def read(f, sections=None, remap=None):
+if f in ctx:
+data = ctx[f].data()
+p.parse(f, data, sections, remap, read)
+sectiondict = p['sections']
+sectionlist = list()
+for key, value in sectiondict.iteritems():
+temp = (key, value)
+sectionlist.append(temp)
+return sectionlist
+else:
+return
+
+if '.hgreleasenotes' in ctx:
+custom_sections = read('.hgreleasenotes')
+return custom_sections
+
 def parsenotesfromrevisions(repo, directives, revs):
 notes = parsedreleasenotes()
 
@@ -311,7 +351,6 @@
 lines.extend(wrapper.wrap(' '.join(para)))
 
 lines.append('')
-
 if lines[-1]:
 lines.append('')
 
@@ -396,7 +435,7 @@
 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)
+sections = releasenotessections(ui, repo)
 
 revs = scmutil.revrange(repo, [rev or 'not public()'])
 incoming = parsenotesfromrevisions(repo, sections.names(), revs)
@@ -411,12 +450,11 @@
 notes = parsedreleasenotes()
 
 notes.merge(ui, incoming)
-
 with open(file_, 'wb') as fh:
 fh.write(serializenotes(sections, notes))
 
 @command('debugparsereleasenotes', norepo=True)
-def debugparsereleasenotes(ui, path):
+def debugparsereleasenotes(ui, path, repo=None):
 """parse release notes and print resulting data structure"""
 if path == '-':
 text = sys.stdin.read()
@@ -424,7 +462,7 @@
 with open(path, 'rb') as fh:
 text = fh.read()
 
-sections = releasenotessections(ui)
+sections = releasenotessections(ui, repo)
 
 notes = parsereleasenotesfile(sections, text)
 
diff -r 4672db164c98 -r 5f22d3d43d36 tests/test-releasenotes-formatting.t
--- a/tests/test-releasenotes-formatting.t  Sat Jun 24 15:29:42 2017 -0700
+++ b/tests/test-releasenotes-formatting.t  Sun Jul 09 19:04:10 2017 +0200
@@ -255,6 +255,8 @@
   
   * Short summary of fix 3
 
+  $ cd ..
+
 Multiple 'Other Changes' sub-sections for every section
 
   $ hg init multiple-otherchanges
@@ -324,3 +326,52 @@
   
   * Short summary of fix 2
 
+  $ cd ..
+
+Using custom sections in notes
+
+  $ hg init custom-section
+  $ cd custom-section
+  $ cat >> .hgreleasenotes << EOF
+  > [sections]
+  > testsection=Name of Section
+  > EOF
+
+  $ touch a
+  $ hg -q commit -A -l - << EOF
+  > commit