2012-11-23 11 views
4

我在Windows上使用Sphinx。
我的大部分文档都是针对普通用户的,但也有一些仅供管理员使用的内容。 所以我想构建我的文档的两个版本:一个完整​​的版本,第二个版本的“管理”页面排除在外。如何从命令行设置Sphinx的`exclude_patterns`?

我为此使用了exclude_patterns in the build configuration
到目前为止,它的工作。在每个子文件夹的名称包含当我把这个到conf.py文件“管理员”被忽略的每个文件:

exclude_patterns = ['**/*admin*'] 

的问题是,我想运行构建一次获得两个版本。

我现在想要做的是运行make.bat两次,并在每次运行时提供不同的参数。
根据the documentation,我可以通过设置BUILDDIRSPHINXOPTS变量来实现此目的。

所以现在我有一个build.bat,看起来是这样的:当我从狮身人面像生成make.bat文件中删除线set BUILDDIR=build

path=%path%;c:\python27\scripts 

rem BUILD ADMIN DOCS 
set SPHINXOPTS= 
set BUILDDIR=c:\build\admin 
call make clean 
call make html 

rem BUILD USER DOCS 
set SPHINXOPTS=-D exclude_patterns=['**/*admin*'] 
set BUILDDIR=c:\build\user 
call make clean 
call make html 

pause 

构建在两个不同的目录工作。

但是,排除模式确实不是的工作。
上面列出的批处理文件输出本作的第二个版本(一个与排除模式):

Making output directory... 
Running Sphinx v1.1.3 
loading translations [de]... done 
loading pickled environment... not yet created 

Exception occurred: 
    File "C:\Python27\lib\site-packages\sphinx-1.1.3-py2.7.egg\sphinx\environment. 
py", line 495, in find_files 
    ['**/' + d for d in config.exclude_dirnames] + 
TypeError: coercing to Unicode: need string or buffer, list found 
The full traceback has been saved in c:\users\myusername\appdata\local\temp\sphinx-err-kmihxk.log, if you want to report the issue to the developers. 
Please also report this if it was a user error, so that a better error message can be provided next time. 
Either send bugs to the mailing list at <http://groups.google.com/group/sphinx-dev/>, 
or report them in the tracker at <http://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks! 

我在做什么错?
sphinx-build命令行中exclude_patterns的语法与conf.py文件中的语法不同吗?
还是有更好的方法来一步建立两个不同的版本?

回答

8

我的第一个想法是,这是一个引用问题,引用臭名昭着的difficule来获取正确的Windows命令行。但是,我无法想出任何改变行为的引用组合。 (这个问题很容易复制)

当然,它可能仍然只是一些引用问题我不够聪明想弄清楚,但我怀疑这是某种狮身人面像的错误,并希望你会报告它给狮身人面像开发者。

在此期间,这里是一个替代的解决方案:

here报价:

有一个名为在配置文件中tags可用的特殊对象。它可以用来查询和更改标签(请参阅包含基于标签的内容)。使用tags.has('tag')查询,tags.add('tag')tags.remove('tag')改变

这使你完全传递参数到命令行的conf.py文件,并且由于conf.py文件仅仅是Python中,你可以使用if语句设置的值。的exclude_patterns有条件根据您在通过标签

例如,你可以通过Sphinx的选项,如:

集SPHINXOPTS = -t foradmin小号

通过了“foradmins”标签,然后选中它在您conf.py像这样:

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

这应该让你做你想要的。祝你好运!

+1

顺便说一句,不排除任何东西的正确语法是'exclude_patterns = []' –

+0

谢谢,我编辑了答案,包括正确的语法。 –