I want to create my own theme--mytheme
for python-sphinx.
tree project
project
├── build
├── make.bat
├── Makefile
├── mytheme
│ ├── static
│ │ └── style.css
│ └── theme.conf
└── source
└── conf.py
Content in theme.conf:
cat project/mytheme/theme.conf
[theme]
inherit = default
stylesheet = style.css
Conent in 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 = ['.']
Now let's make all my *.rst file in source.
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
How to fix it ?
You use two mutually exclusive approaches - using local theme from filesystem, and at the same time register theme as it is done in themes distributed as Python PyPI package.
If you want a theme to be a part of the Sphinx project, good place for such project-specific themes is _themes/
in the directory with conf.py, and set html_theme = "mytheme"
and html_theme_path = ["_themes"]
in your conf.py.
_themes/
mytheme/
static/
css/
main.css
theme.conf
layout.html
conf.py
index.rst
second.rst
third.rst
...
(borrowed from https://blog.documatt.com/sphinx-theming/themes.html#project-specific-themes)
Completely delete block
def setup(app):
app.add_stylesheet('static/style.css')
app.add_html_theme('mytheme', os.path.abspath(os.path.dirname(__file__)))
add_html_theme()
it is for themes distributed as a package. add_stylesheet()
is to add additional (not replace existing) stylesheet. Themes main stylesheet is in their theme.conf stylesheet
option.
The last issue I see in your example is your theme inherit from default
theme. It works, it looks it's an old name for classic
theme (https://www.sphinx-doc.org/en/master/usage/theming.html#builtin-themes), but use its official name - classic
.