in tools/config_doc_gen.py [0:0]
def comments_from_file(file_path):
"""
Get comments from config.py
"""
comments = []
analyze = False
comment_block_begin = False
with open(file_path, 'r') as config_file:
lines = config_file.readlines()
lines = [line.rstrip() for line in lines]
for line in lines:
if line.startswith('# THIS MUST PRECEDE DIRECTLY BEFORE LIST OF CONFIG OPTIONS!'):
analyze = True
continue
if line.startswith('# THIS MUST FOLLOW DIRECTLY AFTER LIST OF CONFIG OPTIONS!'):
break
if analyze and line.startswith('#'):
if line.startswith('# BEGIN'):
comments.append(line)
comment_block_begin = False
continue
if comment_block_begin:
comments[-1] += line.lstrip('#') if not comments[-1].endswith('/') else line.lstrip('# ')
continue
comment_block_begin = True
comments.append(line.lstrip('# '))
else: # not comment
if comment_block_begin:
comment_block_begin = False
return comments