Skip to content

Commit 52cecac

Browse files
authored
docs: resolve Sphinx warnings caused by API reference and add Macaron style guide (#440)
Closes #433. Resolve Sphinx warnings caused by: 1. using the `__all__` variable in `__init__.py` files 2. naming two or more classes with the same name 3. using `numpydoc` style `Attribute` section in class docstring Add a style guide page to Macaron documentation. --------- Signed-off-by: Nathan Nguyen <[email protected]>
1 parent 71accbf commit 52cecac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+314
-129
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ git commit --signoff
2727

2828
Finally, make sure to sign your commits using a GPG key. See the instructions [here](https://docs.github.com/en/authentication/managing-commit-signature-verification/generating-a-new-gpg-key) for more information. A green `verified` label will appear next to your commit on GitHub if it is successfully signed.
2929

30+
### Style Guide
31+
32+
See our [Macaron Style Guide](./docs/source/pages/developers_guide/style_guide.rst).
3033

3134
### Pull request process
3235

@@ -135,9 +138,9 @@ Ideally, the GitHub token must have **read** permissions for the repositories th
135138

136139
After generating a GitHub personal-access token, please store its value in an environment variable called ``GITHUB_TOKEN``. This environment variable will be read by Macaron for its **analyze** command.
137140

138-
### Running checks and tests locally
141+
## Running checks and tests locally
139142

140-
#### Git hooks
143+
### Git hooks
141144

142145
Using the pre-commit tool and its `.pre-commit-config.yaml` configuration, a number of [pre-commit hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_committing_workflow_hooks) ensure that your code is formatted correctly.
143146

@@ -156,7 +159,7 @@ make check
156159
runs _all_ installed git hooks over your code. For more control over the code checks, the Makefile also implements the `check-bandit`, `check-flake8`, `check-lint`, `check-mypy`, and `check-actionlint` goals.
157160

158161

159-
#### Testing
162+
### Testing
160163

161164
This repository is set up to test either standalone or as a pre-push git hook. Tests are stored in the `tests/` folder, and you can run them manually like so:
162165
```bash
@@ -172,9 +175,9 @@ make integration-test
172175
Note that integration tests can take a long time to complete. Also the repositories that we clone for these tests will be stored under `output/` directory. If you do not remove/move this directory and run the pre-commit tool you might get errors.
173176

174177

175-
#### Generating documentation
178+
## Generating documentation
176179

177-
As mentioned above, all package code should make use of [Python docstrings](https://www.python.org/dev/peps/pep-0257/) in [reStructured text format](https://www.python.org/dev/peps/pep-0287/). Using these docstrings and the documentation template in the `docs/source/` folder, you can then generate proper documentation in different formats using the [Sphinx](https://github.com/sphinx-doc/sphinx/) tool:
180+
As mentioned above, all package code should make use of [Python docstrings](https://www.python.org/dev/peps/pep-0257/) in [reStructured text format](https://www.python.org/dev/peps/pep-0287/) following [numpydoc style](https://numpydoc.readthedocs.io/en/latest/format.html) (with some exceptions - see our [style guide](https://oracle.github.io/pages/developers_guide/style_guide.html#docstrings)). Using these docstrings and the documentation template in the `docs/source/` folder, you can then generate proper documentation in different formats using the [Sphinx](https://github.com/sphinx-doc/sphinx/) tool:
178181

179182
```bash
180183
make docs

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-build-epoch.txt:
304304
docs: docs-clean
305305
$(MAKE) -C docs/ html
306306

307+
# Generate API reference pages in the documentation using `sphinx-apidoc`.
308+
.PHONY: docs-api
309+
docs-api:
310+
sphinx-apidoc --no-toc --module-first --force --maxdepth 1 --output-dir docs/source/pages/developers_guide/apidoc/ src/
311+
312+
# Combine the two targets `docs-api` and `docs`:
313+
# First generate API reference pages, then build the HTML documentation.
314+
.PHONY: docs-full
315+
docs-full: docs-api docs
307316

308317
# Build the Docker image. The image name and tag are read from IMAGE_NAME and RELEASE_TAG
309318
# environment variables, respectively. By default "test" is used as the image tag.

docs/README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,26 @@ This command will build and generate the documentation into `docs/_build/html`.
1616
python3 -m http.server -d docs/_build/html
1717
```
1818

19-
## Extend the API reference.
19+
## Extend the API reference
2020

21-
If you add a new module, make sure that it is added to the API reference. The API reference is generated using the [sphinx-apidoc](https://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html) tool.
21+
We use the [sphinx-apidoc](https://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html) tool to generate API reference automatically from Python docstrings. See the [Docstring section in the Macaron Style Guide](https://oracle.github.io/pages/developers_guide/style_guide.html#docstrings) for how to write docstrings in Macaron.
22+
23+
If you make a code change, make sure to regenerate the API reference by running (with the dev environment activated):
24+
25+
```
26+
make docs-api
27+
```
28+
29+
This command uses [sphinx-apidoc](https://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html) to generate the API reference RST files into `docs/source/pages/developers_guide/apidoc/`. Make sure to check in these API reference RST files to the repository.
30+
31+
You can then rebuild the whole HTML documentation with:
2232

23-
From within the root directory of Macaron, run (with the dev environment activated):
2433
```
25-
sphinx-apidoc --no-toc --module-first --force --maxdepth 1 --output-dir docs/source/pages/apidoc/ src/
34+
make docs
2635
```
2736

28-
This command will generate the API reference RST files into `docs/source/pages/apidoc/`. Make sure to check in the changed source files to the repository.
37+
In addition, instead of running `make docs-api` and `make docs` separately, you can combine the two commands by running:
38+
39+
```
40+
make docs-full
41+
```

docs/source/conf.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,21 @@
3030
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
3131

3232
extensions = [
33-
"sphinx.ext.napoleon",
34-
"sphinx.ext.autodoc",
35-
"sphinx.ext.autosectionlabel",
36-
"sphinx_autodoc_typehints",
37-
"numpydoc",
38-
"sphinx_tabs.tabs",
33+
"sphinx.ext.napoleon", # Support parsing numpydoc style docstrings
34+
"sphinx.ext.autodoc", # Support generating API reference from docstrings
35+
"sphinx.ext.autosectionlabel", # Support referencing sections using their titles
36+
"sphinx.ext.intersphinx", # Support referencing external APIs
37+
"sphinx_autodoc_typehints", # Resolve type annotations in docstrings
38+
"numpydoc", # Support numpydoc style docstrings
39+
"sphinx_tabs.tabs", # Support tabbed views in documentation
3940
]
4041
autosectionlabel_prefix_document = True
4142
autosectionlabel_maxdepth = 2
4243
autodoc_member_order = "bysource"
4344
numpydoc_show_class_members = False
4445

46+
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
47+
4548
templates_path = ["_templates"]
4649
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".venv"]
4750

docs/source/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ concrete rules that can be checked automatically. Macaron has a customizable che
3636
Getting started
3737
---------------
3838

39-
To start with Macaron, see our :doc:`Installation </pages/installation>` and :doc:`Using </pages/using>` pages.
39+
To start with Macaron, see the :doc:`Installation </pages/installation>` and :doc:`Using </pages/using>` pages.
4040

41-
For all services and technologies that Macaron supports, see our :doc:`Supported Technologies </pages/supported_technologies/index>` page.
41+
For all services and technologies that Macaron supports, see the :doc:`Supported Technologies </pages/supported_technologies/index>` page.
4242

4343
-------------------------
4444
Current checks in Macaron
@@ -106,4 +106,4 @@ intermediate representations as abstractions. Using such abstractions, Macaron i
106106
pages/output_files
107107
pages/cli_usage/index
108108
pages/supported_technologies/index
109-
pages/apidoc/index
109+
pages/developers_guide/index

docs/source/pages/apidoc/index.rst renamed to docs/source/pages/developers_guide/apidoc/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
.. Copyright (c) 2022 - 2023, Oracle and/or its affiliates. All rights reserved.
22
.. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
33
4-
===================
5-
Developer Reference
6-
===================
4+
=====================
5+
Macaron API Reference
6+
=====================
77

88
.. toctree::
99
:maxdepth: 1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)