|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | """Sphinx configuration for PyMC-Marketing Docs.""" |
3 | 3 |
|
| 4 | +import multiprocessing |
4 | 5 | import os |
5 | 6 |
|
6 | 7 | import pymc_marketing # isort:skip |
7 | 8 |
|
| 9 | +# -- Fast Build Mode Configuration ---------------------------------------- |
| 10 | +# Set environment variables to speed up builds during development: |
| 11 | +# - PYMC_MARKETING_FAST_DOCS=1: Skip notebooks and heavy API generation |
| 12 | +# - SKIP_NOTEBOOKS=1: Skip notebook execution only |
| 13 | +# - SKIP_API_GENERATION=1: Skip API documentation generation only |
| 14 | + |
| 15 | +FAST_DOCS = os.environ.get("PYMC_MARKETING_FAST_DOCS", "0") == "1" |
| 16 | +SKIP_NOTEBOOKS = os.environ.get("SKIP_NOTEBOOKS", "0") == "1" or FAST_DOCS |
| 17 | +SKIP_API_GENERATION = os.environ.get("SKIP_API_GENERATION", "0") == "1" or FAST_DOCS |
| 18 | + |
| 19 | +if FAST_DOCS: |
| 20 | + print("=" * 70) |
| 21 | + print("FAST BUILD MODE ENABLED") |
| 22 | + print(" - Notebooks: SKIPPED") |
| 23 | + print(" - API Generation: SKIPPED") |
| 24 | + print(" - Build time: ~30-60 seconds") |
| 25 | + print("=" * 70) |
| 26 | +elif SKIP_NOTEBOOKS or SKIP_API_GENERATION: |
| 27 | + print("=" * 70) |
| 28 | + print("PARTIAL FAST BUILD MODE") |
| 29 | + print(f" - Notebooks: {'SKIPPED' if SKIP_NOTEBOOKS else 'ENABLED'}") |
| 30 | + print(f" - API Generation: {'SKIPPED' if SKIP_API_GENERATION else 'ENABLED'}") |
| 31 | + print("=" * 70) |
| 32 | + |
8 | 33 | # -- General configuration ------------------------------------------------ |
9 | 34 |
|
10 | 35 | # General information about the project. |
|
66 | 91 | "**.ipynb_checkpoints", |
67 | 92 | ] |
68 | 93 |
|
| 94 | +# Fast build mode: Skip notebooks |
| 95 | +if SKIP_NOTEBOOKS: |
| 96 | + exclude_patterns.extend([ |
| 97 | + "notebooks/**", |
| 98 | + "guide/benefits/model_deployment.ipynb", |
| 99 | + ]) |
| 100 | + print(" ⚡ Excluding all notebooks from build") |
| 101 | + |
| 102 | +# Fast build mode: Skip API generation |
| 103 | +if SKIP_API_GENERATION: |
| 104 | + exclude_patterns.extend([ |
| 105 | + "api/generated/**", |
| 106 | + ]) |
| 107 | + print(" ⚡ Excluding API documentation from build") |
| 108 | + |
69 | 109 | # The reST default role (used for this markup: `text`) to use for all documents. |
70 | 110 | # This sets the behaviour to be the same as in markdown |
71 | 111 | default_role = "code" |
|
87 | 127 | remove_from_toctrees = ["**/classmethods/*"] |
88 | 128 |
|
89 | 129 | # myst config |
90 | | -nb_execution_mode = "auto" |
91 | | -nb_execution_excludepatterns = ["*.ipynb"] |
| 130 | +# Use cache mode for faster subsequent builds (only re-executes modified notebooks) |
| 131 | +# Use "off" in fast build mode to skip all notebook execution |
| 132 | +if SKIP_NOTEBOOKS: |
| 133 | + nb_execution_mode = "off" |
| 134 | +else: |
| 135 | + nb_execution_mode = "cache" # Changed from "auto" for better performance |
| 136 | + |
| 137 | +nb_execution_cache_path = ".jupyter_cache" # Persistent cache directory |
| 138 | +nb_execution_timeout = 600 # 10 minutes per notebook |
| 139 | +nb_execution_allow_errors = False |
| 140 | +nb_execution_raise_on_error = True |
| 141 | +nb_execution_excludepatterns = [ |
| 142 | + # Heavy notebooks that take too long - execute manually when needed |
| 143 | + "notebooks/mmm/mmm_case_study.ipynb", |
| 144 | + "notebooks/mmm/mmm_multidimensional_example.ipynb", |
| 145 | + "notebooks/mmm/mmm_tvp_example.ipynb", |
| 146 | + "notebooks/mmm/mmm_time_varying_media_example.ipynb", |
| 147 | + "notebooks/clv/dev/*.ipynb", # Development notebooks |
| 148 | +] |
92 | 149 | nb_kernel_rgx_aliases = {".*": "python3"} |
93 | 150 | myst_enable_extensions = ["colon_fence", "deflist", "dollarmath", "amsmath"] |
94 | 151 | myst_heading_anchors = 0 |
95 | 152 |
|
96 | 153 | # numpydoc and autodoc typehints config |
97 | 154 | numpydoc_show_class_members = False |
98 | 155 | numpydoc_xref_param_type = True |
| 156 | + |
| 157 | +# Enable parallel builds for faster processing |
| 158 | +# Use all CPUs except one to keep system responsive |
| 159 | +autodoc_parallel = max(1, multiprocessing.cpu_count() - 1) |
| 160 | + |
| 161 | +# Optimize autosummary generation |
| 162 | +autosummary_generate = True |
| 163 | +# Don't regenerate unchanged files (speeds up incremental builds) |
| 164 | +autosummary_generate_overwrite = False |
99 | 165 | # fmt: off |
100 | 166 | numpydoc_xref_ignore = { |
101 | 167 | "of", "or", "optional", "default", "numeric", "type", "scalar", "1D", "2D", "3D", "nD", "array", |
|
128 | 194 | "xarray": ("https://docs.xarray.dev/en/stable/", None), |
129 | 195 | } |
130 | 196 |
|
| 197 | +# Cache intersphinx inventories for faster builds |
| 198 | +intersphinx_cache_limit = 10 # Days to cache |
| 199 | +intersphinx_timeout = 30 # Seconds |
| 200 | + |
131 | 201 | # -- Options for HTML output ---------------------------------------------- |
132 | 202 |
|
133 | 203 | # The theme to use for HTML and HTML Help pages. See the documentation for |
|
0 commit comments