Skip to content

Commit d7f822b

Browse files
committed
feat: add ability to ignore parse exception console messages
Refs: #55
1 parent 23f7cdd commit d7f822b

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

sphinxcontrib/doxylink/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
__version__ = "1.12.3"
1+
from . import config
22

3+
__version__ = "1.12.3"
34

45
def setup(app):
56
from .doxylink import setup_doxylink_roles
67
app.add_config_value('doxylink', {}, 'env')
78
app.add_config_value('doxylink_pdf_files', {}, 'env')
9+
app.add_config_value(config.DOXYLINK_IGNORE_PARSE_EXCEPTIONS_KEY,
10+
default=False, types=bool, rebuild='env')
811
app.connect('builder-inited', setup_doxylink_roles)
912

1013
return {

sphinxcontrib/doxylink/config.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DOXYLINK_KEY = 'doxylink'
2+
3+
DOXYLINK_IGNORE_PARSE_EXCEPTIONS_KEY = (
4+
'_'.join([DOXYLINK_KEY,'ignore_parse_exceptions'])
5+
)

sphinxcontrib/doxylink/doxylink.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from sphinx.util.logging import getLogger
2020

2121
from . import __version__
22+
from . import config
2223
from .parsing import normalise, ParseException
2324

2425

@@ -134,8 +135,8 @@ def is_url(str_to_validate: str) -> bool:
134135

135136
class SymbolMap:
136137
"""A SymbolMap maps symbols to Entries."""
137-
def __init__(self, xml_doc: ET.ElementTree) -> None:
138-
entries = parse_tag_file(xml_doc)
138+
def __init__(self, xml_doc: ET.ElementTree, ignore_parse_exceptions: bool) -> None:
139+
entries = parse_tag_file(xml_doc, ignore_parse_exceptions)
139140

140141
# Sort the entry list for use with bisect
141142
self._entries = sorted(entries)
@@ -225,7 +226,7 @@ def __getitem__(self, item: str) -> Entry:
225226
return self._disambiguate(symbol, candidates)
226227

227228

228-
def parse_tag_file(doc: ET.ElementTree) -> List[Entry]:
229+
def parse_tag_file(doc: ET.ElementTree, ignore_parse_exceptions: bool) -> List[Entry]:
229230
"""
230231
Takes in an XML tree from a Doxygen tag file and returns a list that looks something like:
231232
@@ -290,7 +291,9 @@ def parse_tag_file(doc: ET.ElementTree) -> List[Entry]:
290291
entries.append(
291292
Entry(name=member_symbol, kind=member_kind, file=member_file, arglist=normalised_arglist))
292293
except ParseException as e:
293-
print(f'Skipping {member_kind} {member_symbol}{arglist}. Error reported from parser was: {e}')
294+
if not ignore_parse_exceptions:
295+
print(f'Skipping {member_kind} {member_symbol}{arglist}. Error reported from parser was: {e}')
296+
continue
294297
else:
295298
# Put the simple things directly into the list
296299
entries.append(Entry(name=member_symbol, kind=member_kind, file=member_file, arglist=None))
@@ -303,6 +306,10 @@ def join(*args):
303306

304307

305308
def create_role(app, tag_filename, rootdir, cache_name, pdf=""):
309+
ignore_parse_exceptions = getattr(app.config, config.DOXYLINK_IGNORE_PARSE_EXCEPTIONS_KEY)
310+
if ignore_parse_exceptions:
311+
report_info(app.env,"Ignoring parsing exceptions")
312+
306313
# Tidy up the root directory path
307314
if not rootdir.endswith(('/', '\\')):
308315
rootdir = join(rootdir, os.sep)
@@ -330,22 +337,22 @@ def _parse():
330337
if not hasattr(app.env, 'doxylink_cache'):
331338
# no cache present at all, initialise it
332339
report_info(app.env, 'No cache at all, rebuilding...')
333-
mapping = SymbolMap(_parse())
340+
mapping = SymbolMap(_parse(), ignore_parse_exceptions)
334341
app.env.doxylink_cache = {cache_name: {'mapping': mapping, 'mtime': modification_time, 'version': __version__}}
335342
elif not app.env.doxylink_cache.get(cache_name):
336343
# Main cache is there but the specific sub-cache for this tag file is not
337344
report_info(app.env, 'Sub cache is missing, rebuilding...')
338-
mapping = SymbolMap(_parse())
345+
mapping = SymbolMap(_parse(), ignore_parse_exceptions)
339346
app.env.doxylink_cache[cache_name] = {'mapping': mapping, 'mtime': modification_time, 'version': __version__}
340347
elif app.env.doxylink_cache[cache_name]['mtime'] < modification_time:
341348
# tag file has been modified since sub-cache creation
342349
report_info(app.env, 'Sub-cache is out of date, rebuilding...')
343-
mapping = SymbolMap(_parse())
350+
mapping = SymbolMap(_parse(), ignore_parse_exceptions)
344351
app.env.doxylink_cache[cache_name] = {'mapping': mapping, 'mtime': modification_time}
345352
elif not app.env.doxylink_cache[cache_name].get('version') or app.env.doxylink_cache[cache_name].get('version') != __version__:
346353
# sub-cache doesn't have a version or the version doesn't match
347354
report_info(app.env, 'Sub-cache schema version doesn\'t match, rebuilding...')
348-
mapping = SymbolMap(_parse())
355+
mapping = SymbolMap(_parse(), ignore_parse_exceptions)
349356
app.env.doxylink_cache[cache_name] = {'mapping': mapping, 'mtime': modification_time, 'version': __version__}
350357
else:
351358
# The cache is up to date

0 commit comments

Comments
 (0)