From 6bb3994abe2ce96991b765030875c45a3d7a1eee Mon Sep 17 00:00:00 2001 From: Ludovico Bianchi Date: Mon, 9 Dec 2024 18:41:03 -0600 Subject: [PATCH] Add initial Sphinx docs infrastructure (#10) * Add initial Sphinx files * Add ReadTheDocs config file * Add dev dependencies for docs build * Add job step to test local docs build * Format docs/conf.py with Black --- .github/workflows/checks.yml | 4 +++ .readthedocs.yaml | 19 ++++++++++ docs/Makefile | 20 +++++++++++ docs/conf.py | 67 ++++++++++++++++++++++++++++++++++++ docs/index.rst | 12 +++++++ docs/make.bat | 35 +++++++++++++++++++ requirements-dev.txt | 5 +++ 7 files changed, 162 insertions(+) create mode 100644 .readthedocs.yaml create mode 100644 docs/Makefile create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/make.bat diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index c5bd16e..a0a10f1 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -104,3 +104,7 @@ jobs: name: coverage-report-${{ matrix.os }} path: coverage.xml if-no-files-found: error + - name: Build Sphinx docs + if: matrix.install-mode == 'dev' + run: | + make -C docs html diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..e5fd526 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,19 @@ +# .readthedocs.yaml +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Build documentation in the docs/ directory with Sphinx +sphinx: + fail_on_warning: true + +build: + os: ubuntu-22.04 + tools: + python: "3.11" + +python: + install: + - requirements: requirements-dev.txt diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..cf33ec8 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,67 @@ +from importlib import metadata + +# 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 + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +project = "IDAES Flowsheet Processor" +copyright = "2024, WaterTAP" +author = "WaterTAP" + +release = version = metadata.version("idaes-flowsheet-processor") + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = [ + "sphinx_rtd_theme", + "sphinx.ext.doctest", + "sphinx.ext.napoleon", + "autoapi.extension", + "sphinx.ext.intersphinx", +] +suppress_warnings = [] + +templates_path = ["_templates"] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + +# see https://sphinx-autoapi.readthedocs.io/en/latest/reference/config.html +autoapi_dirs = ["../src"] +autoapi_root = "technical_reference" +autoapi_options = [ + "members", + "undoc-members", + "show-module-summary", +] +# set to True to save the autogenerated +autoapi_keep_files = False +autoapi_ignore = ["*conftest.py", "*test_*.py", "*tests/*.py", "*_testing/*.py"] +# suppress_warnings += ["autoapi.python_import_resolution"] + +intersphinx_mapping = { + "python": ("https://docs.python.org/3", None), + "pyomo": ("https://pyomo.readthedocs.io/en/stable", None), + "numpy": ("https://numpy.org/doc/stable", None), + "idaes": ("https://idaes-pse.readthedocs.io/en/stable", None), + "watertap": ("https://watertap.readthedocs.io/en/latest", None), + "prommis": ("https://prommis.readthedocs.io/en/latest", None), +} + + +def _skip_tests(app, what: str, name: str, obj, skip, options): + return skip + + +def setup(sphinx): + sphinx.connect("autoapi-skip-member", _skip_tests) + + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = "sphinx_rtd_theme" +html_static_path = [] diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..da88277 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,12 @@ +IDAES Flowsheet Processor +========================= + +Contents +-------- + +.. toctree:: + :maxdepth: 3 + + technical_reference/index + +* :ref:`genindex` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..32bb245 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/requirements-dev.txt b/requirements-dev.txt index 033b21a..ee3102b 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,9 @@ black==24.8.0 pytest-cov==5.0.* +Sphinx==7.1.2 ; python_version < '3.9' +Sphinx==7.3.7 ; python_version >= '3.9' +sphinx-autoapi==3.0.0 +sphinx-rtd-theme==2.0.0 + --editable .[testing] \ No newline at end of file