|
| 1 | + |
| 2 | +# Documentation Site Using Sphinx |
| 3 | + |
| 4 | +This document includes: |
| 5 | +- [The Sphinx local directory structure](#local-directory-structure) |
| 6 | +- [Sphinx commands](#sphinx-commands) |
| 7 | +- [Guide to updating the documentation site](#updating-the-documentation-site) |
| 8 | +- [Helpful sphinx features](#helpful-sphinx-features) |
| 9 | +- [Site Deployment](#deploying-the-documentation-site-using-github-actions) |
| 10 | + |
| 11 | + |
| 12 | +## Local Directory Structure |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +## Sphinx Commands |
| 17 | + |
| 18 | +### Dependencies |
| 19 | + |
| 20 | +Included in `coderdata/docs/requirements.txt`. Example installations that enable various sphinx extensions. |
| 21 | + |
| 22 | +- sphinx |
| 23 | +- myst-parser - adds support for markdown files |
| 24 | +- sphinx-design - provides extra design functions (i.e buttons and grids) |
| 25 | +- nbsphinx - enables rendering of .ipynb files |
| 26 | +- sphinx_tabs - adds tabbed content components |
| 27 | + |
| 28 | +### Build |
| 29 | + |
| 30 | +To build the Sphinx documentation locally, navigate to the `docs/` directory and run the `sphinx-build` command. This command processes the content files from the `docs/source/` directory and generates the rendered HTML output in the `docs/build/` directory. |
| 31 | + |
| 32 | +```sh |
| 33 | +$ cd ../coderdata/docs |
| 34 | + |
| 35 | +$ python -m sphinx.cmd.build -M html <SOURCEDIR/> <OUTPUTDIR/> |
| 36 | + |
| 37 | +$ python -m sphinx.cmd.build -M html source/ build/ |
| 38 | +``` |
| 39 | +To view the rendered site open `coderdata/docs/build/html/index.html`. |
| 40 | + |
| 41 | +### Quickstart |
| 42 | + |
| 43 | +To create a basic sphinx set-up in a local repository use sphinx quickstart command. |
| 44 | + |
| 45 | +```sh |
| 46 | +$ cd ../repo/docs |
| 47 | +$ python -m sphinx.cmd.quickstart |
| 48 | +``` |
| 49 | +Questions will follow this command and when it prompts if you'd like to separate the source and build directories select yes. |
| 50 | + |
| 51 | +## Updating the Documentation Site |
| 52 | + |
| 53 | +The `conf.py` file is the central configuration file for Sphinx and it determines the behavior and appearance of the generated documentation. Specifically it configures extensions, defines metadata, controls output settings, and customizes sphinx behavior. The `index.rst` file is the starting page for the Sphinx documentation build process. It acts as the root file, linking all other pages and defining the document hierarchy. All other .md and .rst files are added and internally referenced within the index page and/or within the sidebar. |
| 54 | + |
| 55 | +### Pages |
| 56 | +**Note:** All updates will be made in the `documentation-staging` branch.\ |
| 57 | +To update pages navigate to `docs/source/`, all .rst and .md files live here. Here is a reference of the main pages used for the documentation site. The tutorial page consists if the docsite_tutorial.ipynb converted to an html. The notebook lives in `docs/source/_notebooks/` and is converted to an html during the build process based on code within `conf.py`. |
| 58 | + |
| 59 | +| Page | File Name | Content | |
| 60 | +| -----------------| ----------------------------------------------------------------------- | ------------------------------ | |
| 61 | +| Home Page | index.rst | Introduction and Install | |
| 62 | +| Usage | usage.md | API and CLI | |
| 63 | +| API Reference | APIreference.rst | Autogenerated documentation from docstrings| |
| 64 | +| Datasets | datasets_included.rst | Datasets overview | |
| 65 | +| Tutorial | docsite_tutorial.ipynb | Deep Learning Tutorial | |
| 66 | +| Contributing | contribution_guide.rst *includes contribution.md and add_code_guide.md* | Contribution Guide | |
| 67 | + |
| 68 | +**Note:** |
| 69 | +- When adding pages, reStructuredText files are the most sphinx friendly and allow for use of helpful directives. However, Markdown files can be used and will render properly when the myst-parser extension is used. |
| 70 | +- New pages must be added to the `.. toctree::` in the `index.rst` to be recognized by Sphinx. |
| 71 | +- Currently the API reference does not include documentation for `plot_2D_respones_metric`, `format`, `split_train_test_validate`, and `split_train_other`. It seems that the most updated `coderdata` directory currently does not include docstrings for these functions. |
| 72 | + |
| 73 | +### Tutorial |
| 74 | + |
| 75 | +The tutorial is sourced in `source/_notebooks/` and when built pushed to `_notebooks/` in `gh-pages` branch. It uses nbsphinx extension to convert from .ipynb to an html and is referenced in the `index.rst` and the `my_custom_sidebar.html`. The dependencies for this should only be needed in your local environment and not in the `requirements.txt`. |
| 76 | + |
| 77 | +### Images and Graphics |
| 78 | + |
| 79 | +To add any new images they will live in `docs/source/_static/` and when built are pushed to `_images` in `gh-pages` branch. The coderdata_header.jpg was made using [canva](https://www.canva.com/) and coderdata_1.jpg was made using biorender. |
| 80 | + |
| 81 | +### Site Theme and Design |
| 82 | + |
| 83 | +The original sphinx theme used is 'sphinxdoc', however, to change certain aspects I created `custom.css` to override the sphinxdoc theme. To update the custom theme navigate to `docs/source/_static/custom.css`. Changes to the sidebar can be made in `docs/source/_templates/my_custom_sidebar.html`. Any other custom templates will be added to `docs/source/_templates/`. |
| 84 | + |
| 85 | +**Note:** The sphinxdoc theme is auto-generated during the build command into `docs/build/html/_static/sphinxdoc.css`. It is regenerated everytime sphinx build runs so changes must be made in custom.css. |
| 86 | + |
| 87 | + |
| 88 | +## Helpful Sphinx Features |
| 89 | + |
| 90 | +### Site Links |
| 91 | + |
| 92 | +- [sphinx-doc.org](https://www.sphinx-doc.org/en/master/index.html) |
| 93 | +- [sphinx.org/sample-sites](https://sphinx-themes.org/sample-sites/default-sphinxdoc/) |
| 94 | +- [sphinx.org/directives](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#rst-directives) |
| 95 | + |
| 96 | + |
| 97 | +### Directives and Examples Used in CoderData Documentation |
| 98 | + |
| 99 | +- .. automodule:: |
| 100 | +This is used to generate documentation from the package. It is used in API reference. |
| 101 | + |
| 102 | +```sh |
| 103 | +.. automodule:: <pkg>.module |
| 104 | + :members: <function> |
| 105 | + :undoc-members: |
| 106 | + :show-inheritance: |
| 107 | +``` |
| 108 | + |
| 109 | +- .. include:: |
| 110 | +To include content from another file. Example shows how to render a markdown file when using the include call. |
| 111 | + |
| 112 | +```sh |
| 113 | +.. include:: guide.md |
| 114 | + :parser: myst_parser.sphinx_ |
| 115 | +``` |
| 116 | + |
| 117 | +- .. image:: |
| 118 | + |
| 119 | +```sh |
| 120 | +.. image:: _static/image.png |
| 121 | + :align: center |
| 122 | + :scale: 100% |
| 123 | +``` |
| 124 | +## Deploying the Documentation Site Using Github Actions |
| 125 | + |
| 126 | +### Directory Structure for Deployment with Relevant Branches |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | +### Site Deployment |
| 131 | + |
| 132 | +- We added `sphinx.yml` to the `.github/workflows/` directory in the `documentation-staging` branch. |
| 133 | + |
| 134 | +- Then in `documentation-staging` we included all the source directory files that are needed to build the documentation. (These are all the same files that are needed to build the documentation locally, the only addition is `requirements.txt`). |
| 135 | +**Note:** If you have been building the documentation locally and then are moving to commit to the staging branch there is no need to include any files from `docs/build/` directory. |
| 136 | + |
| 137 | +- Once a push is made from `documentation-staging` the workflow is triggered. |
| 138 | + |
| 139 | +- The built html files are then deployed to the root of the `gh-pages` branch. The included files in the branch are shown in the graphic above. |
| 140 | + |
| 141 | +**Note:** When updates to the python files in `coderdata` directory occur in `main`, those changes must be transfered to the `documentation-staging` branch in order for Sphinx to see the updated docstrings with the functions and correctly autogenerate the documentation for the API reference page. |
0 commit comments