daizutabi / mkapi

A plugin for MkDocs to generate API documentation
https://daizutabi.github.io/mkapi/
MIT License
103 stars 19 forks source link

Mock unavailable libraries? #11

Closed AchimKern closed 4 years ago

AchimKern commented 4 years ago

Hi ,

I would like do to document a project that makes heavy use of external libraries where I don't have access to the sources. Does mkapi offer something similar to mocks in sphinxs/autodoc autodoc_mock_imports = ["django","td"]?

Thanks in advance

AchimKern commented 4 years ago

in other words, is there a way to configure/run something like this when documentation is created

import sys
from unittest.mock import MagicMock as mock
sys.modules["td"] = mock()
daizutabi commented 4 years ago

In Version 0.8.1, on_config option was added. See this example

In your case, please try:

# setup.py
import sys
from unittest.mock import MagicMock as mock

def on_config():
    sys.modules["td"] = mock()

and

# mkdocs.yml
plugins:
  - mkapi:
    src_dirs: [<path_to_setup.py>]
    on_config: setup.on_config
AchimKern commented 4 years ago

wow. thank you. this seems to be working perfectly