Przeglądaj źródła

docs: add sphinx warnings in format_idf_target

format_idf_target will now log sphinx warnings for any
{IDF_TARGET_X} that were not replaced.
Marius Vikhammer 5 lat temu
rodzic
commit
c8cd68fbe6
1 zmienionych plików z 13 dodań i 0 usunięć
  1. 13 0
      docs/idf_extensions/format_idf_target.py

+ 13 - 0
docs/idf_extensions/format_idf_target.py

@@ -5,6 +5,7 @@ from docutils import io, nodes, statemachine, utils
 from docutils.utils.error_reporting import SafeString, ErrorString
 from docutils.parsers.rst import directives
 from sphinx.directives.other import Include as BaseInclude
+from sphinx.util import logging
 
 
 def setup(app):
@@ -21,6 +22,16 @@ def setup(app):
     return {'parallel_read_safe': True, 'parallel_write_safe': True, 'version': '0.2'}
 
 
+def check_content(content, docname):
+    # Log warnings for any {IDF_TARGET} expressions that haven't been replaced
+    logger = logging.getLogger(__name__)
+
+    errors = re.findall(r'{IDF_TARGET.*?}', content)
+
+    for err in errors:
+        logger.warning('Badly formated string substitution: {}'.format(err), location=docname)
+
+
 class StringSubstituter:
     """ Allows for string substitution of target related strings
         before any markup is parsed
@@ -113,6 +124,8 @@ class StringSubstituter:
     def substitute_source_read_cb(self, app, docname, source):
         source[0] = self.substitute(source[0])
 
+        check_content(source[0], docname)
+
 
 class FormatedInclude(BaseInclude):