From 8f658d63298c5fae29616b8d922d03bb7ea67c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Vall=C3=A9e?= Date: Fri, 23 Oct 2015 16:36:28 -0400 Subject: Fix wrapping file paths in Writer.comment Long file names, especially with hyphens will get incorrectly wrapped by the comment method. Pass has_path=True to prevent this type of wrapping. This is mainly so that longer path names can show up in comments on their on line without breaking them up. --- misc/ninja_syntax.py | 7 +++++-- misc/ninja_syntax_test.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/misc/ninja_syntax.py b/misc/ninja_syntax.py index 8673518..091e054 100644 --- a/misc/ninja_syntax.py +++ b/misc/ninja_syntax.py @@ -21,8 +21,11 @@ class Writer(object): def newline(self): self.output.write('\n') - def comment(self, text): - for line in textwrap.wrap(text, self.width - 2): + def comment(self, text, has_path=False): + args = {} + if has_path: + args['break_long_words'] = args['break_on_hyphens'] = False + for line in textwrap.wrap(text, self.width - 2, **args): self.output.write('# ' + line + '\n') def variable(self, key, value, indent=0): diff --git a/misc/ninja_syntax_test.py b/misc/ninja_syntax_test.py index 36b2e7b..46ce382 100755 --- a/misc/ninja_syntax_test.py +++ b/misc/ninja_syntax_test.py @@ -45,6 +45,17 @@ class TestLineWordWrap(unittest.TestCase): INDENT + 'y']) + '\n', self.out.getvalue()) + def test_comment_wrap(self): + # We should wrap the comments + self.n.comment('Hello there') + self.assertEqual('# Hello\n# there\n', self.out.getvalue()) + + def test_comment_wrap_filename(self): + # Filenames shoud not be wrapped + self.n.comment('Hello /usr/local/build-tools/bin', has_path=True) + self.assertEqual('# Hello\n# /usr/local/build-tools/bin\n', + self.out.getvalue()) + def test_short_words_indented(self): # Test that indent is taking into acount when breaking subsequent lines. # The second line should not be ' to tree', as that's longer than the -- cgit v0.12 From 8c18cf97ff0ff2a6347865443052913c598d7ee6 Mon Sep 17 00:00:00 2001 From: Alex Vallee Date: Wed, 11 Nov 2015 22:48:39 -0500 Subject: Fix indent in pull request #1042. --- misc/ninja_syntax.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/ninja_syntax.py b/misc/ninja_syntax.py index 091e054..f285420 100644 --- a/misc/ninja_syntax.py +++ b/misc/ninja_syntax.py @@ -24,7 +24,7 @@ class Writer(object): def comment(self, text, has_path=False): args = {} if has_path: - args['break_long_words'] = args['break_on_hyphens'] = False + args['break_long_words'] = args['break_on_hyphens'] = False for line in textwrap.wrap(text, self.width - 2, **args): self.output.write('# ' + line + '\n') -- cgit v0.12 From 97e96284a3cec71b8cf78a3bec5b525cc3e538bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Vall=C3=A9e?= Date: Fri, 27 Nov 2015 16:09:34 -0500 Subject: Disable long word wrapping entirely in comments. As pointed out by nico, we should unconditionally disable breaking of long words in comments. It is unlikely long words that are in comments should be split (like pathnames). --- misc/ninja_syntax.py | 6 ++---- misc/ninja_syntax_test.py | 7 +------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/misc/ninja_syntax.py b/misc/ninja_syntax.py index f285420..73d2209 100644 --- a/misc/ninja_syntax.py +++ b/misc/ninja_syntax.py @@ -22,10 +22,8 @@ class Writer(object): self.output.write('\n') def comment(self, text, has_path=False): - args = {} - if has_path: - args['break_long_words'] = args['break_on_hyphens'] = False - for line in textwrap.wrap(text, self.width - 2, **args): + for line in textwrap.wrap(text, self.width - 2, break_long_words=False, + break_on_hyphens=False): self.output.write('# ' + line + '\n') def variable(self, key, value, indent=0): diff --git a/misc/ninja_syntax_test.py b/misc/ninja_syntax_test.py index 46ce382..c9755b8 100755 --- a/misc/ninja_syntax_test.py +++ b/misc/ninja_syntax_test.py @@ -46,13 +46,8 @@ class TestLineWordWrap(unittest.TestCase): self.out.getvalue()) def test_comment_wrap(self): - # We should wrap the comments - self.n.comment('Hello there') - self.assertEqual('# Hello\n# there\n', self.out.getvalue()) - - def test_comment_wrap_filename(self): # Filenames shoud not be wrapped - self.n.comment('Hello /usr/local/build-tools/bin', has_path=True) + self.n.comment('Hello /usr/local/build-tools/bin') self.assertEqual('# Hello\n# /usr/local/build-tools/bin\n', self.out.getvalue()) -- cgit v0.12