-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathconf.py
More file actions
188 lines (156 loc) · 4.77 KB
/
conf.py
File metadata and controls
188 lines (156 loc) · 4.77 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
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
# Copyright (c) QuantCo 2025-2026
# SPDX-License-Identifier: BSD-3-Clause
# 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 --------------------------------------------------------------
import datetime
import importlib
import inspect
import os
import subprocess
import sys
from subprocess import CalledProcessError
from typing import Any, cast
# -- Project information -----------------------------------------------------
_mod = importlib.import_module("dataframely")
project = "dataframely"
copyright = f"{datetime.date.today().year}, QuantCo, Inc"
author = "QuantCo, Inc."
extensions = [
# builtin sphinx
"sphinx.ext.autosummary",
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.linkcode",
"sphinx.ext.napoleon",
# external
"autodocsumm",
"myst_parser",
"nbsphinx",
"numpydoc",
"sphinx_copybutton",
"sphinx_design",
"sphinx_toolbox.more_autodoc.overloads",
]
## sphinx
# html output
html_theme = "pydata_sphinx_theme"
pygments_style = "lovelace"
html_theme_options = {
"external_links": [],
"icon_links": [
{
"name": "GitHub",
"url": "https://github.com/Quantco/dataframely",
"icon": "fa-brands fa-github",
},
],
}
html_title = "Dataframely"
html_static_path = ["_static"]
html_css_files = ["css/custom.css"]
html_favicon = "_static/favicon.ico"
html_show_sourcelink = False
# markup
default_role = "code"
# object signatures
maximum_signature_line_length = 88
# source files
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
source_suffix = {
".rst": "restructuredtext",
".txt": "markdown",
".md": "markdown",
}
# templating
templates_path = ["_templates"]
## sphinx.ext.autodoc
autoclass_content = "both"
autodoc_default_options = {
"inherited-members": True,
}
## sphinx.ext.intersphinx
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"polars": ("https://docs.pola.rs/py-polars/html/", None),
"sqlalchemy": ("https://docs.sqlalchemy.org/en/20/", None),
}
## myst_parser
myst_parser_config = {"myst_enable_extensions": ["rst_eval_roles"]}
nitpick_ignore = [("myst", "group-rules")]
## numpydoc
numpydoc_class_members_toctree = False
numpydoc_show_class_members = False
## sphinx_toolbox
overloads_location = ["bottom"]
# Copied and adapted from
# https://github.com/pandas-dev/pandas/blob/4a14d064187367cacab3ff4652a12a0e45d0711b/doc/source/conf.py#L613-L659
# Required configuration function to use sphinx.ext.linkcode
def linkcode_resolve(domain: str, info: dict[str, str]) -> str | None:
"""Determine the URL corresponding to a given Python object."""
if domain != "py":
return None
module_name = info["module"]
full_name = info["fullname"]
_submodule = sys.modules.get(module_name)
if _submodule is None:
return None
_object = _submodule
for _part in full_name.split("."):
try:
_object = getattr(_object, _part)
except AttributeError:
return None
try:
fn = inspect.getsourcefile(inspect.unwrap(_object)) # type: ignore
except TypeError:
fn = None
if not fn:
return None
try:
source, line_number = inspect.getsourcelines(_object)
except OSError:
line_number = None
if line_number:
linespec = f"#L{line_number}-L{line_number + len(source) - 1}"
else:
linespec = ""
fn = os.path.relpath(fn, start=os.path.dirname(cast(str, _mod.__file__)))
try:
# See https://stackoverflow.com/a/21901260
commit = (
subprocess.check_output(["git", "rev-parse", "HEAD"])
.decode("ascii")
.strip()
)
except CalledProcessError:
# If subprocess returns non-zero exit status
commit = "main"
return (
"https://github.com/quantco/dataframely"
f"/blob/{commit}/{_mod.__name__.replace('.', '/')}/{fn}{linespec}"
)
## Hide the signature for classes that should not be instantiated by the user
def hide_class_signature(
app: Any,
what: str,
name: str,
obj: Any,
options: Any,
signature: str | None,
return_annotation: str,
) -> tuple[str, str] | None:
if what == "class" and (
name.endswith("FilterResult")
or name.endswith("FailureInfo")
or name.endswith("AnnotationImplementationError")
):
# Return empty signature (no args after the class name)
return "", return_annotation
# Otherwise, keep default behavior
return None
def setup(app: Any) -> None:
app.connect("autodoc-process-signature", hide_class_signature)