Sphinx: how to exclude imports in automodule?

前端 未结 3 1380
清歌不尽
清歌不尽 2020-12-03 03:02

I have a Raspberry Pi project written in Python that uses RPi.GPIO module. All the work on the code is done on a Windows box where RPi.GPIO will not install and every time I

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 03:33

    Just a few minutes ago I've found another solution: Do not place "import RPi.GPIO" at the beginning of the file. Place it inside the function / method (maybe not a good style). So sphinx will not see it and a documentation will be build.

    But the solution with mocking is better, here is a link: http://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_mock_imports

    Just add the following line to conf.py (RPi and serial are examples):

    autodoc_mock_imports = ["RPi", 'serial']
    

提交回复
热议问题