Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
holoviz
GitHub Repository: holoviz/panel
Path: blob/main/doc/conf.py
2004 views
1
import json
2
import os
3
import pathlib
4
5
from typing import Any
6
7
import param
8
9
param.parameterized.docstring_signature = False
10
param.parameterized.docstring_describe_params = False
11
12
from nbsite.shared_conf import *
13
14
project = 'Panel'
15
authors = 'Panel contributors'
16
copyright_years['start_year'] = '2019'
17
copyright = copyright_fmt.format(**copyright_years)
18
description = 'High-level dashboarding for python visualization libraries'
19
20
import panel
21
22
from panel.io.convert import (
23
BOKEH_VERSION, MINIMUM_VERSIONS, PY_VERSION, PYODIDE_VERSION,
24
PYSCRIPT_VERSION,
25
)
26
from panel.io.resources import CDN_ROOT
27
28
PANEL_ROOT = pathlib.Path(panel.__file__).parent
29
30
version = release = base_version(panel.__version__)
31
js_version = json.loads((PANEL_ROOT / 'package.json').read_text())['version']
32
33
is_dev = any(ext in version for ext in ('a', 'b', 'rc'))
34
35
# For the interactivity warning box created by nbsite to point to the right
36
# git tag instead of the default i.e. main.
37
os.environ['BRANCH'] = f"v{release}"
38
39
html_static_path += ['_static']
40
41
html_css_files += [
42
'css/custom.css',
43
]
44
45
html_theme = "pydata_sphinx_theme"
46
html_favicon = "_static/icons/favicon.ico"
47
48
current_release = panel.__version__ # Current release version variable
49
50
announcement_text = f"Panel {current_release} has just been released! Check out the <a href='https://panel.holoviz.org/about/releases.html'>release notes</a> and support Panel by giving it a 🌟 on <a href='https://github.com/holoviz/panel'>Github</a>."
51
52
53
html_theme_options = {
54
"logo": {
55
"image_light": "_static/logo_horizontal_light_theme.png",
56
"image_dark": "_static/logo_horizontal_dark_theme.png",
57
},
58
"github_url": "https://github.com/holoviz/panel",
59
"icon_links": [
60
{
61
"name": "Twitter",
62
"url": "https://twitter.com/Panel_Org",
63
"icon": "fa-brands fa-twitter-square",
64
},
65
{
66
"name": "Discourse",
67
"url": "https://discourse.holoviz.org/c/panel/5",
68
"icon": "fa-brands fa-discourse",
69
},
70
{
71
"name": "Discord",
72
"url": "https://discord.gg/UXdtYyGVQX",
73
"icon": "fa-brands fa-discord",
74
},
75
],
76
"pygments_light_style": "material",
77
"pygments_dark_style": "material",
78
"header_links_before_dropdown": 5,
79
'secondary_sidebar_items': [
80
"github-stars-button",
81
"panelitelink",
82
"page-toc",
83
],
84
"announcement": announcement_text,
85
}
86
87
88
extensions = [
89
'numpydoc',
90
'bokeh.sphinxext.bokeh_plot',
91
'myst_parser',
92
'sphinx_design',
93
'sphinx.ext.autodoc',
94
'sphinx.ext.doctest',
95
'sphinx.ext.intersphinx',
96
'sphinx.ext.coverage',
97
'sphinx.ext.mathjax',
98
'sphinx.ext.ifconfig',
99
'sphinx.ext.linkcode',
100
'sphinx.ext.inheritance_diagram',
101
'sphinx_copybutton',
102
'sphinxext.rediraffe',
103
'nbsite.gallery',
104
'nbsite.pyodide',
105
'nbsite.analytics',
106
]
107
108
numpydoc_show_inherited_class_members = False
109
numpydoc_class_members_toctree = False
110
napoleon_numpy_docstring = True
111
112
autodoc_mock_imports = ["panel.pane.vtk"]
113
114
myst_enable_extensions = ["colon_fence", "deflist"]
115
116
gallery_endpoint = 'panel-gallery-dev' if is_dev else 'panel-gallery'
117
gallery_url = f'https://{gallery_endpoint}.holoviz-demo.anaconda.com'
118
jlite_url = 'https://holoviz-dev.github.io/panelite-dev/lab' if is_dev else 'https://panelite.holoviz.org/lab'
119
pyodide_url = 'https://holoviz-dev.github.io/panel/pyodide' if is_dev else 'https://panel.holoviz.org/pyodide'
120
121
rediraffe_redirects = {
122
# Removal of the developer testing page
123
'developer_guide/testing': 'developer_guide/index',
124
'user_guide/APIs': 'explanation/api/index',
125
'user_guide/Pipelines': 'how_to/pipeline/index',
126
'user_guide/Templates': 'how_to/templates/index',
127
'user_guide/Server_Configuration': 'how_to/server/index',
128
}
129
130
nbsite_analytics = {
131
'goatcounter_holoviz': True,
132
}
133
134
nbsite_gallery_conf = {
135
'github_org': 'holoviz',
136
'github_project': 'panel',
137
'galleries': {
138
'reference': {
139
'title': 'Component Gallery',
140
'extensions': ['*.ipynb', '*.py', '*.md'],
141
'sections': [
142
'panes',
143
'widgets',
144
'layouts',
145
# 3 most important by expected usage. Rest alphabetically
146
'chat',
147
'global',
148
'indicators',
149
'templates',
150
'custom_components',
151
],
152
'titles': {
153
'Vega': 'Altair & Vega',
154
'DeckGL': 'PyDeck & Deck.gl',
155
'ECharts': 'PyEcharts & ECharts',
156
'IPyWidget': 'ipywidgets',
157
'PanelCallbackHandler': 'LangChain CallbackHandler',
158
},
159
'as_pyodide': True,
160
'normalize_titles': False,
161
}
162
},
163
'thumbnail_url': 'https://assets.holoviz.org/panel/thumbnails',
164
'deployment_url': gallery_url,
165
'jupyterlite_url': jlite_url,
166
'only_use_existing': True,
167
}
168
169
if panel.__version__ != version and (PANEL_ROOT / 'dist' / 'wheels').is_dir():
170
py_version = panel.__version__.replace("-dirty", "")
171
panel_req = f'./wheels/panel-{py_version}-py3-none-any.whl'
172
bokeh_req = f'./wheels/bokeh-{BOKEH_VERSION}-py3-none-any.whl'
173
else:
174
panel_req = f'{CDN_ROOT}wheels/panel-{PY_VERSION}-py3-none-any.whl'
175
bokeh_req = f'{CDN_ROOT}wheels/bokeh-{BOKEH_VERSION}-py3-none-any.whl'
176
177
def get_requirements():
178
with open('pyodide_dependencies.json') as deps:
179
dependencies = json.load(deps)
180
requirements = {}
181
for src, deps in dependencies.items():
182
if deps is None:
183
continue
184
src = src.replace('.ipynb', '').replace('.md', '')
185
for name, min_version in MINIMUM_VERSIONS.items():
186
if any(name in req for req in deps):
187
deps = [f'{name}>={min_version}' if name in req else req for req in deps]
188
requirements[src] = deps
189
return requirements
190
191
192
html_js_files = [
193
(None, {'body': '{"shimMode": true}', 'type': 'esms-options'}),
194
f'https://cdn.holoviz.org/panel/{js_version}/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js',
195
]
196
197
nbsite_pyodide_conf = {
198
'PYODIDE_URL': f'https://cdn.jsdelivr.net/pyodide/{PYODIDE_VERSION}/full/pyodide.js',
199
'requirements': [bokeh_req, panel_req, 'pyodide-http'],
200
'requires': get_requirements(),
201
}
202
203
templates_path += [
204
'_templates'
205
]
206
207
html_context.update({
208
"last_release": f"v{release}",
209
"github_user": "holoviz",
210
"github_repo": "panel",
211
"default_mode": "light",
212
"panelite_endpoint": jlite_url,
213
"gallery_url": gallery_url,
214
"pyodide_url": pyodide_url
215
})
216
217
nbbuild_patterns_to_take_along = ["simple.html", "*.json", "json_*"]
218
219
# Override the Sphinx default title that appends `documentation`
220
html_title = f'{project} v{version}'
221
222
# Ensure the global version string includes the SHA to ensure the service
223
# worker is invalidated on builds between tags
224
if is_dev:
225
version = panel.__version__
226
227
# Patching GridItemCardDirective to be able to substitute the domain name
228
# in the link option.
229
from sphinx_design.cards import CardDirective
230
from sphinx_design.grids import GridItemCardDirective
231
232
orig_grid_run = GridItemCardDirective.run
233
234
def patched_grid_run(self):
235
app = self.state.document.settings.env.app
236
existing_link = self.options.get('link')
237
domain = getattr(app.config, 'grid_item_link_domain', None)
238
if self.has_content:
239
self.content.replace('|gallery-endpoint|', domain)
240
if existing_link and domain:
241
new_link = existing_link.replace('|gallery-endpoint|', domain)
242
self.options['link'] = new_link
243
return list(orig_grid_run(self))
244
245
GridItemCardDirective.run = patched_grid_run
246
247
orig_card_run = CardDirective.run
248
249
def patched_card_run(self):
250
app = self.state.document.settings.env.app
251
existing_link = self.options.get('link')
252
domain = getattr(app.config, 'grid_item_link_domain', None)
253
if existing_link and domain:
254
new_link = existing_link.replace('|gallery-endpoint|', domain)
255
self.options['link'] = new_link
256
return orig_card_run(self)
257
258
CardDirective.run = patched_card_run
259
260
def _get_pyodide_version():
261
if PYODIDE_VERSION.startswith("v"):
262
return PYODIDE_VERSION[1:]
263
raise NotImplementedError(F"{PYODIDE_VERSION=} is not valid")
264
265
def update_versions(app, docname, source):
266
from panel.models.tabulator import TABULATOR_VERSION
267
from panel.models.vizzu import VIZZU_VERSION
268
269
# Inspired by: https://stackoverflow.com/questions/8821511
270
version_replace = {
271
"{{PANEL_VERSION}}" : PY_VERSION,
272
"{{BOKEH_VERSION}}" : BOKEH_VERSION,
273
"{{PYSCRIPT_VERSION}}" : PYSCRIPT_VERSION,
274
"{{PYODIDE_VERSION}}" : _get_pyodide_version(),
275
"{{TABULATOR_VERSION}}" : TABULATOR_VERSION,
276
"{{TABULATOR_VERSION_WWW}}" : ".".join(TABULATOR_VERSION.split(".")[:2]),
277
"{{VIZZU_VERSION}}" : VIZZU_VERSION,
278
}
279
280
for old, new in version_replace.items():
281
source[0] = source[0].replace(old, new)
282
283
284
def setup_mystnb(app):
285
from myst_nb.core.config import NbParserConfig
286
from myst_nb.sphinx_ import (
287
HideCodeCellNode, HideInputCells, SelectMimeType,
288
)
289
from myst_nb.sphinx_ext import create_mystnb_config
290
291
_UNSET = "--unset--"
292
for name, default, field in NbParserConfig().as_triple():
293
if not field.metadata.get("sphinx_exclude"):
294
# TODO add types?
295
app.add_config_value(f"nb_{name}", default, "env", Any) # type: ignore[arg-type]
296
if "legacy_name" in field.metadata:
297
app.add_config_value(
298
f"{field.metadata['legacy_name']}",
299
_UNSET,
300
"env",
301
Any, # type: ignore[arg-type]
302
)
303
app.add_config_value("nb_render_priority", _UNSET, "env", Any) # type: ignore[arg-type]
304
create_mystnb_config(app)
305
306
# add post-transform for selecting mime type from a bundle
307
app.add_post_transform(SelectMimeType)
308
309
# setup collapsible content
310
app.add_post_transform(HideInputCells)
311
HideCodeCellNode.add_to_app(app)
312
313
314
315
def setup(app) -> None:
316
try:
317
from nbsite.paramdoc import param_formatter, param_skip
318
app.connect('autodoc-process-docstring', param_formatter)
319
app.connect('autodoc-skip-member', param_skip)
320
except ImportError:
321
print('no param_formatter (no param?)')
322
323
app.connect('builder-inited', setup_mystnb)
324
325
app.connect('source-read', update_versions)
326
nbbuild.setup(app)
327
app.add_config_value('grid_item_link_domain', '', 'html')
328
329
# hv_sidebar_dropdown
330
app.add_config_value('nbsite_hv_sidebar_dropdown', {}, 'html')
331
app.connect("html-page-context", add_hv_sidebar_dropdown_context)
332
333
334
grid_item_link_domain = gallery_endpoint
335
336