-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathconf.py
More file actions
162 lines (130 loc) · 5.21 KB
/
Copy pathconf.py
File metadata and controls
162 lines (130 loc) · 5.21 KB
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
import inspect
import os
import sys
import glob
from os.path import join
import json
import vitessce
import nbclean
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = 'vitessce'
copyright = '2020, HIDIVE Lab'
author = 'HIDIVE Lab'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.linkcode',
'sphinx.ext.intersphinx',
'sphinx_rtd_theme',
'nbsphinx',
'IPython.sphinxext.ipython_console_highlighting'
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = [
'notebooks/README.md',
'notebooks/environment.yml',
'notebooks/example_configs.py',
'notebooks/data/**'
]
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_css_files = [
'stylesheet.css',
]
html_context = {
'display_github': True,
'github_user': 'vitessce',
'github_repo': 'vitessce-python',
'github_version': 'main/docs/',
}
autoclass_content = 'both'
def linkcode_resolve(domain, info):
def find_source():
# try to find the file and line number, based on code from numpy:
# https://github.com/numpy/numpy/blob/master/doc/source/conf.py#L286
obj = sys.modules[info['module']]
for part in info['fullname'].split('.'):
obj = getattr(obj, part)
fn = inspect.getsourcefile(obj)
fn = os.path.relpath(fn, start=os.path.dirname(vitessce.__file__))
source, lineno = inspect.getsourcelines(obj)
return fn, lineno, lineno + len(source) - 1
if domain != 'py' or not info['module']:
return None
try:
filename = 'vitessce/%s#L%d-L%d' % find_source()
except Exception as e:
print(str(e))
filename = info['module'].replace('.', '/') + '.py'
return f"https://github.com/{html_context['github_user']}/{html_context['github_repo']}/blob/main/{filename}"
# -- Options for intersphinx -------------------------------------------------
intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'anndata': ('https://anndata.readthedocs.io/en/latest', None),
'loompy': ('http://linnarssonlab.org/loompy/', None),
}
# -- Options for nbsphinx -------------------------------------------------
nbsphinx_execute = 'never'
# -- Strip notebook output -------------------------------------------------
for filename in glob.glob(join('notebooks', "__ipynb__", '*.ipynb'), recursive=True):
ntbk = nbclean.NotebookCleaner(filename)
ntbk.clear('stderr')
ntbk.clear('output')
ntbk.remove_cells(empty=True)
ntbk.remove_cells(search_text="import marimo as mo")
ntbk.save(filename)
# Add missing metadata, to enable the code to be interpreted as Python code
# for syntax highlighting when rendered by nbsphinx.
with open(filename, 'r') as f:
ntbk_json = json.load(f)
with open(filename, 'w') as f:
if len(ntbk_json['metadata']) == 0:
# If the metadata is empty, we add the default metadata.
# This is needed for nbsphinx to render the notebook correctly.
ntbk_json['metadata'] = {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
}
json.dump(ntbk_json, f, indent=2)