From 7ebfface22976a2d8fee3dc885626a5b009377d8 Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 6 May 2021 23:12:19 +1000 Subject: [PATCH] Explicitly ignore legacy file reference errors in sphinx -n mode --- docs/conf.py | 8 ++++++++ docs/extensions/nitpick_file_ignorer.py | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 docs/extensions/nitpick_file_ignorer.py diff --git a/docs/conf.py b/docs/conf.py index 925d5339b..f7193dc59 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -40,6 +40,7 @@ extensions = [ 'exception_hierarchy', 'attributetable', 'resourcelinks', + 'nitpick_file_ignorer', ] autodoc_member_order = 'bysource' @@ -140,6 +141,13 @@ pygments_style = 'friendly' #keep_warnings = False +# Nitpicky mode options +nitpick_ignore_files = [ + "migrating_to_async", + "migrating", + "whats_new", +] + # -- Options for HTML output ---------------------------------------------- html_experimental_html5_writer = True diff --git a/docs/extensions/nitpick_file_ignorer.py b/docs/extensions/nitpick_file_ignorer.py new file mode 100644 index 000000000..f5dff1d12 --- /dev/null +++ b/docs/extensions/nitpick_file_ignorer.py @@ -0,0 +1,22 @@ +import logging + +from sphinx.application import Sphinx +from sphinx.util import logging as sphinx_logging + + +class NitpickFileIgnorer(logging.Filter): + + def __init__(self, app: Sphinx) -> None: + self.app = app + super().__init__() + + def filter(self, record: sphinx_logging.SphinxLogRecord) -> bool: + if getattr(record, 'type', None) == 'ref': + return record.location.get('refdoc') not in self.app.config.nitpick_ignore_files + return True + + +def setup(app: Sphinx): + app.add_config_value('nitpick_ignore_files', [], '') + f = NitpickFileIgnorer(app) + sphinx_logging.getLogger('sphinx.transforms.post_transforms').logger.addFilter(f)