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

您如何在sphinx-apidoc中包含几个子目录?

如何解决您如何在sphinx-apidoc中包含几个子目录?

问题

我正在尝试为包含多个子目录的Python项目构建文档。我正在尝试使用import iterutils template initClosure(id:untyped,iter:untyped) = let id = iterator():auto {.closure.} = for x in iter: yield x iterator letters: auto = for c in 'a' .. 'z': yield c # Now requires a parameter iterator numbers(s: int): int = var n = s while true: yield n inc n initClosure(cletter,letters()) initClosure(numbers8,numbers(8)) for (c,n) in zip(cletter,numbers8): echo c,n 来使过程变得无缝。但是,尽管我已尽力而为,但我无法处理子目录中的代码。我在YouTube here上观看了一篇很棒的简短教程,效果很好。为了模拟我一直遇到的问题,我将其中一个文件放在sphinx-apidoc目录中,如下所示。

can_it_handle_folders

我转到spamfilter-py │ __init__.py (**) │ readme.md │ sample.py │ spamfilter.py │ token.py ├───can_it_handle_folders │ __init__.py │ test_spamfilter.py ├───docs │ ├───build │ │ └───html │ └───source │ ├───conf.py │ ├───index.rst │ ├───modules.rst │ ├───sample.rst │ ├───spamfilter.rst │ ├───token.rst │ ├───spamfilter-py.test_spamfilter.rst │ └───html ... 目录并运行docs以基于根sphinx-apidoc -o . ..目录生成.rst文件。我已将以下行添加spamfilter

conf.py

和我生成sys.path.insert(0,os.path.abspath('..')) 如下:

modules.rst

spamfilter-py ============= .. toctree:: :maxdepth: 4 sample spamfilter token 目录中任何内容的html均不会生成。如果我尝试将can_it_handle_folders添加到toctree,则会收到can_it_handle_folders/test_spamfilter错误

问题

我希望toctree contains reference to nonexisting document 'can_it_handle_folders/test_spamfilter'模块显示生成的html中。我该怎么做呢?最好的设置方法是什么?

更新:它是初始化文件

我已经隔离了该问题,它似乎是根目录中的test_spamfilter(上面带有**标记)。我不知道该如何处理。如果删除它,狮身人面像可以按照我想要的方式工作。如果我保留它,问题就变成了这个here。看来__init__.py一定是有问题的。对于每个文件,这都是我得到的错误

sys.path

我在WARNING: invalid signature for automodule ('spamfilter-py.can_it_handle_folders') WARNING: don't kNow which module to import for autodocumenting 'spamfilter-py.can_it_handle_folders' (try placing a "module" or "currentmodule" directive in the document,or giving an explicit module name) 文件中尝试了以下操作:

所有结果均导致以上相同的错误消息。除了上述每个路径的sys.path.insert(0,'..','..')))之外,我还尝试过运行sphinx-apidoc -o ./source ../..。可能是什么问题?我知道这一定是一些小的配置工作。

上下文

我绝对是Sphinx的初学者。我试图阅读该文档,但尚未解决此问题。我尝试了很多我认为显然不正确的事情。如果没有简单的答案,我将在这里添加尝试。我知道关于此还有其他堆栈溢出问题,但它们不是最近的并且没有帮助。

  • 使用PowerShell执行命令的Windows 10计算机

包含的文件

  • index.rst
sphinx-apidoc -o ./source ..
  • conf.py
Welcome to j's documentation!
=============================

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

   modules

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

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
  • 一个不起作用的rst spamfilter-py.rst:
import os
import sys
sys.path.insert(0,'..')))


# -- Project information -----------------------------------------------------

project = 'j'
copyright = '2020,k'
author = 'k'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here,as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc'
]

# Add any paths that contain templates here,relative to this directory.
templates_path = ['_templates']

# List of patterns,relative to source directory,that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Add any paths that contain custom static files (such as style sheets) here,# relative to this directory. They are copied after the builtin static files,# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

文档如下所示:

No methods or parameters

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