|
| 1 | +"""Sphinx Configuration File.""" |
| 2 | + |
| 3 | +import datetime |
| 4 | +import pathlib |
| 5 | + |
| 6 | +import autoapi.extension |
| 7 | +import toml |
| 8 | + |
| 9 | +# Add any Sphinx extension module names here, as strings. They can be |
| 10 | +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom |
| 11 | +# ones. |
| 12 | +extensions = [ |
| 13 | + "autoapi.extension", |
| 14 | + "m2r2", |
| 15 | + "sphinx.ext.autodoc", |
| 16 | + "sphinx.ext.intersphinx", |
| 17 | + "sphinx.ext.napoleon", |
| 18 | + "sphinx.ext.viewcode", |
| 19 | +] |
| 20 | + |
| 21 | +root_path = pathlib.Path(__file__).parent.parent |
| 22 | +pyproj_file = root_path / "pyproject.toml" |
| 23 | +proj_config = toml.loads(pyproj_file.read_text()) |
| 24 | + |
| 25 | + |
| 26 | +project = proj_config["tool"]["poetry"]["name"] |
| 27 | +company = "National Instruments" |
| 28 | +copyright = f"2025-%Y, {company}" |
| 29 | +if datetime.datetime.now().year == 2025: |
| 30 | + copyright = f"%Y, {company}" |
| 31 | + |
| 32 | + |
| 33 | +# The version info for the project you're documenting, acts as replacement for |
| 34 | +# |version| and |release|, also used in various other places throughout the |
| 35 | +# built documents. |
| 36 | +# |
| 37 | +version = proj_config["tool"]["poetry"]["version"] |
| 38 | +release = ".".join(version.split(".")[:2]) |
| 39 | +description = proj_config["tool"]["poetry"]["description"] |
| 40 | + |
| 41 | + |
| 42 | +htmlhelp_basename = f"{project}doc" |
| 43 | + |
| 44 | + |
| 45 | +# tell autoapi to doc the public options |
| 46 | +autoapi_options = list(autoapi.extension._DEFAULT_OPTIONS) |
| 47 | +autoapi_options.remove("private-members") # note: remove this to include "_" members in docs |
| 48 | +autoapi_dirs = [root_path / "src" / "nitypes"] |
| 49 | +autoapi_type = "python" |
| 50 | +autodoc_typehints = "description" |
| 51 | + |
| 52 | + |
| 53 | +# TODO: https://github.com/ni/nitypes-python/issues/16 - Update nitypes-python docs to use |
| 54 | +# :canonical: to resolve aliases (once supported by sphinx-autoapi) |
| 55 | +def skip_aliases(app, what, name, obj, skip, options): |
| 56 | + """Skip documentation for classes that are exported from multiple modules.""" |
| 57 | + # For names that are defined in a private sub-module and aliased into a |
| 58 | + # public package, hide the definition. |
| 59 | + if name.startswith("nitypes.time._") or name.startswith("nitypes.waveform._"): |
| 60 | + skip = True |
| 61 | + |
| 62 | + return skip |
| 63 | + |
| 64 | + |
| 65 | +def setup(sphinx): |
| 66 | + """Sphinx setup callback.""" |
| 67 | + sphinx.connect("autoapi-skip-member", skip_aliases) |
| 68 | + |
| 69 | + |
| 70 | +# List of patterns, relative to source directory, that match files and |
| 71 | +# directories to ignore when looking for source files. |
| 72 | +# This patterns also effect to html_static_path and html_extra_path |
| 73 | +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] |
| 74 | + |
| 75 | + |
| 76 | +intersphinx_mapping = { |
| 77 | + "python": ("https://docs.python.org/3", None), |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | +# -- Options for HTML output ---------------------------------------------- |
| 82 | + |
| 83 | + |
| 84 | +# The theme to use for HTML and HTML Help pages. See the documentation for |
| 85 | +# a list of builtin themes. |
| 86 | +# |
| 87 | +html_theme = "sphinx_rtd_theme" |
| 88 | +html_theme_options = { |
| 89 | + "navigation_depth": -1, |
| 90 | +} |
| 91 | + |
| 92 | +# Napoleon settings |
| 93 | +napoleon_numpy_docstring = False |
0 commit comments