作为构建命令的一部分更改狮身人面像 conf.py 中的变量

Change variable in sphinx conf.py as part of build command

我有一个带有 conf.py 的 Sphinx 项目,我在其中使用一个变量来指定我的产品名称,如下所示:

device_name = "ProductName"
rst_epilog = f".. |device_name| replace:: {device_name}"

我希望能够在我的构建过程中修改 ProductName 的值作为我的 .bat 文件的一部分,因为我正在构建同一个项目两次,我的两个产品各一次:

sphinx-build  -t ce2 -b html -d _build_ce2/doctrees source _build_ce2/html -E
sphinx-build  -t ce1 -b html -d _build_ce1/doctrees source _build_ce1/html -E

有没有办法直接在构建命令中修改conf.py变量device_name

我最终使用环境变量解决了这个问题。

conf.py

# get environment variables (set as part of make .bat files)
env_device_name = os.getenv("DEVICENAME")

# set device name
if env_device_name != None:
    device_name = env_device_name
else:
    device_name = "CANedge2"  # default device name

make.bat

SET DEVICENAME=Product2
sphinx-build  -t ce2 -b html -d _build_ce2/doctrees source _build_ce2/html -E
SET DEVICENAME=Product1
sphinx-build  -t ce1 -b html -d _build_ce1/doctrees source _build_ce1/html -E