【问题标题】:theme theme-name doesn't have "theme" setting for customizing my theme in sphinx?主题主题名称没有用于在 sphinx 中自定义主题的“主题”设置?
【发布时间】:2020-08-18 13:29:20
【问题描述】:

我想为 python-sphinx 创建自己的主题--mytheme

tree project
project
├── build
├── make.bat
├── Makefile
├── mytheme
│   ├── static
│   │   └── style.css
│   └── theme.conf
└── source
    └── conf.py

theme.conf 中的内容:

cat  project/mytheme/theme.conf
[theme]
inherit = default
stylesheet = style.css

project/source/conf.py中的内容

cat project/source/conf.py
def setup(app):
    app.add_stylesheet('static/style.css')
    app.add_html_theme('mytheme', os.path.abspath(os.path.dirname(__file__)))

html_theme = 'mytheme'  
html_theme_path = ['.'] 

现在让我们在源代码中制作我所有的 *.rst 文件。

cd project
make html
Running Sphinx v2.4.4
loading pickled environment... done

Theme error:
theme 'mytheme' doesn't have "theme" setting
Makefile:19: recipe for target 'html' failed
make: *** [html] Error 2

如何解决?

【问题讨论】:

  • 看起来您遵循了文档sphinx-doc.org/en/master/development/theming.html 中的每一步,setup.py 除外。此外,文档没有提到如何安装您的主题,这可能是一个遗漏。配置你的setup.py 后,尝试pip install -e ."[docs]" 以可编辑模式安装你的包,然后尝试使用它。我从来没有这样做过,但是为了使用它而安装你的包是有意义的。

标签: themes customization python-sphinx


【解决方案1】:

您使用两种相互排斥的方法 - 使用文件系统中的本地主题,同时注册主题,因为它在作为 Python PyPI 包分发的主题中完成。

如果您希望某个主题成为 Sphinx 项目的一部分,此类项目特定主题的好地方是 conf.py 目录中的 _themes/,并在您的 conf 中设置 html_theme = "mytheme"html_theme_path = ["_themes"]。 py.

_themes/
    mytheme/
        static/
            css/
                main.css
        theme.conf
        layout.html
conf.py
index.rst
second.rst
third.rst
...

(借自https://blog.documatt.com/sphinx-theming/themes.html#project-specific-themes

彻底删除区块

def setup(app):
    app.add_stylesheet('static/style.css')
    app.add_html_theme('mytheme', os.path.abspath(os.path.dirname(__file__)))

add_html_theme() 用于作为包分发的主题。 add_stylesheet() 是添加额外的(不是替换现有的)样式表。主题主样式表在他们的 theme.conf stylesheet 选项中。

我在您的示例中看到的最后一个问题是您的主题继承自 default 主题。它有效,它看起来是 classic 主题 (https://www.sphinx-doc.org/en/master/usage/theming.html#builtin-themes) 的旧名称,但使用它的正式名称 - classic

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-29
    • 2023-01-28
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-24
    相关资源
    最近更新 更多