Skip to content

Commit f309aee

Browse files
authored
🐛 FIX: Docs build against non-html formats (executablebooks#88)
- Add CI tests against builders: html, latex and man - Fix visits to fontawesome nodes, and add warning for non-supported formats
1 parent 8c486be commit f309aee

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ jobs:
7777
- name: Run pytest
7878
run: pytest
7979

80+
docs-build-format:
81+
82+
runs-on: ubuntu-latest
83+
strategy:
84+
matrix:
85+
format: [html, latex, man]
86+
87+
steps:
88+
- uses: actions/checkout@v2
89+
- name: Set up Python 3.9
90+
uses: actions/setup-python@v2
91+
with:
92+
python-version: "3.9"
93+
- name: Install dependencies
94+
run: |
95+
python -m pip install --upgrade pip
96+
pip install -e .[rtd]
97+
- name: Build documentation
98+
run: sphinx-build -nW --keep-going -b ${{ matrix.format }} docs/ docs/_build/${{ matrix.format }}
99+
80100
publish:
81101

82102
name: Publish to PyPi

docs/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
extensions = ["myst_parser", "sphinx_design"]
99

10+
suppress_warnings = ["design.fa-build"]
11+
sd_fontawesome_latex = True
12+
1013
html_theme = os.environ.get("SPHINX_THEME", "alabaster")
1114
html_title = f"Sphinx Design ({html_theme.replace('_', '-')})"
1215

sphinx_design/icons.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
from docutils import nodes
88
from docutils.parsers.rst import directives
99
from sphinx.application import Sphinx
10+
from sphinx.util import logging
1011
from sphinx.util.docutils import SphinxDirective, SphinxRole
1112

1213
from . import compiled
14+
from .shared import WARNING_TYPE
15+
16+
logger = logging.getLogger(__name__)
1317

1418
OCTICON_VERSION = "v16.1.1"
1519

@@ -35,9 +39,9 @@ def setup_icons(app: Sphinx) -> None:
3539
fontawesome,
3640
html=(visit_fontawesome_html, depart_fontawesome_html),
3741
latex=(visit_fontawesome_latex, None),
38-
text=(None, None),
39-
man=(None, None),
40-
texinfo=(None, None),
42+
man=(visit_fontawesome_warning, None),
43+
text=(visit_fontawesome_warning, None),
44+
texinfo=(visit_fontawesome_warning, None),
4145
)
4246

4347

@@ -207,8 +211,29 @@ def add_fontawesome_pkg(app, config):
207211

208212

209213
def visit_fontawesome_latex(self, node):
214+
"""Add latex fonteawesome icon, if configured, else warn."""
210215
if self.config.sd_fontawesome_latex:
211-
self.body.append(f"\\faicon{{{node['icon_name']}}}")
216+
self.body.append(f"\\faicon{{{node['icon']}}}")
217+
else:
218+
logger.warning(
219+
"Fontawesome icons not included in LaTeX output, "
220+
f"consider 'sd_fontawesome_latex=True' [{WARNING_TYPE}.fa-build]",
221+
location=node,
222+
type=WARNING_TYPE,
223+
subtype="fa-build",
224+
)
225+
raise nodes.SkipNode
226+
227+
228+
def visit_fontawesome_warning(self, node: nodes.Element) -> None:
229+
"""Warn that fontawesome is not supported for this builder."""
230+
logger.warning(
231+
"Fontawesome icons not supported for builder: "
232+
f"{self.builder.name} [{WARNING_TYPE}.fa-build]",
233+
location=node,
234+
type=WARNING_TYPE,
235+
subtype="fa-build",
236+
)
212237
raise nodes.SkipNode
213238

214239

0 commit comments

Comments
 (0)