Patchwork [2/3] package_ipk.bbclass: make DESCRIPTION support newline

login
register
mail settings
Submitter Robert Yang
Date June 19, 2013, 9 a.m.
Message ID <5bc169404eddb0ec90ce82c6013432f295d0cdc3.1371621343.git.liezhi.yang@windriver.com>
Download mbox | patch
Permalink /patch/51979/
State New
Headers show

Comments

Robert Yang - June 19, 2013, 9 a.m.
The recipe's DESCRIPTION is wrapped automatically by textwrap, make it
support newline ("\n") to let the user can wrap it manually, e.g.:

DESCRIPTION = "Foo1\nFoo2"

In the past, it would be:
Foo1\nFoo2

Now:
Foo1
Foo2

[YOCTO #4348]

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 meta/classes/package_ipk.bbclass |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Martin Jansa - June 19, 2013, 9:29 a.m.
On Wed, Jun 19, 2013 at 05:00:40AM -0400, Robert Yang wrote:
> The recipe's DESCRIPTION is wrapped automatically by textwrap, make it
> support newline ("\n") to let the user can wrap it manually, e.g.:
> 
> DESCRIPTION = "Foo1\nFoo2"
> 
> In the past, it would be:
> Foo1\nFoo2
> 
> Now:
> Foo1
> Foo2
> 
> [YOCTO #4348]
> 
> Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
> ---
>  meta/classes/package_ipk.bbclass |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/classes/package_ipk.bbclass b/meta/classes/package_ipk.bbclass
> index 55628e4..e67f641 100644
> --- a/meta/classes/package_ipk.bbclass
> +++ b/meta/classes/package_ipk.bbclass
> @@ -304,10 +304,11 @@ python do_package_ipk () {
>                  # Special behavior for description...
>                  if 'DESCRIPTION' in fs:
>                      summary = localdata.getVar('SUMMARY', True) or localdata.getVar('DESCRIPTION', True) or "."
> +                    ctrlfile.write('Description: %s\n' % summary)
>                      description = localdata.getVar('DESCRIPTION', True) or "."
>                      description = textwrap.dedent(description).strip()
> -                    ctrlfile.write('Description: %s\n' % summary)
> -                    ctrlfile.write('%s\n' % textwrap.fill(description, width=74, initial_indent=' ', subsequent_indent=' '))
> +                    for t in description.split('\\n'):
> +                        ctrlfile.write('%s\n' % textwrap.fill(t, width=74, initial_indent=' ', subsequent_indent=' '))
>                  else:

Isn't DESCRIPTION supposed to be short oneline and longer multiline only
in SUMMARY?

is opkg-utils (package-index) working with this? Newlines in SUMMARY
were causing incorrect parsing and not using cache IIRC, not sure if the
fix for that was generic enough to cover DESCRIPTION.
Richard Purdie - June 19, 2013, 9:49 a.m.
On Wed, 2013-06-19 at 11:29 +0200, Martin Jansa wrote:
> On Wed, Jun 19, 2013 at 05:00:40AM -0400, Robert Yang wrote:
> > The recipe's DESCRIPTION is wrapped automatically by textwrap, make it
> > support newline ("\n") to let the user can wrap it manually, e.g.:
> > 
> > DESCRIPTION = "Foo1\nFoo2"
> > 
> > In the past, it would be:
> > Foo1\nFoo2
> > 
> > Now:
> > Foo1
> > Foo2
> > 
> > [YOCTO #4348]
> > 
> > Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
> > ---
> >  meta/classes/package_ipk.bbclass |    5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/meta/classes/package_ipk.bbclass b/meta/classes/package_ipk.bbclass
> > index 55628e4..e67f641 100644
> > --- a/meta/classes/package_ipk.bbclass
> > +++ b/meta/classes/package_ipk.bbclass
> > @@ -304,10 +304,11 @@ python do_package_ipk () {
> >                  # Special behavior for description...
> >                  if 'DESCRIPTION' in fs:
> >                      summary = localdata.getVar('SUMMARY', True) or localdata.getVar('DESCRIPTION', True) or "."
> > +                    ctrlfile.write('Description: %s\n' % summary)
> >                      description = localdata.getVar('DESCRIPTION', True) or "."
> >                      description = textwrap.dedent(description).strip()
> > -                    ctrlfile.write('Description: %s\n' % summary)
> > -                    ctrlfile.write('%s\n' % textwrap.fill(description, width=74, initial_indent=' ', subsequent_indent=' '))
> > +                    for t in description.split('\\n'):
> > +                        ctrlfile.write('%s\n' % textwrap.fill(t, width=74, initial_indent=' ', subsequent_indent=' '))
> >                  else:
> 
> Isn't DESCRIPTION supposed to be short oneline and longer multiline only
> in SUMMARY?

No, SUMMARY is meant to be the short oneline and DESCRIPTION is the
multiline one afaik...

Cheers,

Richard

> is opkg-utils (package-index) working with this? Newlines in SUMMARY
> were causing incorrect parsing and not using cache IIRC, not sure if the
> fix for that was generic enough to cover DESCRIPTION.
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core@lists.openembedded.org
> http://lists.openembedded.org/mailman/listinfo/openembedded-core
Phil Blundell - June 19, 2013, 10:10 a.m.
On Wed, 2013-06-19 at 11:29 +0200, Martin Jansa wrote:
> On Wed, Jun 19, 2013 at 05:00:40AM -0400, Robert Yang wrote:
> > The recipe's DESCRIPTION is wrapped automatically by textwrap, make it
> > support newline ("\n") to let the user can wrap it manually, e.g.:
> > 
> > DESCRIPTION = "Foo1\nFoo2"
> > 
> > In the past, it would be:
> > Foo1\nFoo2
> > 
> > Now:
> > Foo1
> > Foo2
> > 
> > [YOCTO #4348]
> > 
> > Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
> > ---
> >  meta/classes/package_ipk.bbclass |    5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/meta/classes/package_ipk.bbclass b/meta/classes/package_ipk.bbclass
> > index 55628e4..e67f641 100644
> > --- a/meta/classes/package_ipk.bbclass
> > +++ b/meta/classes/package_ipk.bbclass
> > @@ -304,10 +304,11 @@ python do_package_ipk () {
> >                  # Special behavior for description...
> >                  if 'DESCRIPTION' in fs:
> >                      summary = localdata.getVar('SUMMARY', True) or localdata.getVar('DESCRIPTION', True) or "."
> > +                    ctrlfile.write('Description: %s\n' % summary)
> >                      description = localdata.getVar('DESCRIPTION', True) or "."
> >                      description = textwrap.dedent(description).strip()
> > -                    ctrlfile.write('Description: %s\n' % summary)
> > -                    ctrlfile.write('%s\n' % textwrap.fill(description, width=74, initial_indent=' ', subsequent_indent=' '))
> > +                    for t in description.split('\\n'):
> > +                        ctrlfile.write('%s\n' % textwrap.fill(t, width=74, initial_indent=' ', subsequent_indent=' '))
> >                  else:
> 
> Isn't DESCRIPTION supposed to be short oneline and longer multiline only
> in SUMMARY?

No, the reverse.  SUMMARY is (as the name suggests, and as the existing
code implements) meant to be the short synopsis and DESCRIPTION is the
longer text. 

> is opkg-utils (package-index) working with this? Newlines in SUMMARY
> were causing incorrect parsing and not using cache IIRC, not sure if the
> fix for that was generic enough to cover DESCRIPTION.

Newlines in SUMMARY would indeed break opkg-utils because the text after
the line break wouldn't be correctly indented.  It wouldn't be a bad
thing for package_ipk to check for that, but this shouldn't be an issue
with the patch above since it seems to be explicitly indenting all lines
of the long description.

I'm not entirely thrilled with Robert's patch because it seems rather
ugly to have embedded "\n" sequences in the recipe DESCRIPTION fields,
and also because package_ipk isn't the only consumer of that variable
and it isn't entirely obvious that all the other users will know what to
do.  But, absent a way to express string literals with embedded newlines
in bitbake, perhaps this is indeed the best compromise.

p.
Enrico Scholz - June 19, 2013, 10:33 a.m.
Robert Yang <liezhi.yang-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
writes:

> The recipe's DESCRIPTION is wrapped automatically by textwrap, make it
> support newline ("\n") to let the user can wrap it manually, e.g.:
>
> -                    ctrlfile.write('Description: %s\n' % summary)
> -                    ctrlfile.write('%s\n' % textwrap.fill(description, width=74, initial_indent=' ', subsequent_indent=' '))
> +                    for t in description.split('\\n'):
> +                        ctrlfile.write('%s\n' % textwrap.fill(t, width=74, initial_indent=' ', subsequent_indent=' '))

When user wrapped lines manually, why is textwrap.fill() called on the
lines again?  E.g. when user wrapped manually at 78 columns, this will
create long - short - long - short lines (in german, why call this
effect "Kammquoting" (comb quoting)) .

I suggest to avoid textwrap.fill() when text contains '\n'.



Enrico
Robert Yang - June 28, 2013, 3:21 a.m.
Sorry, it's only replied to Enrico, now, reply to the list ...

On 06/19/2013 06:33 PM, Enrico Scholz wrote:
>
>
> Robert Yang <liezhi.yang-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
> writes:
>
>> The recipe's DESCRIPTION is wrapped automatically by textwrap, make it
>> support newline ("\n") to let the user can wrap it manually, e.g.:
>>
>> -                    ctrlfile.write('Description: %s\n' % summary)
>> -                    ctrlfile.write('%s\n' % textwrap.fill(description, width=74, initial_indent=' ', subsequent_indent=' '))
>> +                    for t in description.split('\\n'):
>> +                        ctrlfile.write('%s\n' % textwrap.fill(t, width=74, initial_indent=' ', subsequent_indent=' '))
>
> When user wrapped lines manually, why is textwrap.fill() called on the
> lines again?  E.g. when user wrapped manually at 78 columns, this will
> create long - short - long - short lines (in german, why call this
> effect "Kammquoting" (comb quoting)) .
>
> I suggest to avoid textwrap.fill() when text contains '\n'.
>

Because I think that the "\n" is mainly used for splitting paragraph,
so the auto wrap is still useful when there is a "\n", e.g.:

DESCRIPTION = "FOO \n<Too many characters>"

The ouput is:
  FOO
  <74 characters>
  <74 characters>
  [snip]

I think that this is better than:
  FOO
  <Too many characters>

// Robert

>
>
> Enrico
>
>
>

Patch

diff --git a/meta/classes/package_ipk.bbclass b/meta/classes/package_ipk.bbclass
index 55628e4..e67f641 100644
--- a/meta/classes/package_ipk.bbclass
+++ b/meta/classes/package_ipk.bbclass
@@ -304,10 +304,11 @@  python do_package_ipk () {
                 # Special behavior for description...
                 if 'DESCRIPTION' in fs:
                     summary = localdata.getVar('SUMMARY', True) or localdata.getVar('DESCRIPTION', True) or "."
+                    ctrlfile.write('Description: %s\n' % summary)
                     description = localdata.getVar('DESCRIPTION', True) or "."
                     description = textwrap.dedent(description).strip()
-                    ctrlfile.write('Description: %s\n' % summary)
-                    ctrlfile.write('%s\n' % textwrap.fill(description, width=74, initial_indent=' ', subsequent_indent=' '))
+                    for t in description.split('\\n'):
+                        ctrlfile.write('%s\n' % textwrap.fill(t, width=74, initial_indent=' ', subsequent_indent=' '))
                 else:
                     ctrlfile.write(c % tuple(pullData(fs, localdata)))
         except KeyError: