canonical / craft-application

The basis for *craft applications
https://canonical-craft-application.readthedocs-hosted.com/en/latest
GNU Lesser General Public License v3.0
5 stars 7 forks source link

Properly represent multi-line yaml strings #255

Open cmatsuoka opened 4 months ago

cmatsuoka commented 4 months ago

What needs to get done

Add multi-line string representer to be used when marshaling yaml fields such as description and scriptlets. The representer is currently defined in Snapcraft but it's not being invoked since https://github.com/canonical/snapcraft/commit/e75d0e93bcbf019a8dbd17caf4842e23788ab53a.

Why it needs to get done

Multi-line fields formatting is not correct in generated yaml data if the representer is not used.

syncronize-issues-to-jira[bot] commented 2 months ago

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CRAFT-2666.

This message was autogenerated

lengau commented 2 months ago

util.dump_yaml is already supposed to do this, and it looks like CraftBaseModel is using that.

With this attempted reproducer:

from craft_application import util

print(
    util.dump_yaml(
        {
            "single-line": "some line",
            "multi-line": "a\nb",
            "multi-line-with-eol": "a\nb\n"
        }
    )
)

I get the output I would expect:

(craft-application) lengau@ratel:~/tmp$ python yaml_reproducer.py 
single-line: some line
multi-line: |-
  a
  b
multi-line-with-eol: |
  a
  b

Is dump_yaml behaving correctly?