Merge lp:~evarlast/charm-tools/warn-description-newlines into lp:charm-tools/1.4

Proposed by Jay R. Wren
Status: Rejected
Rejected by: Marco Ceppi
Proposed branch: lp:~evarlast/charm-tools/warn-description-newlines
Merge into: lp:charm-tools/1.4
Diff against target: 73 lines (+52/-0)
2 files modified
charmtools/charms.py (+5/-0)
tests/test_charm_proof.py (+47/-0)
To merge this branch: bzr merge lp:~evarlast/charm-tools/warn-description-newlines
Reviewer Review Type Date Requested Status
Charm Toolers Pending
Review via email: mp+230899@code.launchpad.net

Description of the change

  Warn on newlines in config description

  If there are newlines in a config options description,
  juju get <charmname> displays the newlines making for very ugly
  formatting.

  This patch causes charm-proof to warn on newlines in options description.

See also: https://bugs.launchpad.net/juju-core/+bug/1292116

To post a comment you must log in.
Revision history for this message
Charles Butler (lazypower) wrote :

+1 LGTM

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

NLGTM

Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

I appreciate this patch very much, but I don't think this is the correct way to solve this problem.

I think imposing arbitrary restrictions on which yaml contructs can be used will lead to a surprising user experience. This problem should be addressed by fixing the way the data is displayed by `juju get`, not by imposing restrictions on the data itself.

Revision history for this message
Charles Butler (lazypower) wrote :

> +1 LGTM

And I've since been wayyy corrected about why this is not good. DNLGTM

Unmerged revisions

338. By Jay R. Wren

Warn on newlines in config description

If there are newlines in a config options description,
juju get <charmname> displays the newlines making for very ugly
formatting.

This patch causes charm-proof to warn on newlines in options description.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmtools/charms.py'
2--- charmtools/charms.py 2014-06-17 15:44:04 +0000
3+++ charmtools/charms.py 2014-08-14 21:53:52 +0000
4@@ -182,6 +182,11 @@
5 self.warn(
6 'config.yaml: description of option %s should be a '
7 'non-empty string' % option_name)
8+ if (isinstance(option_value['description'], basestring) and
9+ '\n' in option_value['description']):
10+ self.warn(
11+ 'config.yaml: description of option {} contains '
12+ 'newlines'.format(option_name))
13 option_type = option_value.get('type', 'string')
14 if option_type not in KNOWN_OPTION_TYPES:
15 self.warn('config.yaml: option %s has an invalid type (%s)'
16
17=== modified file 'tests/test_charm_proof.py'
18--- tests/test_charm_proof.py 2014-06-17 15:44:04 +0000
19+++ tests/test_charm_proof.py 2014-08-14 21:53:52 +0000
20@@ -341,6 +341,53 @@
21 "for the tag 'tag:yaml.org,2002:python/name:__builtin__.int'")
22 self.assertTrue(self.linter.lint[0].startswith(expected))
23
24+ def test_multiline_description_newline_block_literal(self):
25+ self.write_config("""
26+ options:
27+ string_opt:
28+ description: |
29+ A long description over many lines.
30+ Please don't use pipe.
31+ default: some text
32+ type: string
33+ """)
34+ self.linter.check_config_file(self.charm_dir)
35+ self.assertEqual(
36+ ['W: config.yaml: description of option string_opt contains '
37+ 'newlines'],
38+ self.linter.lint)
39+
40+ def test_multiline_description_newline_folded_block_literal(self):
41+ self.write_config("""
42+ options:
43+ string_opt:
44+ description: >
45+ A long description over many lines.
46+ Please don't use gt.
47+ default: some text
48+ type: string
49+ """)
50+ self.linter.check_config_file(self.charm_dir)
51+ self.assertEqual(
52+ ['W: config.yaml: description of option string_opt contains '
53+ 'newlines'],
54+ self.linter.lint)
55+
56+ def test_multiline_description_does_not_have_newlines(self):
57+ self.write_config("""
58+ options:
59+ string_opt:
60+ description:
61+ A long description over many lines.
62+ Please don't use pipe.
63+ default: some text
64+ type: string
65+ """)
66+ self.linter.check_config_file(self.charm_dir)
67+ self.assertEqual(
68+ [],
69+ self.linter.lint)
70+
71
72 class MaintainerValidationTest(TestCase):
73 def test_two_maintainer_fields(self):

Subscribers

People subscribed via source and target branches

to all changes: