Skip to content

Commit 6012add

Browse files
authored
Update Sphinx conf.py for the dataframe API site to use Myst (#92)
1 parent aa6fe7d commit 6012add

File tree

4 files changed

+91
-37
lines changed

4 files changed

+91
-37
lines changed

requirements.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
sphinx==3.1.1
1+
sphinx==4.3.0
22
sphinx-material==0.0.30
3-
recommonmark
3+
myst-parser
44
sphinx_markdown_tables
55
sphinx_copybutton
6+
docutils<0.18
7+
sphinx-math-dollar

spec/conf.py

+83-31
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,19 @@
1010
# add these directories to sys.path here. If the directory is relative to the
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
#
13-
# import os
14-
# import sys
15-
# sys.path.insert(0, os.path.abspath('.'))
16-
13+
import os
14+
import sys
1715
import sphinx_material
18-
from recommonmark.transform import AutoStructify
16+
sys.path.insert(0, os.path.abspath('./API_specification'))
1917

2018
# -- Project information -----------------------------------------------------
2119

2220
project = 'Python dataframe API standard'
23-
copyright = '2020, Consortium for Python Data API Standards'
21+
copyright = '2022, Consortium for Python Data API Standards'
2422
author = 'Consortium for Python Data API Standards'
2523

2624
# The full version, including alpha/beta/rc tags
27-
release = '0.1-dev'
25+
release = '2022.12-DRAFT'
2826

2927

3028
# -- General configuration ---------------------------------------------------
@@ -33,13 +31,68 @@
3331
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3432
# ones.
3533
extensions = [
36-
'recommonmark',
34+
'myst_parser',
3735
'sphinx.ext.extlinks',
3836
'sphinx.ext.intersphinx',
3937
'sphinx.ext.todo',
4038
'sphinx_markdown_tables',
4139
'sphinx_copybutton',
40+
'sphinx.ext.autosummary',
41+
'sphinx.ext.napoleon',
42+
'sphinx.ext.autodoc',
43+
'sphinx_math_dollar',
44+
'sphinx.ext.mathjax'
45+
]
46+
47+
autosummary_generate = True
48+
autodoc_typehints = 'signature'
49+
add_module_names = False
50+
napoleon_custom_sections = [('Returns', 'params_style')]
51+
default_role = 'code'
52+
53+
# Mathjax configuration:
54+
mathjax3_config = {
55+
"tex": {
56+
"inlineMath": [['\\(', '\\)']],
57+
"displayMath": [["\\[", "\\]"]],
58+
}
59+
}
60+
61+
# nitpicky = True makes Sphinx warn whenever a cross-reference target can't be
62+
# found.
63+
nitpicky = True
64+
# autodoc wants to make cross-references for every type hint. But a lot of
65+
# them don't actually refer to anything that we have a document for.
66+
nitpick_ignore = [
67+
('py:class', 'array'),
68+
('py:class', 'dataframe'),
69+
('py:class', 'device'),
70+
('py:class', 'dtype'),
71+
('py:class', 'NestedSequence'),
72+
('py:class', 'collections.abc.Sequence'),
73+
('py:class', 'PyCapsule'),
74+
('py:class', 'enum.Enum'),
75+
('py:class', 'ellipsis'),
4276
]
77+
# NOTE: this alias handling isn't used yet - added in anticipation of future
78+
# need based on array API aliases.
79+
# In dataframe_object.py we have to use aliased names for some types because they
80+
# would otherwise refer back to method objects of array
81+
autodoc_type_aliases = {
82+
'dataframe': 'dataframe',
83+
'Device': 'device',
84+
'Dtype': 'dtype',
85+
}
86+
87+
# Make autosummary show the signatures of functions in the tables using actual
88+
# Python syntax. There's currently no supported way to do this, so we have to
89+
# just patch out the function that processes the signatures. See
90+
# https://github.com/sphinx-doc/sphinx/issues/10053.
91+
import sphinx.ext.autosummary as autosummary_mod
92+
if hasattr(autosummary_mod, '_module'):
93+
# It's a sphinx deprecated module wrapper object
94+
autosummary_mod = autosummary_mod._module
95+
autosummary_mod.mangle_signature = lambda sig, max_chars=30: sig
4396

4497
# Add any paths that contain templates here, relative to this directory.
4598
templates_path = ['_templates']
@@ -49,6 +102,9 @@
49102
# This pattern also affects html_static_path and html_extra_path.
50103
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
51104

105+
# MyST options
106+
myst_heading_anchors = 3
107+
myst_enable_extensions = ["colon_fence"]
52108

53109
# -- Options for HTML output -------------------------------------------------
54110

@@ -63,7 +119,7 @@
63119
# Add any paths that contain custom static files (such as style sheets) here,
64120
# relative to this directory. They are copied after the builtin static files,
65121
# so a file named "default.css" will overwrite the builtin "default.css".
66-
html_static_path = ['_static']
122+
#html_static_path = ['_static']
67123

68124

69125
# -- Material theme options (see theme.conf for more information) ------------
@@ -75,7 +131,7 @@
75131
html_theme_options = {
76132

77133
# Set the name of the project to appear in the navigation.
78-
'nav_title': 'Python dataframe API standard',
134+
'nav_title': f'Python dataframe API standard {release}',
79135

80136
# Set you GA account ID to enable tracking
81137
#'google_analytics_account': 'UA-XXXXX',
@@ -86,15 +142,15 @@
86142

87143
# Set the color and the accent color (see
88144
# https://material.io/design/color/the-color-system.html)
89-
'color_primary': 'deep-purple',
90-
'color_accent': 'cyan',
145+
'color_primary': 'indigo',
146+
'color_accent': 'green',
91147

92148
# Set the repo location to get a badge with stats
93149
#'repo_url': 'https://github.com/project/project/',
94150
#'repo_name': 'Project',
95151

96152
"html_minify": False,
97-
"html_prettify": True,
153+
"html_prettify": False,
98154
"css_minify": True,
99155
"logo_icon": "&#xe869",
100156
"repo_type": "github",
@@ -110,20 +166,20 @@
110166
'globaltoc_includehidden': True,
111167

112168
"nav_links": [
113-
{"href": "index", "internal": True, "title": "Array API standard"},
169+
{"href": "index", "internal": True, "title": "Dataframe API standard"},
114170
{
115-
"href": "https://link-to-consortium-website",
171+
"href": "https://data-apis.org",
116172
"internal": False,
117173
"title": "Consortium for Python Data API Standards",
118174
},
119175
],
120176
"heroes": {
121-
"index": "A common API for array and tensor Python libraries",
177+
"index": "A common API for dataframe Python libraries",
122178
#"customization": "Configuration options to personalize your site.",
123179
},
124180

125-
#"version_dropdown": True,
126-
#"version_json": "_static/versions.json",
181+
"version_dropdown": True,
182+
"version_json": "../versions.json",
127183
"table_classes": ["plain"],
128184
}
129185

@@ -141,20 +197,16 @@
141197
),
142198
"durole": ("http://docutils.sourceforge.net/docs/ref/rst/" "roles.html#%s", ""),
143199
"dudir": ("http://docutils.sourceforge.net/docs/ref/rst/" "directives.html#%s", ""),
200+
"pypa": ("https://packaging.python.org/%s", ""),
144201
}
145202

146203

147-
# Enable eval_rst in markdown
204+
def process_signature(app, what, name, obj, options, signature, return_annotation):
205+
if signature:
206+
signature = signature.replace("dataframe_api._types.", "")
207+
if return_annotation:
208+
return_annotation = return_annotation.replace("dataframe_api._types.", "")
209+
return signature, return_annotation
210+
148211
def setup(app):
149-
app.add_config_value(
150-
"recommonmark_config",
151-
{"enable_math": True, "enable_inline_math": True, "enable_eval_rst": True},
152-
True,
153-
)
154-
app.add_transform(AutoStructify)
155-
app.add_object_type(
156-
"confval",
157-
"confval",
158-
objname="configuration value",
159-
indextemplate="pair: %s; configuration value",
160-
)
212+
app.connect("autodoc-process-signature", process_signature)

spec/purpose_and_scope.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ done with dataframe, with the next goals in mind:
112112
libraries for interactive use or specific domains and industries
113113
- Help user transition from one dataframe library to another
114114

115-
See the [use cases](02_use_cases.html) section for details on the exact use cases considered.
115+
See the [use cases](use_cases.md) section for details on the exact use cases considered.
116116

117117

118118
### Out-of-scope

spec/use_cases.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
This section discusses the use cases considered for the standard dataframe API.
66

7-
The goals and scope of this API are defined in the [goals](01_purpose_and_scope.html#Goals),
8-
and [scope](01_purpose_and_scope.html#Scope) sections.
7+
The goals and scope of this API are defined in the [goals](purpose_and_scope.md#Goals),
8+
and [scope](purpose_and_scope.md#Scope) sections.
99

1010
The target audience and stakeholders are presented in the
11-
[stakeholders](01_purpose_and_scope.html#Stakeholders) section.
11+
[stakeholders](purpose_and_scope.md#Stakeholders) section.
1212

1313

1414
## Types of use cases

0 commit comments

Comments
 (0)