From 66570739284e0a6fef84a66c6603c51850453795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dion=20H=C3=A4fner?= Date: Thu, 11 Apr 2024 10:01:17 +0200 Subject: [PATCH] add docs + gh pages deploy --- .github/workflows/build_docs.yml | 51 +++++++++++++++++++++++++++++++ .github/workflows/deploy_docs.yml | 48 +++++++++++++++++++++++++++++ docs/Makefile | 20 ++++++++++++ docs/conf.py | 49 +++++++++++++++++++++++++++++ docs/index.rst | 6 ++++ docs/make.bat | 35 +++++++++++++++++++++ docs/requirements.txt | 1 + docs/static/.empty | 0 exponax/__init__.py | 2 ++ exponax/_utils.py | 11 +++---- 10 files changed, 217 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/build_docs.yml create mode 100644 .github/workflows/deploy_docs.yml create mode 100644 docs/Makefile create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/make.bat create mode 100644 docs/requirements.txt create mode 100644 docs/static/.empty diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml new file mode 100644 index 0000000..cf2f591 --- /dev/null +++ b/.github/workflows/build_docs.yml @@ -0,0 +1,51 @@ +name: Build documentation + +on: + # only run on PRs, not on pushes to main + # (this is handled by deploy_docs.yml) + pull_request: + + workflow_call: + inputs: + artifact_name: + description: "Name of the artifact to upload" + required: false + type: string + +jobs: + test-docs: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install system requirements + run: | + sudo apt-get update + sudo apt-get install -y pandoc + + - name: Setup Python environment + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install doc requirements + run: | + pip install jax[cpu] + pip install . + pip install -r docs/requirements.txt + + - name: Build docs + run: | + cd docs + export SPHINXOPTS="-W" # treat warnings as errors + make html + + - name: Upload HTML files + uses: actions/upload-artifact@v3 + if: ${{ inputs.artifact_name }} + with: + name: ${{ inputs.artifact_name }} + path: docs/build/html + if-no-files-found: error \ No newline at end of file diff --git a/.github/workflows/deploy_docs.yml b/.github/workflows/deploy_docs.yml new file mode 100644 index 0000000..e1cbb74 --- /dev/null +++ b/.github/workflows/deploy_docs.yml @@ -0,0 +1,48 @@ +name: Deploy docs to GitHub Pages + +on: + push: + branches: + - main + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + build-docs: + uses: ./.github/workflows/build_docs.yml + with: + artifact_name: exponax-docs-html + + deploy: + needs: [build-docs] + + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + runs-on: ubuntu-latest + steps: + - name: Setup Pages + uses: actions/configure-pages@v2 + + - name: Download HTML doc artifact + uses: actions/download-artifact@v3 + with: + name: exponax-docs-html + path: docs_build + + - name: Upload pages artifact + uses: actions/upload-pages-artifact@v1 + with: + path: docs_build + + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v1 diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..63a98ea --- /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) -c . diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..f23f75e --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,49 @@ +# 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 + +import re + +from exponax import __version__ # noqa: E402 + +project = "exponax" +copyright = "2024, The exponax Team" +author = "The exponax Team" + +# The short X.Y version +parsed_version = re.match(r"(\d+\.\d+\.\d+)", __version__) +if parsed_version: + version = parsed_version.group(1) +else: + version = "0.0.0" + +# The full version, including alpha/beta/rc tags +release = __version__ + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = [ + "sphinx.ext.intersphinx", + "sphinx.ext.autodoc", + "sphinx.ext.napoleon", +] + +intersphinx_mapping = { + "python": ("https://docs.python.org/3", None), + "numpy": ("http://docs.scipy.org/doc/numpy/", None), +} + +templates_path = [] +exclude_patterns = ["build", "Thumbs.db", ".DS_Store"] + + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = "alabaster" +html_static_path = ["static"] diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..0b2811c --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,6 @@ +API documentation +================= + +.. automodule:: exponax + :members: + :undoc-members: \ No newline at end of file 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/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..45a6471 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1 @@ +sphinx==7.0.1 \ No newline at end of file diff --git a/docs/static/.empty b/docs/static/.empty new file mode 100644 index 0000000..e69de29 diff --git a/exponax/__init__.py b/exponax/__init__.py index 32e1e98..e912e27 100644 --- a/exponax/__init__.py +++ b/exponax/__init__.py @@ -14,6 +14,8 @@ wrap_bc, ) +__version__ = "0.1.0" + __all__ = [ "BaseStepper", "ForcedStepper", diff --git a/exponax/_utils.py b/exponax/_utils.py index 4370501..9d786c5 100644 --- a/exponax/_utils.py +++ b/exponax/_utils.py @@ -29,7 +29,7 @@ def make_grid( - `domain_extent`: The extent of the domain in each spatial dimension. - `num_points`: The number of points in each spatial dimension. - `full`: Whether to include the right boundary point in the grid. - Default: `False`. The right point is redundant for periodic boundary + Default: `False`. The right point is redundant for periodic boundary conditions and is not considered a degree of freedom. Use this option, for example, if you need a full grid for plotting. - `zero_centered`: Whether to center the grid around zero. Default: @@ -38,8 +38,7 @@ def make_grid( - `indexing`: The indexing convention to use. Default: `'ij'`. **Returns:** - - `grid`: The grid in the spatial domain. Shape: `(num_spatial_dims, - ..., num_points)`. + - `grid`: The grid in the spatial domain. Shape: `(num_spatial_dims, ..., num_points)`. """ if full: grid_1d = jnp.linspace(0, domain_extent, num_points + 1, endpoint=True) @@ -266,9 +265,9 @@ def stack_sub_trajectories( condition in the subtrajectories. **Returns:** - - `sub_trjs`: The stacked subtrajectories. Expected shape: `(n_stacks, - n, ...)`. `n_stacks` is the number of subtrajectories stacked - together, i.e., `n_timesteps - n + 1`. + - `sub_trjs`: The stacked subtrajectories. Expected shape: `(n_stacks, n, ...)`. + `n_stacks` is the number of subtrajectories stacked together, i.e., + `n_timesteps - n + 1`. """ n_time_steps = [leaf.shape[0] for leaf in jtu.tree_leaves(trj)]