|
28 | 28 | import os |
29 | 29 | import os.path |
30 | 30 | import sys |
31 | | -import warnings |
| 31 | +import logging |
| 32 | +from sphinx.util import logging as sphinx_logging |
32 | 33 |
|
33 | 34 | # Prevent JAX/Torch/TF from trying to access TPU/GPU during doc build |
34 | 35 | os.environ["JAX_PLATFORMS"] = "cpu" |
35 | 36 | os.environ["CUDA_VISIBLE_DEVICES"] = "" |
| 37 | + |
36 | 38 | MAXTEXT_REPO_ROOT = os.environ.get("MAXTEXT_REPO_ROOT", os.path.join(os.path.dirname(os.path.dirname(__file__)))) |
37 | | -sys.path.insert(0, os.path.abspath(os.path.join(MAXTEXT_REPO_ROOT, "test"))) |
38 | 39 | sys.path.insert(0, os.path.abspath(os.path.join(MAXTEXT_REPO_ROOT, "src"))) |
39 | 40 |
|
40 | | -warnings.filterwarnings("ignore", category=FutureWarning, module="keras.src.export.tf2onnx_lib") |
41 | | - |
42 | 41 | project = "MaxText" |
43 | 42 | # pylint: disable=redefined-builtin |
44 | 43 | copyright = "2023–2026, Google LLC" |
|
62 | 61 | source_suffix = [".rst", ".ipynb", ".md"] |
63 | 62 |
|
64 | 63 | # Suppress specific warnings |
65 | | -suppress_warnings = [ |
66 | | - "app.add_node", |
67 | | - "ref.python", |
68 | | - "myst.xref_ambiguous", |
69 | | - "docutils", |
70 | | - "autodoc", |
71 | | - "autodoc.duplicate_object_description", |
72 | | - "toc.not_included", |
73 | | -] |
| 64 | +suppress_warnings = ["autodoc.import_object"] |
74 | 65 |
|
75 | 66 | # -- Options for HTML output ------------------------------------------------- |
76 | 67 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output |
|
94 | 85 | autodoc_member_order = "bysource" |
95 | 86 | autodoc_typehints = "description" |
96 | 87 | autodoc_mock_imports = [ |
97 | | - "cloud_tpu_diagnostics", |
98 | | - "google_cloud_mldiagnostics", |
99 | | - "jetstream", |
100 | | - "librosa", |
101 | | - "ml_goodput_measurement", |
102 | | - "pathwaysutils", |
103 | 88 | "safetensors", |
104 | 89 | "tensorflow_datasets", |
105 | 90 | "torch", |
106 | 91 | "tpu_inference", |
107 | | - "transformer_engine", |
108 | 92 | "vllm", |
| 93 | + "grain", |
| 94 | + "librosa", |
| 95 | + "sentencepiece", |
109 | 96 | ] |
110 | 97 | autosummary_generate = True |
111 | 98 |
|
|
129 | 116 | os.path.join("guides", "run_maxtext", "run_maxtext_via_multihost_job.md"), |
130 | 117 | os.path.join("guides", "run_maxtext", "run_maxtext_via_multihost_runner.md"), |
131 | 118 | os.path.join("explanations", "llm_calculator.ipynb"), |
132 | | - os.path.join("reference", "api.rst"), |
133 | 119 | os.path.join("run_maxtext", "run_maxtext_via_multihost_job.md"), |
134 | 120 | os.path.join("run_maxtext", "run_maxtext_via_multihost_runner.md"), |
135 | 121 | os.path.join("reference", "core_concepts", "llm_calculator.ipynb"), |
| 122 | + os.path.join("reference", "api_generated", "modules.rst"), |
| 123 | + os.path.join("reference", "api_generated", "install_maxtext_extra_deps.rst"), |
| 124 | + os.path.join("reference", "api_generated", "install_maxtext_extra_deps.install_github_deps.rst"), |
136 | 125 | ] |
137 | 126 |
|
138 | 127 |
|
@@ -191,8 +180,31 @@ def run_apidoc(_): |
191 | 180 | sys.exit(1) |
192 | 181 |
|
193 | 182 |
|
194 | | -# Connect the apidoc generation to the Sphinx build process |
| 183 | +class FilterSphinxWarnings(logging.Filter): |
| 184 | + """Filter autosummary 'duplicate object description' warnings. |
| 185 | +
|
| 186 | + These warnings are unnecessary as they do not cause missing documentation |
| 187 | + or rendering issues, so it is safe to filter them out. |
| 188 | + """ |
| 189 | + |
| 190 | + def __init__(self, app): |
| 191 | + self.app = app |
| 192 | + super().__init__() |
| 193 | + |
| 194 | + def filter(self, record: logging.LogRecord) -> bool: |
| 195 | + msg = record.getMessage() |
| 196 | + filter_out = ("duplicate object description",) |
| 197 | + return not msg.strip().startswith(filter_out) |
| 198 | + |
| 199 | + |
195 | 200 | def setup(app): |
| 201 | + """Set up the Sphinx application with custom behavior.""" |
| 202 | + |
| 203 | + # Connect the apidoc generation to the Sphinx build process |
196 | 204 | run_apidoc(None) |
197 | 205 | print("running:", app) |
198 | | - # app.connect("builder-inited", run_apidoc) |
| 206 | + |
| 207 | + # Set up custom logging filters |
| 208 | + logger = logging.getLogger("sphinx") |
| 209 | + warning_handler, *_ = [h for h in logger.handlers if isinstance(h, sphinx_logging.WarningStreamHandler)] |
| 210 | + warning_handler.filters.insert(0, FilterSphinxWarnings(app)) |
0 commit comments