Skip to content

Commit 0f8ce71

Browse files
committed
修复文档构建
1 parent 99db484 commit 0f8ce71

File tree

8 files changed

+202
-6
lines changed

8 files changed

+202
-6
lines changed

.github/workflows/pages.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ jobs:
4242
cache-dependency-path: "pyproject.toml"
4343
- name: 🔧 Build HTML
4444
run: |
45-
sudo apt-get install graphviz doxygen
4645
apt-get update && sudo apt-get upgrade
4746
pip install --upgrade pip
4847
pip install .[doc] --upgrade
49-
conda install -c conda-forge pandoc compilers cppyy pandoc llvm
48+
conda install -c conda-forge pandoc compilers cppyy pandoc llvm doxygen
49+
conda install anaconda::graphviz
5050
invoke doc
5151
- name: Setup Pages
5252
uses: actions/configure-pages@main

doc/_ext/gallery_directive.py

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
"""A directive to generate a gallery of images from structured data.
2+
3+
Generating a gallery of images that are all the same size is a common
4+
pattern in documentation, and this can be cumbersome if the gallery is
5+
generated programmatically. This directive wraps this particular use-case
6+
in a helper-directive to generate it with a single YAML configuration file.
7+
8+
It currently exists for maintainers of the pydata-sphinx-theme,
9+
but might be abstracted into a standalone package if it proves useful.
10+
"""
11+
12+
from pathlib import Path
13+
from typing import Any, ClassVar, Dict, List
14+
15+
from docutils import nodes
16+
from docutils.parsers.rst import directives
17+
from sphinx.application import Sphinx
18+
from sphinx.util import logging
19+
from sphinx.util.docutils import SphinxDirective
20+
from yaml import safe_load
21+
22+
23+
logger = logging.getLogger(__name__)
24+
25+
26+
TEMPLATE_GRID = """
27+
`````{{grid}} {columns}
28+
{options}
29+
30+
{content}
31+
32+
`````
33+
"""
34+
35+
GRID_CARD = """
36+
````{{grid-item-card}} {title}
37+
{options}
38+
39+
{content}
40+
````
41+
"""
42+
43+
44+
class GalleryGridDirective(SphinxDirective):
45+
"""A directive to show a gallery of images and links in a Bootstrap grid.
46+
47+
The grid can be generated from a YAML file that contains a list of items, or
48+
from the content of the directive (also formatted in YAML). Use the parameter
49+
"class-card" to add an additional CSS class to all cards. When specifying the grid
50+
items, you can use all parameters from "grid-item-card" directive to customize
51+
individual cards + ["image", "header", "content", "title"].
52+
53+
Danger:
54+
This directive can only be used in the context of a Myst documentation page as
55+
the templates use Markdown flavored formatting.
56+
"""
57+
58+
name = "gallery-grid"
59+
has_content = True
60+
required_arguments = 0
61+
optional_arguments = 1
62+
final_argument_whitespace = True
63+
option_spec: ClassVar[dict[str, Any]] = {
64+
# A class to be added to the resulting container
65+
"grid-columns": directives.unchanged,
66+
"class-container": directives.unchanged,
67+
"class-card": directives.unchanged,
68+
}
69+
70+
def run(self) -> List[nodes.Node]:
71+
"""Create the gallery grid."""
72+
if self.arguments:
73+
# If an argument is given, assume it's a path to a YAML file
74+
# Parse it and load it into the directive content
75+
path_data_rel = Path(self.arguments[0])
76+
path_doc, _ = self.get_source_info()
77+
path_doc = Path(path_doc).parent
78+
path_data = (path_doc / path_data_rel).resolve()
79+
if not path_data.exists():
80+
logger.info("Could not find grid data at %s.", path_data)
81+
nodes.text("No grid data found at {path_data}.")
82+
return
83+
yaml_string = path_data.read_text()
84+
else:
85+
yaml_string = "\n".join(self.content)
86+
87+
# Use all the element with an img-bottom key as sites to show
88+
# and generate a card item for each of them
89+
grid_items = []
90+
for item in safe_load(yaml_string):
91+
# remove parameters that are not needed for the card options
92+
title = item.pop("title", "")
93+
94+
# build the content of the card using some extra parameters
95+
header = f"{item.pop('header')} \n^^^ \n" if "header" in item else ""
96+
image = f"![image]({item.pop('image')}) \n" if "image" in item else ""
97+
content = f"{item.pop('content')} \n" if "content" in item else ""
98+
99+
# optional parameter that influence all cards
100+
if "class-card" in self.options:
101+
item["class-card"] = self.options["class-card"]
102+
103+
loc_options_str = "\n".join(f":{k}: {v}" for k, v in item.items()) + " \n"
104+
105+
card = GRID_CARD.format(
106+
options=loc_options_str, content=header + image + content, title=title
107+
)
108+
grid_items.append(card)
109+
110+
# Parse the template with Sphinx Design to create an output container
111+
# Prep the options for the template grid
112+
class_ = "gallery-directive" + f' {self.options.get("class-container", "")}'
113+
options = {"gutter": 2, "class-container": class_}
114+
options_str = "\n".join(f":{k}: {v}" for k, v in options.items())
115+
116+
# Create the directive string for the grid
117+
grid_directive = TEMPLATE_GRID.format(
118+
columns=self.options.get("grid-columns", "1 2 3 4"),
119+
options=options_str,
120+
content="\n".join(grid_items),
121+
)
122+
123+
# Parse content as a directive so Sphinx Design processes it
124+
container = nodes.container()
125+
self.state.nested_parse([grid_directive], 0, container)
126+
127+
# Sphinx Design outputs a container too, so just use that
128+
return [container.children[0]]
129+
130+
131+
def setup(app: Sphinx) -> Dict[str, Any]:
132+
"""Add custom configuration to sphinx app.
133+
134+
Args:
135+
app: the Sphinx application
136+
137+
Returns:
138+
the 2 parallel parameters set to ``True``.
139+
"""
140+
app.add_directive("gallery-grid", GalleryGridDirective)
141+
142+
return {
143+
"parallel_read_safe": True,
144+
"parallel_write_safe": True,
145+
}

doc/_ext/rtd_version.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
from sphinx.application import Sphinx
3+
from sphinx.util.typing import ExtensionMetadata
4+
5+
def setup(app: Sphinx) -> ExtensionMetadata:
6+
# Define the json_url for our version switcher.
7+
json_url = f"https://{app.config.project}.readthedocs.io/zh-cn/latest/_static/switcher.json"
8+
# Define the version we use for matching in the version switcher.
9+
version_match = os.environ.get("READTHEDOCS_VERSION")
10+
# If READTHEDOCS_VERSION doesn't exist, we're not on RTD
11+
# If it is an integer, we're in a PR build and the version isn't correct.
12+
# If it's "latest" → change to "dev" (that's what we want the switcher to call it)
13+
if not version_match or version_match.isdigit() or version_match == "latest":
14+
# For local development, infer the version to match from the package.
15+
if "dev" in app.config.release or "rc" in app.config.release:
16+
version_match = "dev"
17+
# We want to keep the relative reference if we are in dev mode
18+
# but we want the whole url if we are effectively in a released version
19+
json_url = "_static/switcher.json"
20+
else:
21+
version_match = f"v{app.config.release}"
22+
elif version_match == "stable":
23+
version_match = f"v{app.config.release}"
24+
app.config["html_theme_options"].update({"switcher": {
25+
"json_url": json_url,
26+
"version_match": version_match,
27+
},})
28+
# -- To demonstrate ReadTheDocs switcher -------------------------------------
29+
# This links a few JS and CSS files that mimic the environment that RTD uses
30+
# so that we can test RTD-like behavior. We don't need to run it on RTD and we
31+
# don't wanted it loaded in GitHub Actions because it messes up the lighthouse
32+
# results.
33+
if not os.environ.get("READTHEDOCS") and not os.environ.get("GITHUB_ACTIONS"):
34+
app.add_css_file(
35+
"https://assets.readthedocs.org/static/css/readthedocs-doc-embed.css"
36+
)
37+
app.add_css_file("https://assets.readthedocs.org/static/css/badge_only.css")
38+
39+
# Create the dummy data file so we can link it
40+
# ref: https://github.com/readthedocs/readthedocs.org/blob/bc3e147770e5740314a8e8c33fec5d111c850498/readthedocs/core/static-src/core/js/doc-embed/footer.js # noqa: E501
41+
app.add_js_file("rtd-data.js")
42+
app.add_js_file(
43+
"https://assets.readthedocs.org/static/javascript/readthedocs-doc-embed.js",
44+
priority=501,
45+
)
46+
return {
47+
"parallel_read_safe": True,
48+
"parallel_write_safe": True,
49+
}
File renamed without changes.
File renamed without changes.

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
html_logo = "_static/images/logo.jpg"
6969
html_title = "Sphinx xyzstyle Theme"
7070
html_copy_source = True
71-
html_favicon = "_static/images/favicon.jpg"
71+
html_favicon = "_static/images/page-logo.jfif"
7272
html_last_updated_fmt = '%Y-%m-%d, %H:%M:%S' # 文档的最后更新时间格式
7373
# 在此添加包含自定义静态文件(如样式表)的任何路径,相对于此目录。
7474
# 它们会在内置静态文件之后被复制,因此名为 "default.css" 的文件将覆盖内置的 "default.css"。

doc/draft/draft2.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@
2828

2929
访问 `main` 的返回值的方法依赖于系统:
3030

31-
````{tabbed} Windows
31+
`````{tab-set}
32+
````{tab-item} Windows
3233
```sh
3334
echo %ERRORLEVEL%
3435
```
3536
````
3637
37-
````{tabbed} Linux
38+
````{tab-item}Linux
3839
```sh
3940
echo $?
4041
```
4142
````
43+
`````
4244

4345
编译源码的命令:
4446

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ doc = [
4343
"graphviz",
4444
"sphinx-intl", # 文档国际化
4545
"sphinx-tippy",
46-
"taolib",
46+
"taolib[flows]",
4747
"breathe",
4848
]
4949

0 commit comments

Comments
 (0)