【问题标题】:Python Sphinx accessing the html_context from within conf.pyPython Sphinx 从 conf.py 中访问 html_context
【发布时间】:2021-09-14 15:17:56
【问题描述】:

我有一个带有 extension 的 sphinx 项目,它提供了一组值,可以在 html_context 的模板文件中访问这些值。

我想根据我的 conf.py 文件中的这些扩展提供的变量之一进行轻微修改。 sphinx 文档仅说明如何为模板提供更多 html_context 值,但没有说明如何从 conf.py 中读取扩展生成的 html_context 值。是否有一个好的方法来实现这一点,或者这些值是在 conf.py 被读取并执行后生成的?

【问题讨论】:

    标签: python-sphinx


    【解决方案1】:

    html_context 填充在主入口点中,并作为confoverrides 的一部分传递给Sphinx 对象:

    https://github.com/sphinx-doc/sphinx/blob/3d8fbd992cedf1784b106cf43ecbc452953ebe17/sphinx/cmd/build.py#L267-L277

    然后将其与来自conf.py 的实际设置相结合以创建Config 对象:

    https://github.com/sphinx-doc/sphinx/blob/3d8fbd992cedf1784b106cf43ecbc452953ebe17/sphinx/application.py#L216

    因此,据我了解,conf.py 永远不会看到这个html_context,而您所要求的也无法完成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-18
      • 2019-09-14
      • 2010-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多