-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathconf.py
291 lines (241 loc) · 8.57 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# Configuration file for the Sphinx documentation builder.
# https://www.sphinx-doc.org/en/master/usage/configuration.html
from __future__ import annotations
import inspect
import os
import re
import sys
import warnings
from pathlib import Path
from typing import Any
import sphinx_autosummary_accessors
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here.
# Add py-polars directory
sys.path.insert(0, str(Path("../..").resolve()))
# -- Project information -----------------------------------------------------
project = "Polars"
author = "Ritchie Vink"
copyright = f"2025, {author}"
# -- General configuration ---------------------------------------------------
extensions = [
# Sphinx extensions
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.githubpages",
"sphinx.ext.intersphinx",
"sphinx.ext.linkcode",
"sphinx.ext.mathjax",
# Third-party extensions
"autodocsumm",
"numpydoc",
"sphinx_autosummary_accessors",
"sphinx_copybutton",
"sphinx_design",
"sphinx_favicon",
"sphinx_reredirects",
"sphinx_toolbox.more_autodoc.overloads",
]
# Render docstring text in `single backticks` as code.
default_role = "code"
maximum_signature_line_length = 88
# Below setting is used by
# sphinx-autosummary-accessors - build docs for namespace accessors like `Series.str`
# https://sphinx-autosummary-accessors.readthedocs.io/en/stable/
templates_path = ["_templates", sphinx_autosummary_accessors.templates_path]
# 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 = ["Thumbs.db", ".DS_Store"]
# Hide overload type signatures
# sphinx_toolbox - Box of handy tools for Sphinx
# https://sphinx-toolbox.readthedocs.io/en/latest/
overloads_location = ["bottom"]
# -- Extension settings ------------------------------------------------------
# sphinx.ext.intersphinx - link to other projects' documentation
# https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html
intersphinx_mapping = {
"numpy": ("https://numpy.org/doc/stable/", None),
"pandas": ("https://pandas.pydata.org/docs/", None),
"pyarrow": ("https://arrow.apache.org/docs/", None),
"python": ("https://docs.python.org/3", None),
}
# numpydoc - parse numpy docstrings
# https://numpydoc.readthedocs.io/en/latest/
# Used in favor of sphinx.ext.napoleon for nicer render of docstring sections
numpydoc_show_class_members = False
# Sphinx-copybutton - add copy button to code blocks
# https://sphinx-copybutton.readthedocs.io/en/latest/index.html
# strip the '>>>' and '...' prompt/continuation prefixes.
copybutton_prompt_text = r">>> |\.\.\. "
copybutton_prompt_is_regexp = True
# redirect empty root to the actual landing page
redirects = {"index": "reference/index.html"}
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages.
html_theme = "pydata_sphinx_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 = ["css/custom.css"] # relative to html_static_path
html_show_sourcelink = False
# key site root paths
static_assets_root = "https://raw.githubusercontent.com/pola-rs/polars-static/master"
github_root = "https://github.com/pola-rs/polars"
web_root = "https://docs.pola.rs"
# Specify version for version switcher dropdown menu
git_ref = os.environ.get("POLARS_VERSION", "main")
version_match = re.fullmatch(r"py-(\d+)\.\d+\.\d+.*", git_ref)
switcher_version = version_match.group(1) if version_match is not None else "dev"
html_js_files = [
(
"https://plausible.io/js/script.js",
{"data-domain": "docs.pola.rs,combined.pola.rs", "defer": "defer"},
),
]
html_theme_options = {
"external_links": [
{
"name": "User guide",
"url": f"{web_root}/",
},
],
"icon_links": [
{
"name": "GitHub",
"url": github_root,
"icon": "fa-brands fa-github",
},
{
"name": "Discord",
"url": "https://discord.gg/4UfP5cfBE7",
"icon": "fa-brands fa-discord",
},
{
"name": "X/Twitter",
"url": "https://x.com/datapolars",
"icon": "fa-brands fa-x-twitter",
},
{
"name": "Bluesky",
"url": "https://bsky.app/profile/pola.rs",
"icon": "fa-brands fa-bluesky",
},
],
"logo": {
"image_light": f"{static_assets_root}/logos/polars-logo-dark-medium.png",
"image_dark": f"{static_assets_root}/logos/polars-logo-dimmed-medium.png",
},
"switcher": {
"json_url": f"{web_root}/api/python/dev/_static/version_switcher.json",
"version_match": switcher_version,
},
"show_version_warning_banner": False,
"navbar_end": ["theme-switcher", "version-switcher", "navbar-icon-links"],
"check_switcher": False,
}
# sphinx-favicon - Add support for custom favicons
# https://github.com/tcmetzger/sphinx-favicon
favicons = [
{
"rel": "icon",
"sizes": "32x32",
"href": f"{static_assets_root}/icons/favicon-32x32.png",
},
{
"rel": "apple-touch-icon",
"sizes": "180x180",
"href": f"{static_assets_root}/icons/touchicon-180x180.png",
},
]
# sphinx-ext-linkcode - Add external links to source code
# https://www.sphinx-doc.org/en/master/usage/extensions/linkcode.html
def linkcode_resolve(domain: str, info: dict[str, Any]) -> str | None:
"""
Determine the URL corresponding to Python object.
Based on pandas equivalent:
https://github.com/pandas-dev/pandas/blob/main/doc/source/conf.py#L629-L686
"""
if domain != "py":
return None
modname = info["module"]
fullname = info["fullname"]
submod = sys.modules.get(modname)
if submod is None:
return None
obj = submod
for part in fullname.split("."):
try:
with warnings.catch_warnings():
# Accessing deprecated objects will generate noisy warnings
warnings.simplefilter("ignore", FutureWarning)
obj = getattr(obj, part)
except AttributeError: # noqa: PERF203
return None
try:
fn = inspect.getsourcefile(inspect.unwrap(obj))
except TypeError:
try: # property
fn = inspect.getsourcefile(inspect.unwrap(obj.fget))
except (AttributeError, TypeError):
fn = None
if not fn:
return None
try:
source, lineno = inspect.getsourcelines(obj)
except TypeError:
try: # property
source, lineno = inspect.getsourcelines(obj.fget)
except (AttributeError, TypeError):
lineno = None
except OSError:
lineno = None
linespec = f"#L{lineno}-L{lineno + len(source) - 1}" if lineno else ""
conf_dir_path = Path(__file__).absolute().parent
polars_root = (conf_dir_path.parent.parent / "polars").absolute()
fn = os.path.relpath(fn, start=polars_root)
return f"{github_root}/blob/{git_ref}/py-polars/polars/{fn}{linespec}"
def _minify_classpaths(s: str) -> str:
# strip private polars classpaths, leaving the classname:
# * "pl.Expr" -> "Expr"
# * "polars.expr.expr.Expr" -> "Expr"
# * "polars.lazyframe.frame.LazyFrame" -> "LazyFrame"
# also:
# * "datetime.date" => "date"
s = s.replace("datetime.", "")
return re.sub(
pattern=r"""
~?
(
(?:pl|
(?:polars\.
(?:_reexport|datatypes)
)
)
(?:\.[a-z.]+)?\.
([A-Z][\w.]+)
)
""",
repl=r"\2",
string=s,
flags=re.VERBOSE,
)
def process_signature( # noqa: D103
app: object,
what: object,
name: object,
obj: object,
opts: object,
sig: str,
ret: str,
) -> tuple[str, str]:
return (
_minify_classpaths(sig) if sig else sig,
_minify_classpaths(ret) if ret else ret,
)
def setup(app: Any) -> None: # noqa: D103
# TODO: a handful of methods do not seem to trigger the event for
# some reason (possibly @overloads?) - investigate further...
app.connect("autodoc-process-signature", process_signature)