How to set Sphinx's `exclude_patterns` from the command line?

﹥>﹥吖頭↗ 提交于 2019-12-04 10:10:11

My first thought was that this was a quoting issue, quoting being notoriously difficule to get right on the Windows command line. However, I wasn't able to come up with any combination of quoting that changed the behavior at all. (the problem is easy to replicate)

Of course it could still just be some quoting issue I'm not smart enough to figure out, but I suspect this is a Sphinx bug of some kind, and hope you will report it to the Sphinx developers.

In the meantime, here's an alternate solution:

quoting from here:

There is a special object named tags available in the config file. It can be used to query and change the tags (see Including content based on tags). Use tags.has('tag') to query, tags.add('tag') and tags.remove('tag') to change

This allows you to essentially pass flags into the conf.py file from the command line, and since the conf.py file is just Python, you can use if statements to set the value of exclude_patterns conditionally based on the tags you pass in.

For example, you could pass Sphinx options like:

set SPHINXOPTS=-t foradmins

to pass the "foradmins" tag, and then check for it in your conf.py like so:

exclude_patterns = blah
if tags.has('foradmins'):
    exclude_patterns = []

That should allow you to do what you want. Good Luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!