如何获取我编写的Sphinx扩展中的配置值?

时间:2018-06-07 09:58:14

标签: python python-sphinx

我写了一个Sphinx扩展。有setup(app)功能。在里面我想要配置值。

例如:

def setup(app):
    app.add_config_value('my_key', 'default_value', 'html')
    my_key_value = <something>.conf['my_key']
    print("The value of my_key is: {}".format(my_key_value))

sphinx-build命令中,我计划通过提供my_key来覆盖-D my_key=another_value的值。

1 个答案:

答案 0 :(得分:1)

app应用程序对象(sphinx.application.Application的实例)提供配置设置作为app.config的属性。

在您的情况下,my_key_value = app.config.my_key应该有效。

参考:https://sphinx-doc.org/en/master/extdev/appapi.html#the-config-object