|
| 1 | +"""Sphinx documentation configuration file.""" |
| 2 | + |
| 3 | +from datetime import datetime |
| 4 | +import os |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +from allie.flowkit import __version__ |
| 8 | +from ansys_sphinx_theme import ( |
| 9 | + ansys_favicon, |
| 10 | + ansys_logo_white, |
| 11 | + ansys_logo_white_cropped, |
| 12 | + get_autoapi_templates_dir_relative_path, |
| 13 | + get_version_match, |
| 14 | + latex, |
| 15 | + pyansys_logo_black, |
| 16 | + watermark, |
| 17 | +) |
| 18 | +from sphinx.builders.latex import LaTeXBuilder |
| 19 | + |
| 20 | +LaTeXBuilder.supported_image_types = ["image/png", "image/pdf", "image/svg+xml"] |
| 21 | + |
| 22 | +# Project information |
| 23 | +project = "allie-flowkit-python" |
| 24 | +copyright = f"(c) {datetime.now().year} ANSYS, Inc. All rights reserved" |
| 25 | +author = "ANSYS, Inc." |
| 26 | +release = version = __version__ |
| 27 | +cname = os.getenv("DOCUMENTATION_CNAME", default="allie-flowkit-python.docs.pyansys.com") |
| 28 | +switcher_version = get_version_match(__version__) |
| 29 | + |
| 30 | +# Select desired logo, theme, and declare the html title |
| 31 | +html_logo = pyansys_logo_black |
| 32 | +html_theme = "ansys_sphinx_theme" |
| 33 | +html_short_title = html_title = "Allie Flowkit Python" |
| 34 | +html_baseurl = f"https://{cname}/version/stable" |
| 35 | + |
| 36 | +# specify the location of your github repo |
| 37 | +html_context = { |
| 38 | + "github_user": "ansys", |
| 39 | + "github_repo": "allie-flowkit-python", |
| 40 | + "github_version": "main", |
| 41 | + "doc_path": "doc/source", |
| 42 | +} |
| 43 | +html_theme_options = { |
| 44 | + "switcher": { |
| 45 | + "json_url": f"https://{cname}/versions.json", |
| 46 | + "version_match": switcher_version, |
| 47 | + }, |
| 48 | + "check_switcher": False, |
| 49 | + "github_url": "https://github.com/ansys/allie-flowkit-python", |
| 50 | + "show_prev_next": False, |
| 51 | + "show_breadcrumbs": True, |
| 52 | + "collapse_navigation": True, |
| 53 | + "use_edit_page_button": True, |
| 54 | + "additional_breadcrumbs": [ |
| 55 | + ("PyAnsys", "https://docs.pyansys.com/"), |
| 56 | + ], |
| 57 | + "icon_links": [ |
| 58 | + { |
| 59 | + "name": "Support", |
| 60 | + "url": "https://github.com/ansys/allie-flowkit-python/discussions", |
| 61 | + "icon": "fa fa-comment fa-fw", |
| 62 | + }, |
| 63 | + { |
| 64 | + "name": "Download documentation in PDF", |
| 65 | + "url": f"https://{cname}/version/{switcher_version}/_static/assets/download/allie-flowkit-python.pdf", # noqa: E501 |
| 66 | + "icon": "fa fa-file-pdf fa-fw", |
| 67 | + }, |
| 68 | + ] |
| 69 | +} |
| 70 | + |
| 71 | +# Sphinx extensions |
| 72 | +extensions = [ |
| 73 | + "sphinx.ext.intersphinx", |
| 74 | + "sphinx_copybutton", |
| 75 | + "sphinx_design", |
| 76 | + "sphinx_jinja", |
| 77 | + "autoapi.extension", |
| 78 | + "numpydoc", |
| 79 | +] |
| 80 | + |
| 81 | +nbsphinx_execute = "always" |
| 82 | +sphinx_gallery_conf = { |
| 83 | + # path to your examples scripts |
| 84 | + "examples_dirs": ["../../examples"], |
| 85 | + # path where to save gallery generated examples |
| 86 | + "gallery_dirs": ["examples"], |
| 87 | + # Pattern to search for example files |
| 88 | + "filename_pattern": r"\.py", |
| 89 | + # Remove the "Download all examples" button from the top level gallery |
| 90 | + "download_all_examples": False, |
| 91 | + # Sort gallery example by file name instead of number of lines (default) |
| 92 | + # directory where function granular galleries are stored |
| 93 | + "backreferences_dir": None, |
| 94 | + # Modules for which function level galleries are created. In |
| 95 | + "doc_module": "allie-flowkit-python", |
| 96 | + "ignore_pattern": "flycheck*", |
| 97 | + "thumbnail_size": (350, 350), |
| 98 | + "remove_config_comments": True, |
| 99 | + "show_signature": False, |
| 100 | +} |
| 101 | + |
| 102 | + |
| 103 | +# Intersphinx mapping |
| 104 | +intersphinx_mapping = { |
| 105 | + "python": ("https://docs.python.org/3.11", None), |
| 106 | + "numpy": ("https://numpy.org/doc/stable", None), |
| 107 | + "scipy": ("https://docs.scipy.org/doc/scipy/", None), |
| 108 | + "pyvista": ("https://docs.pyvista.org/version/stable", None), |
| 109 | + "grpc": ("https://grpc.github.io/grpc/python/", None), |
| 110 | + "pint": ("https://pint.readthedocs.io/en/stable", None), |
| 111 | + "beartype": ("https://beartype.readthedocs.io/en/stable/", None), |
| 112 | + "docker": ("https://docker-py.readthedocs.io/en/stable/", None), |
| 113 | + "pypim": ("https://pypim.docs.pyansys.com/version/stable", None), |
| 114 | +} |
| 115 | + |
| 116 | +# numpydoc configuration |
| 117 | +numpydoc_show_class_members = False |
| 118 | +numpydoc_xref_param_type = True |
| 119 | + |
| 120 | +# Consider enabling numpydoc validation. See: |
| 121 | +# https://numpydoc.readthedocs.io/en/latest/validation.html# |
| 122 | +numpydoc_validate = True |
| 123 | +numpydoc_validation_checks = { |
| 124 | + "GL06", # Found unknown section |
| 125 | + "GL07", # Sections are in the wrong order. |
| 126 | + # "GL08", # The object does not have a docstring |
| 127 | + "GL09", # Deprecation warning should precede extended summary |
| 128 | + "GL10", # reST directives {directives} must be followed by two colons |
| 129 | + "SS01", # No summary found |
| 130 | + "SS02", # Summary does not start with a capital letter |
| 131 | + # "SS03", # Summary does not end with a period |
| 132 | + "SS04", # Summary contains heading whitespaces |
| 133 | + # "SS05", # Summary must start with infinitive verb, not third person |
| 134 | + "RT02", # The first line of the Returns section should contain only the |
| 135 | + # type, unless multiple values are being returned" |
| 136 | +} |
| 137 | + |
| 138 | +html_favicon = ansys_favicon |
| 139 | + |
| 140 | +# Add any paths that contain templates here, relative to this directory. |
| 141 | +templates_path = ["_templates"] |
| 142 | + |
| 143 | +# The suffix(es) of source filenames. |
| 144 | +source_suffix = { |
| 145 | + ".rst": "restructuredtext", |
| 146 | + ".md": "markdown", |
| 147 | +} |
| 148 | + |
| 149 | +# The master toctree document. |
| 150 | +master_doc = "index" |
| 151 | + |
| 152 | +# Configuration for Sphinx autoapi |
| 153 | +autoapi_type = "python" |
| 154 | +autoapi_dirs = ["../../src"] |
| 155 | +autoapi_root = "api" |
| 156 | +autoapi_template_dir = get_autoapi_templates_dir_relative_path(Path(__file__)) |
| 157 | +suppress_warnings = ["autoapi.python_import_resolution", "design.grid", "config.cache", "autoapi.not_readable"] |
| 158 | +autoapi_python_use_implicit_namespaces = True |
| 159 | +autoapi_keep_files = True |
| 160 | +autoapi_own_page_level = "class" |
| 161 | +autoapi_add_toctree_entry = False |
| 162 | +# Examples gallery customization |
| 163 | +nbsphinx_execute = "always" |
| 164 | + |
| 165 | +nbsphinx_epilog = """ |
| 166 | +---- |
| 167 | +
|
| 168 | +.. admonition:: Download this example |
| 169 | +
|
| 170 | + Download this example as a `Jupyter Notebook <{cname_pref}/{ipynb_file_loc}>`_ |
| 171 | + or as a `Python script <{cname_pref}/{py_file_loc}>`_. |
| 172 | +
|
| 173 | +""".format( |
| 174 | + cname_pref=f"https://{cname}/version/{switcher_version}", |
| 175 | + ipynb_file_loc="{{ env.docname }}.ipynb", |
| 176 | + py_file_loc="{{ env.docname }}.py", |
| 177 | +) |
| 178 | + |
| 179 | +nbsphinx_prolog = """ |
| 180 | +
|
| 181 | +.. admonition:: Download this example |
| 182 | +
|
| 183 | + Download this example as a `Jupyter Notebook <{cname_pref}/{ipynb_file_loc}>`_ |
| 184 | + or as a `Python script <{cname_pref}/{py_file_loc}>`_. |
| 185 | +
|
| 186 | +---- |
| 187 | +""".format( |
| 188 | + cname_pref=f"https://{cname}/version/{switcher_version}", |
| 189 | + ipynb_file_loc="{{ env.docname }}.ipynb", |
| 190 | + py_file_loc="{{ env.docname }}.py", |
| 191 | +) |
| 192 | + |
| 193 | +typehints_defaults = "comma" |
| 194 | +simplify_optional_unions = False |
| 195 | + |
| 196 | +# additional logos for the latex coverpage |
| 197 | +latex_additional_files = [watermark, ansys_logo_white, ansys_logo_white_cropped] |
| 198 | + |
| 199 | +# change the preamble of latex with customized title page |
| 200 | +# variables are the title of pdf, watermark |
| 201 | +latex_elements = {"preamble": latex.generate_preamble(html_title)} |
| 202 | + |
| 203 | +linkcheck_exclude_documents = ["index", "getting_started/local/index", "assets"] |
| 204 | + |
| 205 | +# -- Declare the Jinja context ----------------------------------------------- |
| 206 | +exclude_patterns = [ |
| 207 | + "examples/**/*.ipynb", |
| 208 | + "examples/**/*.py", |
| 209 | + "examples/**/*.md5", |
| 210 | + "api/ansys/visualizer/index.rst", |
| 211 | +] |
| 212 | + |
| 213 | +BUILD_API = True |
| 214 | +if not BUILD_API: |
| 215 | + exclude_patterns.append("autoapi") |
| 216 | + |
| 217 | +BUILD_EXAMPLES = True |
| 218 | +if not BUILD_EXAMPLES: |
| 219 | + exclude_patterns.append("examples/**") |
| 220 | + exclude_patterns.append("examples.rst") |
| 221 | + |
| 222 | +jinja_contexts = { |
| 223 | + "main_toctree": { |
| 224 | + "build_api": BUILD_API, |
| 225 | + "build_examples": BUILD_EXAMPLES, |
| 226 | + } |
| 227 | +} |
| 228 | + |
| 229 | + |
| 230 | +def prepare_jinja_env(jinja_env) -> None: |
| 231 | + """Customize the jinja env. |
| 232 | +
|
| 233 | + Notes |
| 234 | + ----- |
| 235 | + See https://jinja.palletsprojects.com/en/3.0.x/api/#jinja2.Environment |
| 236 | +
|
| 237 | + """ |
| 238 | + jinja_env.globals["project_name"] = project |
| 239 | + |
| 240 | + |
| 241 | +autoapi_prepare_jinja_env = prepare_jinja_env |
0 commit comments