Description looks very ugly in snap.yaml

Bug #1804258 reported by Gustavo Niemeyer
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snapcraft
Status tracked in Trunk
Legacy
Fix Committed
High
Sergio Schvezov
Trunk
Fix Released
High
Sergio Schvezov

Bug Description

Multi-line strings are being marshaled in a very poor way by snapcraft. For example, from blender:

description: "Blender is the free and open source 3D creation suite. It supports the\n\
  entirety of the 3D pipeline\u2014modeling, rigging, animation, simulation,\nrendering,\
  \ compositing and motion tracking, even video editing and game\ncreation.\n\nBlender\
  \ is a public project, made by hundreds of people from around the\nworld; by studios\
  \ and individual artists, professionals and hobbyists,\nscientists, students, VFX\
  \ experts, animators, game artists, modders, and\nthe list goes on.\n\nThe standard\
  \ snap channels are used in the following way:\n \n stable - Latest stable\
  \ release.\n candidate - Test builds for the upcoming stable release.\n \
  \ beta - Latest builds for the upcoming stable release.\n edge - Experimental\
  \ builds for the next major release.\n\nSee the following topic for details and\
  \ feedback on this snap:\n\n https://forum.snapcraft.io/t/blender-snap/1382\n"

I've also heard from Sergio that snapcraft is now using ">" somehow, which is almost certainly not the right thing to do given its manipulation of the string. For example:

>>> yaml.load(""">
... One
...
... Two
...
...
... Three
... """)
'One\nTwo\n\nThree\n'

The latter seems unrelated to the former, although Sergio mentioned it in the same conversation. But both issues should be looked into.

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

Can I see the original snapcraft.yaml that generates this ugly output?

As a side note, the switch from | to > was done on https://github.com/snapcore/snapcraft/commit/4e46b5a18f222d1f4e3084d642633e6d25bbd3bd and the reasoning from the store team was to allow for better formatting from the store web front (having the exact opposite effect of what you describe in this bug's description).

snapcraft is only using > when running snapcraft init and we can switch back to | without affecting any existing project.

That said, I do not think this is the reason for that not so nice looking (to not say horrible) output.

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

I can certainly provide it, but I'm curious about why do you think that matters. This comes from a YAML file which has this string under a multi-line description. This is loaded by snapcraft, and then marshaled by Snapcraft itself, which is a process completely independent and unrelated to the source YAML.

About ">", I still don't understand the use case. Can you point me to a thread where this was discussed? The > corrupts the input from the source, making it not match the formatting that was applied by the author, as I demonstrated above with actual code. This is clearly not desirable.

Revision history for this message
John Lenton (chipaca) wrote : Re: [Bug 1804258] Re: Description looks very ugly in snap.yaml

https://forum.snapcraft.io/t/snap-multi-line-descriptions-need-newline-trim-on-store-import/3934
On Wed, 21 Nov 2018 at 12:40, Gustavo Niemeyer <email address hidden> wrote:
>
> I can certainly provide it, but I'm curious about why do you think that
> matters. This comes from a YAML file which has this string under a
> multi-line description. This is loaded by snapcraft, and then marshaled
> by Snapcraft itself, which is a process completely independent and
> unrelated to the source YAML.
>
> About ">", I still don't understand the use case. Can you point me to a
> thread where this was discussed? The > corrupts the input from the
> source, making it not match the formatting that was applied by the
> author, as I demonstrated above with actual code. This is clearly not
> desirable.
>
> --
> You received this bug notification because you are a member of Snappy
> Developers, which is subscribed to Snapcraft.
> https://bugs.launchpad.net/bugs/1804258
>
> Title:
> Description looks very ugly in snap.yaml
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/snapcraft/+bug/1804258/+subscriptions

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Replied there.

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

I ask because I do not see that output with current behavior (video https://asciinema.org/a/QCmVfv9WDxtWybs9uNciBQkqF). From,
$ cat snap/snapcraft.yaml
name: my-snap-name # you probably want to 'snapcraft register <name>'
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: Single-line elevator pitch for your amazing snap # 79 char long summary
description: |
  This is my-snap's description. You have a paragraph or two to tell the
  most important story about your snap. Keep it under 100 words though,
  we live in tweetspace and your description wants to look good in the snap
  store.

  line 1

  line 2

    line 3

  line4.1
  line4.2

  - bullet 1
  - bullet 2
grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots
base: core18

parts:
  my-part:
    # See 'snapcraft plugins'
    plugin: nil

I get,
$ cat prime/meta/snap.yaml
name: my-snap-name
version: '0.1'
summary: Single-line elevator pitch for your amazing snap
description: |
  This is my-snap's description. You have a paragraph or two to tell the
  most important story about your snap. Keep it under 100 words though,
  we live in tweetspace and your description wants to look good in the snap
  store.

  line 1

  line 2

    line 3

  line4.1
  line4.2

  - bullet 1
  - bullet 2
architectures:
- amd64
base: core18
confinement: devmode
grade: devel

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

The store has plenty of examples of that, and this behavior is still visible with the current stable.

$ cat /snap/gnome-calculator/current/meta/snap.yaml | grep description
description: "GNOME Calculator is an application that solves mathematical equations.\n\

$ cat /snap/gnome-calculator/current/snap/snapcraft.yaml | grep description
description: |

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

Use of unicode characters in the description is triggering the bad formatting (both blender and the gnome example given are using unicode)

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

After
(snapcraft) ubuntu@snapcraft-xenial-dev:~/source/snapcraft$ git diff
diff --git a/snapcraft/yaml_utils.py b/snapcraft/yaml_utils.py
index 7aa771f..e2aab3f 100644
--- a/snapcraft/yaml_utils.py
+++ b/snapcraft/yaml_utils.py
@@ -34,7 +34,7 @@ def load(stream: TextIO) -> Any:

 def dump(data: Union[Dict[str, Any], yaml.YAMLObject], *, stream: TextIO = None) -> str:
     """Safely dump YAML in ordered manner."""
- return yaml.dump(data, stream, _SafeOrderedDumper, default_flow_style=False)
+ return yaml.dump(data, stream, _SafeOrderedDumper, default_flow_style=False, allow_unicode=True)

 class _SafeOrderedLoader(CSafeLoader):

(snapcraft) ubuntu@snapcraft-xenial-dev:~/t$ cat prime/meta/snap.yaml
name: my-snap-name
version: '0.1'
summary: Single-line elevator pitch for your amazing snap
description: |
  GNOME Calculator is an application that solves mathematical equations.
  Though it at first appears to be a simple calculator with only basic
  arithmetic operations, you can switch into Advanced, Financial, or
  Programming mode to find a surprising set of capabilities.

  The Advanced calculator supports many operations, including:
  logarithms, factorials, trigonometric and hyperbolic functions,
  modulus division, complex numbers, random number generation, prime
  factorization and unit conversions.

  Financial mode supports several computations, including periodic interest
  rate, present and future value, double declining and straight line
  depreciation, and many others.

  Programming mode supports conversion between common bases (binary, octal,
  decimal, and hexadecimal), boolean algebra, one’s and two’s complementation,
  character to character code conversion, and more.
architectures:
- amd64
base: core18
confinement: devmode
grade: devel

Changed in snapcraft:
status: New → In Progress
importance: Undecided → High
assignee: nobody → Sergio Schvezov (sergiusens)
milestone: none → 3.0.1
Revision history for this message
Sergio Schvezov (sergiusens) wrote :
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Thanks!

Revision history for this message
Sergio Schvezov (sergiusens) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.