2017-08-17 43 views
0

我想将以下链接引用到我的其中一个reST文档中:https://docs.python.org/3/library/stdtypes.html#typecontextmanager。我试图使用:ref:内联指令而不是链接。我跑python -m sphinx.ext.intersphinx https://docs.python.org/3/objects.inv。结果表明,除其他事项外:如何通过sphinx链接到Python 3中的typecontextmanager标签通过sphinx

 
... 
std:label 
    23acks     Acknowledgements    : whatsnew/2.3.html#acks 
    23section-other   Other Changes and Fixes  : whatsnew/2.3.html#section-other 
... 
    typebytearray    Bytearray Objects   : library/stdtypes.html#typebytearray 
    typebytes     Bytes Objects    : library/stdtypes.html#typebytes 
typecontextmanager  Context Manager Types  : library/stdtypes.html#typecontextmanager 
    typeiter     Iterator Types    : library/stdtypes.html#typeiter 
    typememoryview   Memory Views     : library/stdtypes.html#typememoryview 
... 

加粗的URL正是我期待的,因为我的intersphinx_mapping看起来是这样的:

intersphinx_mapping = { 
    'python': ('https://docs.python.org/3', None), 
} 

我用下面的指令:

:ref:`context manager <python:typecontextmanager>` 

这似乎是指向正确的标签,但我得到以下警告:

WARNING: undefined label: python:typecontextmanager (if the link has no caption the label must precede a section header) 

:ref:被替换为字符串context manager,但没有链接。

我缺少什么?

我使用的狮身人面像1.6.3上的蟒蛇安装Python 3.6.2的

注1

我使用:ref:`with <python:with>`同样的问题,这是应该指向https://docs.python.org/3/reference/compound_stmts.html#with,根据库存线(也下std:label):

 with      The with statement   : reference/compound_stmts.html#with 

我猜测到的主要问题的解决方案将最有可能解决这一点。

注2

可能不是100%的相关性,但我可以在相同的部分链接到:py:meth:`~contextmanager.__enter__`没有任何问题。

回答

1

其中任何一个都适合我。

:ref:`python:typecontextmanager` 
:ref:`typecontextmanager <python:typecontextmanager>` 

请注意,如果您在目标周围使用尖括号,则必须包含标题。

下面是它们的渲染对我来说:

顺便说一句,我最近添加上下文管理金字塔的文档中的Glossary,我认为做得很好解释他们是什么的工作。这里的重要来源:

:ref:`With Statement Context Managers <python:context-managers>` 
:ref:`with <python:with>` 
+0

我没有看到我们的参考之间有任何根本的区别在这里。我会做一个“干净”,看看是否有帮助。 –

+0

'干净'固定它。但是,您的答案中有一些有价值的提示,因此我会选择它以保持代表流畅。 –

+1

在我对另一个问题的回答中有几个其他选项:https://stackoverflow.com/a/43908388/2214933。 Sphinx将解析后的reST文件缓存为“doctree pickles”,而不是Python源代码文件,然后写入输出。它只查找新的和已更改的文件。所以如果你没有改变你的reST文件并在上一次运行后保存它,那么输出中的变化将永远不会显示。我有时只是添加一个换行符并保存它以强制当前文件运行。 –

相关问题