Skip to content

Commit 2d1ad60

Browse files
authored
Treat all doc/rst warnings as errors (#414)
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
1 parent 9e783e2 commit 2d1ad60

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

scripts/generate_docs.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
RE_ENABLE = r"^\#\#\s*\-\-validate\s*\=\s*on$"
1515
RE_DISABLE = r"^\#\#\s*\-\-validate\s*\=\s*off$"
1616

17-
RE_PYCODE_BLOCK_BEGIN = r"^\<\%$"
18-
RE_PYCODE_BLOCK_END = r"^\%\>$"
17+
RE_PYCODE_BLOCK_BEGIN = r"^[\ufeff]?\<\%\!?\s*$"
18+
RE_PYCODE_BLOCK_END = r"^\%\>\s*$"
1919

2020
RE_INVALID_TAG_FORMAT = r".*(\$\w).*"
2121
RE_EXTRACT_TAG_NAME = r"\$\{(\w)\}"
@@ -113,11 +113,14 @@ def _generate_valid_rst(fin, fout, namespace, tags, ver, rev, meta):
113113
outlines.append(line)
114114
continue
115115

116-
if re.match(RE_INVALID_TAG_FORMAT, line):
117-
print("%s(%s) : error : invalid %s tag used"%(fin, iline+1, re.sub(RE_INVALID_TAG_FORMAT, r"\1", line)))
118-
119116
# new line will contain proper tags for reStructuredText if needed
120117
newline = line
118+
119+
# Only validate tags when not in code blocks
120+
if not code_block and re.match(RE_INVALID_TAG_FORMAT, line):
121+
error_msg = "%s(%s) : error : invalid %s tag used"%(fin, iline+1, re.sub(RE_INVALID_TAG_FORMAT, r"\1", line))
122+
print(error_msg)
123+
util.makeError(error_msg)
121124
if re.match(RE_PROPER_TAG_FORMAT, line):
122125
words = re.findall(RE_EXTRACT_NAME, line)
123126

scripts/run.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os, sys, platform
1313
import time
1414
import subprocess
15+
import warnings
1516

1617
"""
1718
helper for adding mutually-exclusive boolean arguments "--name" and "--!name"
@@ -48,7 +49,7 @@ def update_spec(target):
4849
"""
4950
def build():
5051
if "Windows" == platform.system():
51-
result = os.system('cmake -B ../build/ -S .. -G "Visual Studio 17 2022" -A x64')
52+
result = os.system('cmake -B ../build/ -S .. -G "Visual Studio 17 2022" -A x64"')
5253
else:
5354
result = os.system('cmake -B ../build/ -S ..')
5455
if result == 0:
@@ -84,6 +85,9 @@ def revision():
8485
Do everything...
8586
"""
8687
def main():
88+
# Configure Python to treat warnings as errors
89+
warnings.filterwarnings('error')
90+
8791
# phase 0: parse cmdline arguments
8892
configParser = util.configRead("config.ini")
8993

@@ -159,8 +163,9 @@ def main():
159163
generate_docs.generate_rst(docpath, config['name'], config['namespace'], config['tags'], args['ver'], args['rev'], specs, input['meta'])
160164

161165
if util.makeErrorCount():
166+
util.printAllErrors()
162167
print("\n%s Errors found during generation, stopping execution!"%util.makeErrorCount())
163-
return
168+
sys.exit(1)
164169

165170
if args['debug']:
166171
util.makoFileListWrite("generated.json")

scripts/util.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ def makoFileListWrite(outpath):
184184
def makeErrorCount():
185185
return len(makoErrorList)
186186

187+
def makeError(message):
188+
makoErrorList.append(message)
189+
190+
def printAllErrors():
191+
if len(makoErrorList) > 0:
192+
print("\n" + "="*80)
193+
print("ERRORS SUMMARY (%d error(s) found):" % len(makoErrorList))
194+
print("="*80)
195+
for idx, error in enumerate(makoErrorList, 1):
196+
print("%d. %s" % (idx, error))
197+
print("="*80)
198+
187199
"""
188200
write to array of string lines to file
189201
"""

0 commit comments

Comments
 (0)