From a6c32b0d962696e4c1c1457d54cfea1bc28cb048 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 12 Jun 2017 18:55:03 +0100 Subject: [PATCH 1/2] Stop attempting to convert previously-converted headers --- scripts/reformat_docs.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/reformat_docs.py b/scripts/reformat_docs.py index 35dc6e12809..91e7abac720 100644 --- a/scripts/reformat_docs.py +++ b/scripts/reformat_docs.py @@ -95,6 +95,10 @@ def is_block_valid(self, block): def convert_sections(self, block): return [self.format_module(block)] + def needs_new_header(self, file_contents): + return (re.search(r'^\/\/\/ \\file$', file_contents, flags=re.MULTILINE) + is None) + class FunctionFormatter(GenericFormatter): def __init__(self, doc_width): @@ -188,6 +192,7 @@ def convert_sections(self, block): def replace_block( block_contents, + file_contents, file, header_formatter, class_formatter, @@ -199,9 +204,12 @@ def replace_block( {f.name: f.contents for f in parse_fields(block_contents.group(1))}) if header_formatter.is_block_valid(block): - return '%s%s\n' % ( - block_contents.group(0), - header_formatter.convert(header_from_block(block))) + converted = header_formatter.convert(header_from_block(block)) + if header_formatter.needs_new_header(file_contents) and converted: + return '%s%s' % ( + block_contents.group(0), + header_formatter.convert(header_from_block(block)) + '\n') + return block_contents.group(0) if class_formatter.is_block_valid(block): return class_formatter.convert(class_from_block(block)) @@ -231,6 +239,7 @@ def convert_file(file, inplace): new_contents = block_re.sub( lambda match: replace_block( match, + contents, file, header_formatter, class_formatter, From bec818e179bcb199e2f95e6923b01f121af21272 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 13 Jun 2017 13:14:24 +0100 Subject: [PATCH 2/2] Remove duplication from conversion script --- scripts/reformat_docs.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/reformat_docs.py b/scripts/reformat_docs.py index 91e7abac720..eadc5359052 100644 --- a/scripts/reformat_docs.py +++ b/scripts/reformat_docs.py @@ -206,9 +206,7 @@ def replace_block( if header_formatter.is_block_valid(block): converted = header_formatter.convert(header_from_block(block)) if header_formatter.needs_new_header(file_contents) and converted: - return '%s%s' % ( - block_contents.group(0), - header_formatter.convert(header_from_block(block)) + '\n') + return block_contents.group(0) + converted + '\n' return block_contents.group(0) if class_formatter.is_block_valid(block):