简体   繁体   English

通过 Sphinx 从脚本中获取文档字符串

[英]Get docstring from script by Sphinx

I have classical Python package structure:我有经典的 Python 包结构:

bin/
    my_script
docs/
my_package/
   ...

and I create docs with Sphinx.我用 Sphinx 创建文档。

I would like to take docstring from my_script automatically.我想自动从my_script获取文档字符串。 Is there any way to do it?有什么办法吗?

Why want I to do it?为什么要我做? I have usage information in this script and I would like to show it in documentation.我在这个脚本中有使用信息,我想在文档中显示它。

My solution - I don't think it's the best.我的解决方案 - 我认为这不是最好的。

I created __init__.py in bin directory and symlink my_script.py to my_script .我在 bin 目录中创建了__init__.py并将my_script.py符号链接到my_script Into conf.py (config of sphinx) I added:conf.py (sphinx 的配置) 中,我添加了:

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

Now I can use automodule:现在我可以使用自动模块:

.. automodule:: bin.my_script

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM