-
-
Notifications
You must be signed in to change notification settings - Fork 519
/
conf.py
238 lines (198 loc) · 7.37 KB
/
conf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import json
import os
import pathlib
import param
param.parameterized.docstring_signature = False
param.parameterized.docstring_describe_params = False
from nbsite.shared_conf import *
project = 'Panel'
authors = 'Panel contributors'
copyright_years['start_year'] = '2019'
copyright = copyright_fmt.format(**copyright_years)
description = 'High-level dashboarding for python visualization libraries'
import panel
from panel.io.convert import (
BOKEH_VERSION, MINIMUM_VERSIONS, PY_VERSION, PYODIDE_VERSION,
PYSCRIPT_VERSION,
)
from panel.io.resources import CDN_DIST
PANEL_ROOT = pathlib.Path(panel.__file__).parent
version = release = base_version(panel.__version__)
js_version = json.loads((PANEL_ROOT / 'package.json').read_text())['version']
is_dev = any(ext in version for ext in ('a', 'b', 'rc'))
# For the interactivity warning box created by nbsite to point to the right
# git tag instead of the default i.e. main.
os.environ['BRANCH'] = f"v{release}"
html_static_path += ['_static']
html_css_files += [
'css/custom.css',
]
html_theme = "pydata_sphinx_theme"
html_favicon = "_static/icons/favicon.ico"
html_theme_options = {
"logo": {
"image_light": "_static/logo_horizontal_light_theme.png",
"image_dark": "_static/logo_horizontal_dark_theme.png",
},
"github_url": "https://github.com/holoviz/panel",
"icon_links": [
{
"name": "Twitter",
"url": "https://twitter.com/Panel_Org",
"icon": "fa-brands fa-twitter-square",
},
{
"name": "Discourse",
"url": "https://discourse.holoviz.org/c/panel/5",
"icon": "fa-brands fa-discourse",
},
{
"name": "Discord",
"url": "https://discord.gg/UXdtYyGVQX",
"icon": "fa-brands fa-discord",
},
],
"analytics": {"google_analytics_id": "G-L0C8PGT2LM"},
"pygment_light_style": "material",
"pygment_dark_style": "material",
"header_links_before_dropdown": 5,
'secondary_sidebar_items': [
"github-stars-button",
"panelitelink",
"page-toc",
],
}
extensions += [
'sphinx.ext.napoleon',
'nbsite.gallery',
'sphinx_copybutton',
'nbsite.pyodide'
]
napoleon_numpy_docstring = True
myst_enable_extensions = ["colon_fence", "deflist"]
gallery_endpoint = 'panel-gallery-dev' if is_dev else 'panel-gallery'
gallery_url = f'https://{gallery_endpoint}.pyviz.demo.anaconda.com'
jlite_url = 'https://pyviz-dev.github.io/panelite-dev' if is_dev else 'https://panelite.holoviz.org'
pyodide_url = 'https://pyviz-dev.github.io/panel/pyodide' if is_dev else 'https://panel.holoviz.org/pyodide'
nbsite_gallery_conf = {
'github_org': 'holoviz',
'github_project': 'panel',
'galleries': {
'reference': {
'title': 'Component Gallery',
'sections': [
'panes',
'widgets',
'layouts',
# 3 most important by expected usage. Rest alphabetically
'chat',
'global',
'indicators',
'templates',
],
'titles': {
'Vega': 'Altair & Vega',
'DeckGL': 'PyDeck & Deck.gl',
'ECharts': 'PyEcharts & ECharts',
'IPyWidget': 'ipywidgets',
'PanelCallbackHandler': 'LangChain CallbackHandler',
},
'as_pyodide': True,
'normalize_titles': False
}
},
'thumbnail_url': 'https://assets.holoviz.org/panel/thumbnails',
'deployment_url': gallery_url,
'jupyterlite_url': jlite_url,
}
if panel.__version__ != version and (PANEL_ROOT / 'dist' / 'wheels').is_dir():
py_version = panel.__version__.replace("-dirty", "")
panel_req = f'./wheels/panel-{py_version}-py3-none-any.whl'
bokeh_req = f'./wheels/bokeh-{BOKEH_VERSION}-py3-none-any.whl'
else:
panel_req = f'{CDN_DIST}wheels/panel-{PY_VERSION}-py3-none-any.whl'
bokeh_req = f'{CDN_DIST}wheels/bokeh-{BOKEH_VERSION}-py3-none-any.whl'
def get_requirements():
with open('pyodide_dependencies.json') as deps:
dependencies = json.load(deps)
requirements = {}
for src, deps in dependencies.items():
if deps is None:
continue
src = src.replace('.ipynb', '').replace('.md', '')
for name, min_version in MINIMUM_VERSIONS.items():
if any(name in req for req in deps):
deps = [f'{name}>={min_version}' if name in req else req for req in deps]
requirements[src] = deps
return requirements
nbsite_pyodide_conf = {
'PYODIDE_URL': f'https://cdn.jsdelivr.net/pyodide/{PYODIDE_VERSION}/full/pyodide.js',
'requirements': [bokeh_req, panel_req, 'pyodide-http'],
'requires': get_requirements()
}
templates_path += [
'_templates'
]
html_context.update({
"last_release": f"v{release}",
"github_user": "holoviz",
"github_repo": "panel",
"default_mode": "light",
"panelite_endpoint": jlite_url,
"gallery_url": gallery_url,
"pyodide_url": pyodide_url
})
nbbuild_patterns_to_take_along = ["simple.html", "*.json", "json_*"]
# Override the Sphinx default title that appends `documentation`
html_title = f'{project} v{version}'
# Patching GridItemCardDirective to be able to substitute the domain name
# in the link option.
from sphinx_design.cards import CardDirective
from sphinx_design.grids import GridItemCardDirective
orig_grid_run = GridItemCardDirective.run
def patched_grid_run(self):
app = self.state.document.settings.env.app
existing_link = self.options.get('link')
domain = getattr(app.config, 'grid_item_link_domain', None)
if self.has_content:
self.content.replace('|gallery-endpoint|', domain)
if existing_link and domain:
new_link = existing_link.replace('|gallery-endpoint|', domain)
self.options['link'] = new_link
return list(orig_grid_run(self))
GridItemCardDirective.run = patched_grid_run
orig_card_run = CardDirective.run
def patched_card_run(self):
app = self.state.document.settings.env.app
existing_link = self.options.get('link')
domain = getattr(app.config, 'grid_item_link_domain', None)
if existing_link and domain:
new_link = existing_link.replace('|gallery-endpoint|', domain)
self.options['link'] = new_link
return orig_card_run(self)
CardDirective.run = patched_card_run
def _get_pyodide_version():
if PYODIDE_VERSION.startswith("v"):
return PYODIDE_VERSION[1:]
raise NotImplementedError(F"{PYODIDE_VERSION=} is not valid")
def update_versions(app, docname, source):
# Inspired by: https://stackoverflow.com/questions/8821511
version_replace = {
"{{PANEL_VERSION}}" : PY_VERSION,
"{{BOKEH_VERSION}}" : BOKEH_VERSION,
"{{PYSCRIPT_VERSION}}" : PYSCRIPT_VERSION,
"{{PYODIDE_VERSION}}" : _get_pyodide_version(),
}
for old, new in version_replace.items():
source[0] = source[0].replace(old, new)
def setup(app) -> None:
try:
from nbsite.paramdoc import param_formatter, param_skip
app.connect('autodoc-process-docstring', param_formatter)
app.connect('autodoc-skip-member', param_skip)
except ImportError:
print('no param_formatter (no param?)')
app.connect('source-read', update_versions)
nbbuild.setup(app)
app.add_config_value('grid_item_link_domain', '', 'html')
grid_item_link_domain = gallery_endpoint