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
=== modified file 'charmtools/charms.py'
--- charmtools/charms.py 2014-06-17 15:44:04 +0000
+++ charmtools/charms.py 2014-08-14 21:53:52 +0000
@@ -182,6 +182,11 @@
182 self.warn(182 self.warn(
183 'config.yaml: description of option %s should be a '183 'config.yaml: description of option %s should be a '
184 'non-empty string' % option_name)184 'non-empty string' % option_name)
185 if (isinstance(option_value['description'], basestring) and
186 '\n' in option_value['description']):
187 self.warn(
188 'config.yaml: description of option {} contains '
189 'newlines'.format(option_name))
185 option_type = option_value.get('type', 'string')190 option_type = option_value.get('type', 'string')
186 if option_type not in KNOWN_OPTION_TYPES:191 if option_type not in KNOWN_OPTION_TYPES:
187 self.warn('config.yaml: option %s has an invalid type (%s)'192 self.warn('config.yaml: option %s has an invalid type (%s)'
188193
=== modified file 'tests/test_charm_proof.py'
--- tests/test_charm_proof.py 2014-06-17 15:44:04 +0000
+++ tests/test_charm_proof.py 2014-08-14 21:53:52 +0000
@@ -341,6 +341,53 @@
341 "for the tag 'tag:yaml.org,2002:python/name:__builtin__.int'")341 "for the tag 'tag:yaml.org,2002:python/name:__builtin__.int'")
342 self.assertTrue(self.linter.lint[0].startswith(expected))342 self.assertTrue(self.linter.lint[0].startswith(expected))
343343
344 def test_multiline_description_newline_block_literal(self):
345 self.write_config("""
346 options:
347 string_opt:
348 description: |
349 A long description over many lines.
350 Please don't use pipe.
351 default: some text
352 type: string
353 """)
354 self.linter.check_config_file(self.charm_dir)
355 self.assertEqual(
356 ['W: config.yaml: description of option string_opt contains '
357 'newlines'],
358 self.linter.lint)
359
360 def test_multiline_description_newline_folded_block_literal(self):
361 self.write_config("""
362 options:
363 string_opt:
364 description: >
365 A long description over many lines.
366 Please don't use gt.
367 default: some text
368 type: string
369 """)
370 self.linter.check_config_file(self.charm_dir)
371 self.assertEqual(
372 ['W: config.yaml: description of option string_opt contains '
373 'newlines'],
374 self.linter.lint)
375
376 def test_multiline_description_does_not_have_newlines(self):
377 self.write_config("""
378 options:
379 string_opt:
380 description:
381 A long description over many lines.
382 Please don't use pipe.
383 default: some text
384 type: string
385 """)
386 self.linter.check_config_file(self.charm_dir)
387 self.assertEqual(
388 [],
389 self.linter.lint)
390
344391
345class MaintainerValidationTest(TestCase):392class MaintainerValidationTest(TestCase):
346 def test_two_maintainer_fields(self):393 def test_two_maintainer_fields(self):

Subscribers

People subscribed via source and target branches

to all changes: