加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 如何从命令行设置Sphinx的`exclude_patterns`?

发布时间:2020-12-14 02:04:52 所属栏目:Windows 来源:网络整理
导读:我在 Windows上使用Sphinx. 我的大多数文档都是针对普通用户的,但有一些子页面仅包含管理员的内容. 所以我想构建我的文档的两个版本:完整版本和排除“管理”页面的第二个版本. 我用了 exclude_patterns in the build configuration. 到目前为止,它的确有效.
我在 Windows上使用Sphinx.
我的大多数文档都是针对普通用户的,但有一些子页面仅包含管理员的内容.
所以我想构建我的文档的两个版本:完整版本和排除“管理”页面的第二个版本.

我用了exclude_patterns in the build configuration.
到目前为止,它的确有效.当我将其放入conf.py文件中时,将忽略名称中包含“admin”的每个子文件夹中的每个文件:

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

问题是我想运行一次构建以获得两个版本.

我现在要做的是运行make.bat两次,并在每次运行时提供不同的参数.
根据the documentation,我可以通过设置BUILDDIR和SPHINXOPTS变量来实现这一点.

所以现在我有一个看起来像这样的build.bat:

path=%path%;c:python27scripts

rem BUILD ADMIN DOCS
set SPHINXOPTS=
set BUILDDIR=c:buildadmin
call make clean
call make html

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

pause

当我从sphinx生成的make.bat文件中删除行集BUILDDIR = build时,两个不同目录中的构建工作.

但是,排除模式不起作用.
上面列出的批处理文件为第二个构建(具有排除模式的那个)输出:

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

Exception occurred:
  File "C:Python27libsite-packagessphinx-1.1.3-py2.7.eggsphinxenvironment.
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:usersmyusernameappdatalocaltempsphinx-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文件中的语法不同?
或者是否有更好的方法一步构建两个不同的版本?

解决方法

我的第一个想法是,这是一个引用问题,引用着名的难以在Windows命令行上运行.但是,我无法想出任何改变行为的引用组合. (问题很容易复制)

当然它可能仍然只是一些引用问题,我不够聪明,但我怀疑这是某种Sphinx漏洞,并希望你将它报告给Sphinx开发人员.

与此同时,这是另一种解决方案:

引自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

这允许您基本上从命令行将标志传递到conf.py文件中,并且由于conf.py文件只是Python,因此您可以使用if语句根据传入的标记有条件地设置exclude_patterns的值.

例如,您可以传递Sphinx选项,例如:

set SPHINXOPTS=-t foradmins

传递“foradmins”标签,然后在conf.py中检查它,如下所示:

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

这应该可以让你做你想做的事.祝好运!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读