pdoc3 / pdoc

:snake: :arrow_right: :scroll: Auto-generate API documentation for Python projects
https://pdoc3.github.io/pdoc/
GNU Affero General Public License v3.0
1.11k stars 143 forks source link

Search function #446

Closed AnthonyZJiang closed 2 weeks ago

AnthonyZJiang commented 3 weeks ago

How do I add a search function?

I noticed it was implemented but there is no documentation on it. How do I use it?

kernc commented 3 weeks ago

In your config.mako, you enable either of the two search methods following the provided template/example: https://github.com/pdoc3/pdoc/blob/80697ebf2cb4385af2d1c76148ee7a7435e1467f/pdoc/templates/config.mako#L45-L56 That's been supported for a while.

AnthonyZJiang commented 3 weeks ago

In your config.mako, you enable either of the two search methods following the provided template/example:

https://github.com/pdoc3/pdoc/blob/80697ebf2cb4385af2d1c76148ee7a7435e1467f/pdoc/templates/config.mako#L45-L56

That's been supported for a while.

Thanks. I have tried to enable lunr_search, but it causes an error at the end of the doc generation. The search box appears in the HTML but not working.

The terminal prompt:

% pdoc --html --output-dir docs/ --force python_lib/isotope/isotope --template-dir docs/templates/
docs/isotope/index.html
/Users/user/Documents/isotope_sdk/venv/lib/python3.12/site-packages/pdoc/html_helpers.py:532: ReferenceWarning: Code reference `isotope.port.PowerOutput` in module "isotope.isotope" does not match any documented object.
  linked = re.sub(r'[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*(?:\(\))?', handle_refname, code_span)
/Users/user/Documents/isotope_sdk/venv/lib/python3.12/site-packages/pdoc/html_helpers.py:532: ReferenceWarning: Code reference `isotope.port.Motor` in module "isotope.isotope" does not match any documented object.
  linked = re.sub(r'[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*(?:\(\))?', handle_refname, code_span)
/Users/user/Documents/isotope_sdk/venv/lib/python3.12/site-packages/pdoc/html_helpers.py:532: ReferenceWarning: Code reference `isotope.port.ADCInput` in module "isotope.isotope" does not match any documented object.
  linked = re.sub(r'[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*(?:\(\))?', handle_refname, code_span)
/Users/user/Documents/isotope_sdk/venv/lib/python3.12/site-packages/pdoc/html_helpers.py:532: ReferenceWarning: Code reference `isotope.port.PWMOutput` in module "isotope.isotope" does not match any documented object.
  linked = re.sub(r'[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*(?:\(\))?', handle_refname, code_span)
/Users/user/Documents/isotope_sdk/venv/lib/python3.12/site-packages/pdoc/html_helpers.py:532: ReferenceWarning: Code reference `isotope.port.TempInput` in module "isotope.isotope" does not match any documented object.
  linked = re.sub(r'[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*(?:\(\))?', handle_refname, code_span)
docs/isotope/isotope.html
docs/isotope/isotope_comms_lib.html
docs/isotope/port/index.html
docs/isotope/port/adc_input.html
docs/isotope/port/isotope_port.html
docs/isotope/port/motor.html
docs/isotope/port/power_output.html
docs/isotope/port/pwm_output.html
docs/isotope/port/temp_input.html
docs/isotope/utils/index.html
docs/isotope/utils/logging.html
Traceback (most recent call last):
  File "/Users/user/Documents/isotope_sdk/venv/bin/pdoc", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/user/Documents/isotope_sdk/venv/lib/python3.12/site-packages/pdoc/cli.py", line 606, in main
    _generate_lunr_search(
  File "/Users/user/Documents/software/isotope_sdk/venv/lib/python3.12/site-packages/pdoc/cli.py", line 422, in _generate_lunr_search
    proc = subprocess.Popen(cmd, text=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'node'

In my config.mako file:

  <%!
      hljs_style = 'atom-one-light'
      lunr_search = {'fuzziness': 1, 'index_docstrings': True}
  %>
AnthonyZJiang commented 3 weeks ago

In case it helps, here is the repository I am using pdoc3 to generate documentation for

https://github.com/ICE9-Robotics/isotope_sdk