juju / charm-tools

Tools for charm authors and maintainers
Other
42 stars 64 forks source link

'charm create' populates metadata.yaml will error inducing content #502

Open erik78se opened 5 years ago

erik78se commented 5 years ago

What version am I running?

snap info charm
name:      charm
summary:   charm and charm-tools
publisher: Cory Johns (johnsca)
contact:   juju@lists.ubuntu.com
license:   unset
description: |
  charmstore-client and charm-tools
commands:
  - charm
snap-id:      2Rryoc2ylScfbFl4eQtpntHD9iuZuMvt
tracking:     stable
refresh-date: 23 days ago, at 17:26 CET
channels:
  stable:    2.5.2                2019-02-07 (320) 47MB classic
  candidate: 2.5.2                2019-02-07 (320) 47MB classic
  beta:      2.5.2                2019-02-07 (320) 47MB classic
  edge:      2.5.2+git-3-gef3d9a6 2019-02-12 (326) 47MB classic
installed:   2.5.2                           (320) 47MB classic

I am using: Distributor ID: Ubuntu Description: Ubuntu 18.04.1 LTS Release: 18.04 Codename: bionic

Issue

I create a new charm with:

charm create -t bash"

The generated metadata.yaml gets populated with my name which contains "non english" chars. In my case "Ö" which is a swedish character.

This blows up the following build.

The metadata.yaml content that blows it all up:

$ grep maintainer metadata.yaml maintainer: Erik Lönroth Erik.Lönroth@juju-dev

I expected the following

I expect that the generated metadata.yaml would at least either warn me about the situation - or even better - charm create would not populate with chars that are doomed to fail which leads up to an uncaught exception.

Although its evident that this is the problem and the fix is obvious to me. Its not cool to produce a charm from the tool that by no means is usable and also causes build havoc which requires knowledge in python to understand even for someone that tries to produce a "bash" charm.

What I got

$ charm build

build: DEPRECATED: implicit series; specify series in metadata.yaml instead
build: Build dir not specified via command-line or environment; defaulting to /tmp/charm-builds
build: Please add a `repo` key to your layer.yaml, with a url from which your layer can be cloned.
build: Destination charm directory: /tmp/charm-builds/hooker
build: The top level layer expects a valid layer.yaml file
build: Processing layer: hooker (from .)
Traceback (most recent call last):
  File "/snap/charm/320/bin/charm-build", line 9, in <module>
    load_entry_point('charm-tools==2.5.2', 'console_scripts', 'charm-build')()
  File "/snap/charm/320/lib/python3.5/site-packages/charmtools/build/builder.py", line 924, in main
    lint, exit_code = proof.proof(build.target_dir, False, False)
  File "/snap/charm/320/lib/python3.5/site-packages/charmtools/proof.py", line 65, in proof
    lint, err_code = c.proof()
  File "/snap/charm/320/lib/python3.5/site-packages/charmtools/charms.py", line 324, in proof
    validate_maintainer(charm, lint)
  File "/snap/charm/320/lib/python3.5/site-packages/charmtools/charms.py", line 923, in validate_maintainer
    formatted = email.utils.formataddr((name, address))
  File "/snap/charm/320/usr/lib/python3.5/email/utils.py", line 91, in formataddr
    address.encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode character '\xf6' in position 6: ordinal not in range(128)
stub42 commented 5 years ago

validate_maintainer needs to catch the malformed email address, however it ended up in metadata.yaml.