From 251d61a6e252e92a12c77670f81a8d3d4b325642 Mon Sep 17 00:00:00 2001 From: Kernc Date: Thu, 6 May 2021 23:10:33 +0200 Subject: [PATCH] BUG: Don't build Lunr search index when not --html Refs: https://github.com/pdoc3/pdoc/issues/339 --- pdoc/cli.py | 9 +++++---- pdoc/test/__init__.py | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pdoc/cli.py b/pdoc/cli.py index 3fcd164a..97a47384 100755 --- a/pdoc/cli.py +++ b/pdoc/cli.py @@ -581,10 +581,11 @@ def docfilter(obj, _filters=args.filter.strip().split(',')): # Two blank lines between two modules' texts sys.stdout.write(os.linesep * (1 + 2 * int(module != modules[-1]))) - lunr_config = pdoc._get_config(**template_config).get('lunr_search') - if lunr_config is not None: - _generate_lunr_search( - modules, lunr_config.get("index_docstrings", True), template_config) + if args.html: + lunr_config = pdoc._get_config(**template_config).get('lunr_search') + if lunr_config is not None: + _generate_lunr_search( + modules, lunr_config.get("index_docstrings", True), template_config) _PANDOC_COMMAND = '''\ diff --git a/pdoc/test/__init__.py b/pdoc/test/__init__.py index 6fae460f..5ea6141f 100644 --- a/pdoc/test/__init__.py +++ b/pdoc/test/__init__.py @@ -274,6 +274,10 @@ def test_lunr_search(self): file_pattern='example_pkg/module.html') self._check_files(include_patterns=["'../../doc-search.html#'"], file_pattern='example_pkg/subpkg/index.html') + # Only build lunr search when --html + with redirect_streams() as (_, stderr): + run(EXAMPLE_MODULE, config='lunr_search={"fuzziness": 1}') + self.assertFalse(stderr.read()) def test_force(self): with run_html(EXAMPLE_MODULE):