微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Sphinx 未正确显示代码文档

如何解决Sphinx 未正确显示代码文档

问题:

Sphinx 不显示文档化代码 - 仅目录。我已将此隔离到 Sphinx 未在调用 sphinx-apidoc 时为每个记录的 *.py 文件生成 *.rst 文件

注意:

我将 vscode 与 autodoc 一起使用,autodoc 格式在 vscode 设置文件中设置为 sphinx

我的项目树:

.
└── MNF
    ├── classes
    │   ├── file_parser.py
    │   └── README.txt
    ├── configs
    │   ├── datasets.json
    │   └── README.txt
    ├── data_in
    │   └── README.txt
    ├── data_out
    │   └── README.txt
    ├── LICENSE
    ├── models
    │   └── README.txt
    ├── notebooks
    │   ├── eda.ipynb
    │   └── README.txt
    ├── packages.microsoft.gpg
    ├── papers
    │   ├── conda-cheatsheet.pdf
    │   ├── dejuan2013.pdf
    │   ├── Git-Cheatsheet.pdf
    │   └── READE.txt
    ├── plots
    │   └── README.txt
    ├── __pycache__
    │   └── file_parser.cpython-39.pyc
    ├── README.md
    ├── src
    │   └── README.txt
    ├── test_branch.txt
    ├── test_main.txt
    ├── tests
    │   └── README.txt
    └── utilities
        └── README.txt

感兴趣的代码

class FileParser:
    """File parser
    """
    def __init__(self,root_path="../data_in/"):
        """
        :param root_path: root path to search isHiddenWithinTree,defaults to "../data_in/"
        :type root_path: str,optional
        """
        self.root_path = root_path

    def get_root_path(self):
        """Basic getter

        :return: root path
        :rtype: string
        """
        return self.root_path
    

步骤第 1 部分:

修改conf.py:

import os
import sys
sys.path.insert(0,os.path.abspath('.')) 

import os
import sys
sys.path.insert(0,os.path.abspath('..'))

更改 index.rst 以包含模块:

===============================

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   modules



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

步骤第 2 部分:

在文档目录中

  • 运行 sphinx-apidoc -o source/ ..
  • 制作html

新文档树

.
├── docs
│   ├── build
│   │   ├── doctrees
│   │   │   ├── environment.pickle
│   │   │   ├── index.doctree
│   │   │   └── modules.doctree
│   │   └── html
│   │       ├── genindex.html
│   │       ├── index.html
│   │       ├── modules.html
│   │       ├── objects.inv
│   │       ├── search.html
│   │       ├── searchindex.js
│   │       ├── _sources
│   │       │   ├── index.rst.txt
│   │       │   └── modules.rst.txt
│   │       └── _static
│   │           ├── ajax-loader.gif
│   │           ├── alabaster.css
│   │           ├── basic.css
│   │           ├── comment-bright.png
│   │           ├── comment-close.png
│   │           ├── comment.png
│   │           ├── custom.css
│   │           ├── doctools.js
│   │           ├── down.png
│   │           ├── down-pressed.png
│   │           ├── file.png
│   │           ├── jquery-3.2.1.js
│   │           ├── jquery.js
│   │           ├── minus.png
│   │           ├── plus.png
│   │           ├── pygments.css
│   │           ├── searchtools.js
│   │           ├── underscore-1.3.1.js
│   │           ├── underscore.js
│   │           ├── up.png
│   │           ├── up-pressed.png
│   │           └── websupport.js

modules.rst 文件

git_mnf
=======

.. toctree::
   :maxdepth: 4

问题 1:

没有生成 file_parser.rst。

问题 2:

index.html 页面不显示任何文档

enter image description here

帮助: 我对这个一无所知。为什么我的 FileParse.py 文档没有显示的任何想法?

版本:

  • Python 3.9.2
  • 狮身人面像 1.6.7
  • vscode 1.54.3
  • 系统:mac os
  • 浏览器:火狐

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。