From dc3658549742300dbf6a4b6dc434a46fcf999fa3 Mon Sep 17 00:00:00 2001 From: Dan Cummins Date: Sun, 29 Sep 2024 14:34:39 +0100 Subject: [PATCH 1/3] Added basic sphinx documentation --- docs/Makefile | 20 +++++++++++ docs/make.bat | 35 +++++++++++++++++++ docs/source/api_ref.rst | 8 +++++ docs/source/conf.py | 27 +++++++++++++++ docs/source/fargonaut.fields.rst | 45 +++++++++++++++++++++++++ docs/source/fargonaut.rst | 37 ++++++++++++++++++++ docs/source/index.rst | 14 ++++++++ docs/source/user_docs.rst | 9 +++++ docs/source/user_docs/basic_usage.rst | 41 ++++++++++++++++++++++ docs/source/user_docs/contrib_guide.rst | 24 +++++++++++++ docs/source/user_docs/installation.rst | 20 +++++++++++ 11 files changed, 280 insertions(+) create mode 100644 docs/Makefile create mode 100644 docs/make.bat create mode 100644 docs/source/api_ref.rst create mode 100644 docs/source/conf.py create mode 100644 docs/source/fargonaut.fields.rst create mode 100644 docs/source/fargonaut.rst create mode 100644 docs/source/index.rst create mode 100644 docs/source/user_docs.rst create mode 100644 docs/source/user_docs/basic_usage.rst create mode 100644 docs/source/user_docs/contrib_guide.rst create mode 100644 docs/source/user_docs/installation.rst diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d0c3cbf --- /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 = source +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/make.bat b/docs/make.bat new file mode 100644 index 0000000..dc1312a --- /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=source +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/source/api_ref.rst b/docs/source/api_ref.rst new file mode 100644 index 0000000..3f194c6 --- /dev/null +++ b/docs/source/api_ref.rst @@ -0,0 +1,8 @@ +API Reference +============= + +.. toctree:: + :maxdepth: 2 + + fargonaut + diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 0000000..4962ffb --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,27 @@ +"""Configuration file for the Sphinx documentation builder.""" + +import os +import sys + +sys.path.insert(0, os.path.abspath("../..")) + + +# -- Project information ----------------------------------------------------- + +project = "Fargonaut" +copyright = "2024, Dan Cummins" +author = "Dan Cummins" + + +# -- General configuration --------------------------------------------------- + +extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx_rtd_theme"] + +templates_path = ["_templates"] +exclude_patterns = [] + + +# -- Options for HTML output ------------------------------------------------- + +html_theme = "sphinx_rtd_theme" +html_static_path = ["_static"] diff --git a/docs/source/fargonaut.fields.rst b/docs/source/fargonaut.fields.rst new file mode 100644 index 0000000..094a036 --- /dev/null +++ b/docs/source/fargonaut.fields.rst @@ -0,0 +1,45 @@ +fargonaut.fields package +======================== + +Submodules +---------- + +fargonaut.fields.density module +------------------------------- + +.. automodule:: fargonaut.fields.density + :members: + :undoc-members: + :show-inheritance: + +fargonaut.fields.energy module +------------------------------ + +.. automodule:: fargonaut.fields.energy + :members: + :undoc-members: + :show-inheritance: + +fargonaut.fields.magnetic\_field module +--------------------------------------- + +.. automodule:: fargonaut.fields.magnetic_field + :members: + :undoc-members: + :show-inheritance: + +fargonaut.fields.velocity module +-------------------------------- + +.. automodule:: fargonaut.fields.velocity + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: fargonaut.fields + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/fargonaut.rst b/docs/source/fargonaut.rst new file mode 100644 index 0000000..1bdf91f --- /dev/null +++ b/docs/source/fargonaut.rst @@ -0,0 +1,37 @@ +fargonaut package +================= + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + fargonaut.fields + +Submodules +---------- + +fargonaut.field module +---------------------- + +.. automodule:: fargonaut.field + :members: + :undoc-members: + :show-inheritance: + +fargonaut.output module +----------------------- + +.. automodule:: fargonaut.output + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: fargonaut + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/index.rst b/docs/source/index.rst new file mode 100644 index 0000000..94de652 --- /dev/null +++ b/docs/source/index.rst @@ -0,0 +1,14 @@ +Fargonaut documentation +======================= + +Fargonaut is an object-oriented toolkit for post-processing and visualising outputs of FARGO3D_, written in Python. + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + User Documentation + API Reference + + +.. _fargo3d: https://github.com/FARGO3D/fargo3d diff --git a/docs/source/user_docs.rst b/docs/source/user_docs.rst new file mode 100644 index 0000000..1bc5eea --- /dev/null +++ b/docs/source/user_docs.rst @@ -0,0 +1,9 @@ +User Documentation +================== + +.. toctree:: + :maxdepth: 2 + + user_docs/installation + user_docs/basic_usage + user_docs/contrib_guide diff --git a/docs/source/user_docs/basic_usage.rst b/docs/source/user_docs/basic_usage.rst new file mode 100644 index 0000000..961aded --- /dev/null +++ b/docs/source/user_docs/basic_usage.rst @@ -0,0 +1,41 @@ +Basic Usage +=========== + +Locate the directory containing the FARGO3D output you want to open. For demonstrative purposes, we will use "/path/to/fargo3d/outputs", and use the "fargo" output, created when running the example "fargo" setup. + +Open the Python interpreter:: + + $ python + +Import the top-level ``Output`` class:: + + >>> from fargonaut.output import Output + +Use this class to create an object for handling your output:: + + >>> output = Output("/path/to/fargo3d/outputs/fargo") + +Using the ``Output`` class:: + + >>> help(output) + +Retrieve variables defined in the variables.par file using the ``get_var`` method, e.g.:: + + >>> output.get_var("FRAME") + 'G' + +Some commonly used variables are stored as properties, in particular those related to the grid, e.g.:: + + >>> output.ny + 128 + >>> output.nghy + 3 + >>> len(output.ydomain) + 135 + >>> output.xdomain + array([-3.14159265, -3.12523019, -3.10886773, ..., 0, ... 3.14159265]) + +Use the ``get_field`` method to retrieve a field at a given output time. The names of the fields are those of the corresponding output files, e.g. to retrieve the gas density:: + + >>> gasdens50 = output.get_field("gasdens", 50) + diff --git a/docs/source/user_docs/contrib_guide.rst b/docs/source/user_docs/contrib_guide.rst new file mode 100644 index 0000000..8868f3b --- /dev/null +++ b/docs/source/user_docs/contrib_guide.rst @@ -0,0 +1,24 @@ +Contributing Guidelines +======================= + +Install the development requirements:: + + $ pip install -r requirements-dev.txt + +Install the pre-commit hooks:: + + $ pre-commit install + +Run the tests:: + + $ python -m unittest discover tests + +Check test coverage:: + + $ coverage run --omit=tests/* -m unittest discover tests + $ coverage report -m + +Build the documentation:: + + $ cd docs + $ make html diff --git a/docs/source/user_docs/installation.rst b/docs/source/user_docs/installation.rst new file mode 100644 index 0000000..4d21898 --- /dev/null +++ b/docs/source/user_docs/installation.rst @@ -0,0 +1,20 @@ +Installation +============ + +The only requirements for installing Fargonaut are Git and Python. + +First, clone the repository:: + + $ git clone https://github.com/dc2917/Fargonaut + +Create a virtual environment to keep the Python packages separate from system packages and other local environments:: + + $ python -m venv .venv + +Activate the environment:: + + $ source .venv/bin/activate + +Install the dependencies:: + + $ pip install -r requirements.txt From 365a2abc35b35baabcfe3309bf67d274400abae6 Mon Sep 17 00:00:00 2001 From: Dan Cummins Date: Sun, 29 Sep 2024 14:43:05 +0100 Subject: [PATCH 2/3] Point to documentation --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ef30b87..7cf4fbf 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Fargonaut is a package for post-processing and visualising outputs of [FARGO3D]( ![Gas surface density output 50](docs/images/fargo_gasdens50.png) +See the documentation for installation instructions, example usage and the API reference. + ## Contributing to Fargonaut Contributions to Fargonaut are welcome. Please see the [contributing guidelines](CONTRIBUTING.md). From 36328ae52e20f7b4a7d7d9aed60937f0eeb65b02 Mon Sep 17 00:00:00 2001 From: Dan Cummins Date: Sun, 29 Sep 2024 14:43:24 +0100 Subject: [PATCH 3/3] Add workflow to build documentation, --- .github/workflows/docs.yml | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/docs.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..afebb57 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,39 @@ +name: "Build documentation" +on: + pull_request: + branches: + - main + push: + branches: + - main + workflow_dispatch: +jobs: + build: + timeout-minutes: 5 + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: "pip" + cache-dependency-path: "requirements-dev.txt" + - name: Gather dependencies + run: | + pip install -U pip + pip install -r requirements-dev.txt + - name: Build HTML + run: sphinx-build -b html docs/source docs/build/html + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: html-docs + path: docs/build/html/ + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + if: github.ref == 'refs/heads/main' + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: docs/build/html