-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathconf.py
More file actions
149 lines (118 loc) · 4.44 KB
/
conf.py
File metadata and controls
149 lines (118 loc) · 4.44 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
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
import inspect
import os
import sys
from dataclasses import Field as _Field
from unitxt.artifact import Artifact
from unitxt.dataclass import Dataclass, Field, fields, get_field_default
from unitxt.settings_utils import get_constants
constants = get_constants()
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from catalog import create_catalog_docs
create_catalog_docs()
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
project = "Unitxt"
author = "IBM Research"
release = constants.version
html_short_title = "Unitxt"
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinxext.opengraph",
"sphinx.ext.linkcode",
]
templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = "piccolo_theme"
html_logo = "./static/logo.png"
html_theme_options = {
"banner_text": 'Read our <a href="https://www.unitxt.ai/en/latest/blog/2024_summary_blog.html">2024 Summary</a> blog post!',
"banner_hiding": "temporary",
"show_theme_credit": False,
"source_url": "https://github.com/IBM/unitxt/",
}
html_static_path = ["_static"]
html_css_files = ["custom.css"]
html_js_files = ["custom.js"]
html_show_sphinx = False
html_favicon = "./static/favicon.ico"
html_title = "Unitxt"
ogp_image = (
"https://raw.githubusercontent.com/IBM/unitxt/main/docs/static/opg_image.png"
)
autodoc_default_flags = [
"members",
"private-members",
"special-members",
#'undoc-members',
"show-inheritance",
]
def linkcode_resolve(domain, info):
if domain != "py":
return None
if not info["module"]:
return None
try:
# Import the module
obj = sys.modules[info["module"]]
for part in info["fullname"].split("."):
obj = getattr(obj, part)
# Get the source file and line number
fn = inspect.getsourcefile(obj)
source, lineno = inspect.getsourcelines(obj)
except Exception:
return None
if not fn or not lineno:
return None
# Convert file path to relative path
fn = os.path.relpath(fn, start=constants.package_dir)
# Construct the GitHub URL
return f"https://github.com/IBM/unitxt/blob/main/src/unitxt/{fn}#L{lineno}"
def autodoc_skip_member(app, what, name, obj, would_skip, options):
if would_skip:
return True
if callable(obj) and obj.__doc__:
return False
if isinstance(obj, (Field, _Field, bool, int, str, float)):
return True
if obj is None or type(obj) is object:
return True
if hasattr(obj, "__qualname__"):
class_name = obj.__qualname__.split(".")[0]
if class_name and class_name != name:
return True
return None
def process_init_signature(app, what, name, obj, options, signature, return_annotation):
if what == "class" and issubclass(obj, Dataclass):
params = []
for field in fields(obj):
if not field.name.startswith("__"):
new_type = (
str(field.type)
.replace("typing.", "")
.replace("<class '", "")
.replace("'>", "")
)
param = f"{field.name}: {new_type}"
default = get_field_default(field)
if "MISSING_TYPE" not in repr(default):
if isinstance(default, Artifact):
default = default.__id__
param += f" = {default!r}"
else:
param += " = __required__"
params.append(param)
new_signature = f"({', '.join(params)})"
return new_signature, return_annotation
return signature, return_annotation
def setup(app):
app.connect("autodoc-process-signature", process_init_signature)
app.connect("autodoc-skip-member", autodoc_skip_member)