当 Python 文件无法编译时如何使用 Sphinx 自动文档
今天这个问题更加困难,因为我今天没有使用 Sphinx 主页上的搜索功能。
我有一组模块想要从文档字符串中记录下来。然而,这些不是纯 Python 脚本。它们不会按原样编译,因为它们是从在执行范围中创建新变量的 C# 应用程序运行的。
对于 Python 编译器来说,我似乎有一个未定义的方法(从技术上讲,我确实如此,直到 C# 创建 IronPython 脚本引擎并创建该方法)。
当我运行:
sphinx-build -b html output/html
我得到:
NameError: name 'injected_method' is not defined
如何让 Sphinx 忽略编译错误并生成我的文档?
编辑:
如果有人知道 Sphinx 的替代品(如 Epydoc)是否不必编译 Python 脚本来获取函数签名和文档字符串,那也会很有帮助。 Sphinx 是最好看的文档生成器,但如果必须的话我会放弃它。
This question is even harder today because I haven't had any luck using the search function on the Sphinx homepage today.
I have a group of modules that I want to be documented from the docstrings. However, these are not pure Python scripts. They won't compile as is, because they are run from a C# application that creates a new variable in the executing scope.
To the Python compiler, it looks like I have an undefined method (which, technically I do, until C# creates the IronPython script engine and creates the method).
When I run:
sphinx-build -b html output/html
I get:
NameError: name 'injected_method' is not defined
How do I get Sphinx to ignore compilation errors and just generate my documentation?
EDIT:
If anybody knows if an alternative to Sphinx (like Epydoc) does not have to compile the Python script to get the function signatures and docstrings, that would be helpful as well. Sphinx is the best looking documentation generator, but I'll abandon it if I have to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,你可以尝试:
Well, you could try:
也许您可以将injected_method定义为空函数,以便文档正常工作。您需要确保您要注入的injected_method 的定义发生在新的injected_method 存根之后。
Perhaps you could define injected_method as a empty function so that the documentation will work. You'll need to make sure that the definition of injected_method that you're injecting happens after the new injected_method stub.
好的,我找到了解决错误的方法。
在设置嵌入式脚本环境时,而不是使用:
我现在使用:
然后,在脚本中:
然后我在搜索路径中创建了一个虚拟的injected_method.py 文件,该文件是空白的。我在构建 C# 项目期间删除了虚拟文件以避免任何冲突。
Okay, I found a way to get around the Errors.
When setting up the embedded scripting environment, instead of using:
I am now using:
And then, in the script:
Then I created a dummy injected_method.py file in my search path, which is blank. I delete the dummy file during the build of my C# project to avoid any conflicts.