-
Notifications
You must be signed in to change notification settings - Fork 23
/
conf.py
194 lines (163 loc) · 6.86 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
# 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('.'))
# List all organization extensions
import os
import pathlib
import re
import recommonmark
import requests
from datetime import datetime
from recommonmark.transform import AutoStructify
HERE = pathlib.Path(__file__).parent
GET_REPOS = "https://api.github.com/orgs/jupyterlab-contrib/repos"
GET_REPO = "https://api.github.com/repos/jupyterlab-contrib/"
REPO_BADGE = "[![GitHub Repo stars](https://img.shields.io/github/stars/jupyterlab-contrib/{name}?style=social)]({html_url})"
TOKEN = os.getenv("GITHUB_TOKEN")
footer = (HERE / "extensions.tpl").read_text()
header = """# List of extensions and tools
## Extensions in this organization
The extensions hosted in this organization.
"""
default_headers = {}
if TOKEN is not None:
default_headers["authorization"] = f"Bearer {TOKEN}"
try:
repos = requests.get(
GET_REPOS,
headers={**default_headers, "Accept": "application/vnd.github.v3+json"},
params={"per_page": 100},
)
data = repos.json()
extensions = ""
for repo in sorted(data, key=lambda r: r["name"]):
if isinstance(repo, str):
raise ValueError(data["message"])
if "github" in repo["name"] or repo["archived"]:
continue # Skip special repositories and archived ones
try:
response = requests.get(
GET_REPO + repo["name"],
headers={**default_headers, "Accept": "application/vnd.github.v3+json"}
)
repo_attributes = response.json()
description = repo_attributes.get("description", "")
readme = requests.get(
repo["contents_url"].replace("{+path}", "README.md"),
headers={
**default_headers,
"Accept": "application/vnd.github.VERSION.raw",
},
)
filename = repo["name"]
badge = REPO_BADGE.format(name=repo["name"], html_url=repo["html_url"])
readme_content = re.sub(r"\n\n", f"\n\n{badge}", readme.text, count=1)
(HERE / (filename + ".md")).write_text(readme_content)
extensions += f"\n* [{filename.replace('_', ' ')}]({filename}.md): {description}"
except BaseException as err:
print(err)
print(f"Fail to get README for {filename}.")
except BaseException as err:
print(err)
print("Fail to get organization repositories")
finally:
(HERE / "extensions.md").write_text(header + extensions + footer)
# -- Project information -----------------------------------------------------
project = "jupyterlab-contrib"
year = datetime.strftime(datetime.now(), "%Y")
copyright = f"2020-{year}, JupyterLab Contrib Team"
author = "JupyterLab Contrib Team"
# The full version, including alpha/beta/rc tags
release = "1.0.0"
# -- 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 = [
"recommonmark",
# Auto-generate section labels.
"sphinx.ext.autosectionlabel",
"sphinx_markdown_tables",
]
# 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 = ["_build", "Thumbs.db", ".DS_Store"]
# Prefix document path to section labels, otherwise autogenerated labels would look like 'heading'
# rather than 'path/to/file:heading'
autosectionlabel_prefix_document = True
source_suffix = [".rst", ".md"]
# -- 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_material"
html_copy_source = False
# 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_sidebars = {
"**": ["logo-text.html", "globaltoc.html", "localtoc.html", "searchbox.html"]
}
# Material theme options (see theme.conf for more information)
html_theme_options = {
# Set the name of the project to appear in the navigation.
"nav_title": "JupyterLab Unofficial Extensions & Tools",
"nav_links": [
{
"href": "https://jupyterlab.readthedocs.io/en/stable/",
"title": "JupyterLab Documentation",
"internal": False,
},
{
"href": "https://jupyter-server.readthedocs.io/en/stable/",
"title": "Jupyter Server Documentation",
"internal": False,
},
{
"href": "https://github.com/jupyterlab-contrib/jupyterlab-contrib.github.io/issues/new?labels=transfer&template=transfer-repository-to-this-organization.md",
"title": "Transfer your extension",
"internal": False,
},
{
"href": "https://github.com/jupyterlab-contrib/jupyterlab-contrib.github.io/issues/new?template=help-with-maintenance.md",
"title": "I want to help",
"internal": False,
},
],
"master_doc": False,
# Set you GA account ID to enable tracking
# 'google_analytics_account': 'UA-XXXXX',
# Specify a base_url used to generate sitemap.xml. If not
# specified, then no sitemap will be built.
"base_url": "https://jupyterlab-contrib.github.io",
# Set the color and the accent color
"color_primary": "deep-orange",
"color_accent": "orange",
# Set the repo location to get a badge with stats
"repo_url": "https://github.com/jupyterlab-contrib/jupyterlab-contrib.github.io",
"repo_name": "jupyterlab-contrib",
# Visible levels of the global TOC; -1 means unlimited
"globaltoc_depth": 2,
# If False, expand all TOC entries
"globaltoc_collapse": True,
# If True, show hidden TOC entries
"globaltoc_includehidden": False,
}
html_logo = "logo.png"
def setup(app):
app.add_config_value("recommonmark_config", {"enable_auto_toc_tree": True}, True)
app.add_transform(AutoStructify)