草庐IT

sphinx-argparse

全部标签

python - 如何配置构建以使用 bin/sphinxbuilder 创建 sphinx 文档

在我的buildout.cfg文件中我有这样的代码:parts=...sphinxbuilder同一文件中的下一个:eggs=...jinja2markupsafesphinx然后,在文件末尾:[sphinxbuilder]recipe=collective.recipe.sphinxbuildersource=${buildout:directory}/docs-srcbuild=${buildout:directory}/docs我愿意:bin/buildout给出输出(通常:OK):Updatingsphinxbuilder.collective.recipe.sphinxbui

Python argparse 类似帮助的选项

我正在编写一个带有两个参数和一些选项的python脚本:scriptname[-h][-l][-q|-d]arg1arg2-q(安静)和-d(调试)选项改变冗长级别,-h选项是帮助由argparse自动创建的选项。我希望-l(列表)选项的行为类似于-h选项,因为它不需要(否则强制)存在参数并列出一些有用的信息(不同于-h选项)。实际上,这意味着可以通过以下三种方式调用脚本:scriptmane[-q|-d]arg1arg2scriptname-lscriptname-h两种可能的前进方式是:使参数可选(使用nargs='?')并添加代码以验证在所有存在-l和-h选项的情况下是否有两个参

Python argparse : type inconsistencies when combining 'choices' , 'nargs' 和 'default'

我有以下python程序:#!/usr/bin/envpythonimportargparseparser=argparse.ArgumentParser()parser.add_argument('arg',choices=['foo','bar','baz'],default='foo',nargs='*')args=parser.parse_args()print(args)如果我这样调用程序:./prog.py输出是Namespace(arg='foo')但是如果我用foo作为参数调用程序:./prog.pyfoo输出是Namespace(arg=['foo'])问题如何让ar

python - 递归地使用 Sphinx autosummary 生成 API 文档

我想使用Sphinx的autosummaryextension和templates从文档字符串递归生成API文档。我想为每个模块、类、方法、属性和函数创建单独的页面。但它根本没有检测到我的模板。事实上,如果我只是从_templates/autosummary/中删除module.rst文件,它会以与以前完全相同的方式呈现整个文件。我关注了thisSOquestion不折不扣。如果您有兴趣,thefullrepositoryisonGitHub.编辑:它似乎确实生成了一个不同的文件,我必须删除docs/_autosummary才能读取新模板。但是,现在它会生成一个带有sparsehead

python - 在 Sphinx 文档中显示字典数据

我在Python项目源代码中有一本字典,它描述了默认配置值。字典很长。我希望在Sphinx文档中看到除“查看源代码”之外的其他格式的字典,以便人们可以快速检查默认值。当与Sphinxautodoc一起使用时,Sphinx是否提供选项来将类似字典的变量格式化为人类可读的格式?我目前正在使用..automodule::转储整个模块,我在文档中将字典作为一个长字符串转储(没有换行符,pretty-print,任何东西),基本上不可读。Sphinx是否提供工具来打印出各个源代码变量的值有没有pretty-print? 最佳答案 这可能不是最

python - 以 sphinx.autodoc 格式解析函数文档字符串

我在Python中有很多这样的函数:deffoobar(one,two):"""Myfunction.:paramintone:Myoneargument.:paraminttwo:Mytwoargument.:rtype:Somethingnice."""return100+one+two我需要解析docstring以获得类似这样的字典:{'sdesc':'Myfunction.','params':[('one','Myoneargument.'),('two','Mytwoargument.')],'rtype':'Somethingnice.'}我可以使用sphinx.util

python - Python 3.* 中的 Sphinx 和相关导入

我有一个包含python包的目录,如下所示:--docs/index.rst--docs/...--app/__init__.py--app/foo.py我正在使用sphinx和autodocs来记录应用程序(在python3.3中)。现在,在conf.py(在docs/内),我有sys.path.insert(0,os.path.abspath('../app'))我cd进入docs/,运行makehtml这给了我SystemError:Parentmodule''notloaded,cannotperformrelativeimport所有有的模块from.fooimportBar

python - :func: and :meth: roles in Python Sphinx? 之间的行为有什么区别

位于http://www.sphinx-doc.org/en/stable/domains.html#cross-referencing-python-objects的Sphinx文档说,:py:func:ReferenceaPythonfunction;dottednamesmaybeused.Theroletextneedsnotincludetrailingparenthesestoenhancereadability;theywillbeaddedautomaticallybySphinxiftheadd_function_parenthesesconfigvalueisTru

python - 如何更改 argparse 中的文本 "optional arguments"

出于某种原因,我不在我的程序中使用位置参数,而是仅接受“可选”参数,通过narg='?'或action等工具控制参数是否真正可选='store_true'。因此,帮助文本中的“可选参数”会产生误导。我可以将它简单地显示为“参数”吗?谢谢。 最佳答案 好吧,查看argparse源代码,在我看来,它就像覆盖parser._optionals的title一样简单,就像这样:parser._optionals.title="mymandatoryarguments,theyareactuallyoptionals,butI'llcheckf

Python 调用使用 argparser 的模块

这可能是一个愚蠢的问题,但我有一个python脚本,当前使用argparser接受一堆参数,我想将这个脚本作为另一个python脚本中的模块加载,这很好。但是我不确定如何调用模块,因为没有定义函数;如果我只是从cmd调用它,我还能像以前那样调用它吗?这是子脚本:importargparseasapfromsubprocessimportPopen,PIPEparser=ap.ArgumentParser(description='Gathersparameters.')parser.add_argument('-f',metavar='--file',type=ap.FileType(