2012-11-23 9 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

謝謝,我編輯了答案,包括正確的語法。 –