This repository was archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 718
feat: add demonstration of Sphinx documentation system #732
Open
mattmazzola
wants to merge
2
commits into
facebookresearch:main
Choose a base branch
from
mattmazzola:mattm/meta-sphinx-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Minimal makefile for Sphinx documentation | ||
| # | ||
|
|
||
| # You can set these variables from the command line, and also | ||
| # from the environment for the first two. | ||
| # TODO: Investigate errors during first build | ||
| # SPHINXOPTS ?= -W --keep-going -n | ||
| 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) | ||
|
|
||
| # serves html version of documentation | ||
| serve: | ||
| cd build/html && http-server -v | ||
|
|
||
| # start a watch process that automatically rebuilds the HTML version of | ||
| # the doc every time a file is changed in the `source` folder | ||
| watch: | ||
| watchexec -w .. -e md,rst,py $(MAKE) html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| # 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 datetime | ||
|
|
||
| project = 'Metaseq' | ||
| copyright = f'{datetime.datetime.now().year} , Meta' | ||
| author = 'Meta Research' | ||
|
|
||
| # -- Path setup -------------------------------------------------------------- | ||
|
|
||
| # If extensions (or modules to document with autodoc) are in another directory, | ||
| # add these directories to sys.path here. If the directory is relative to the | ||
| # documentation root, use os.path.abspath to make it absolute, like shown here. | ||
| # | ||
| from glob import glob | ||
| import os | ||
| import shutil | ||
| import sys | ||
|
|
||
| sys.path.insert(0, os.path.abspath('../..')) | ||
|
|
||
| # -- General configuration --------------------------------------------------- | ||
|
|
||
| # Add any Sphinx extension module names here, as strings. They can be | ||
| # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom | ||
| # ones. | ||
| extensions = [ | ||
| "myst_parser", | ||
| "sphinx.ext.autodoc", | ||
| "sphinx.ext.napoleon", | ||
| "sphinx.ext.intersphinx", | ||
| "sphinx.ext.viewcode", | ||
| 'sphinx_copybutton', | ||
| "sphinx_design", | ||
| "sphinxcontrib.mermaid", | ||
| ] | ||
|
|
||
| myst_enable_extensions = [ | ||
| "amsmath", | ||
| "colon_fence", | ||
| "deflist", | ||
| "dollarmath", | ||
| "fieldlist", | ||
| "html_admonition", | ||
| "html_image", | ||
| "linkify", | ||
| "replacements", | ||
| "smartquotes", | ||
| "strikethrough", | ||
| "substitution", | ||
| "tasklist", | ||
| ] | ||
|
|
||
| # Add any paths that contain templates here, relative to this directory. | ||
| templates_path = ['_templates'] | ||
|
|
||
| # List of patterns, relative to source directory, that match files and | ||
| # directories to ignore when looking for source files. | ||
| # This pattern also affects html_static_path and html_extra_path. | ||
| exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] | ||
|
|
||
| suppress_warnings = ["myst.strikethrough"] | ||
|
|
||
| # -- Options for HTML output ------------------------------------------------- | ||
|
|
||
| # The theme to use for HTML and HTML Help pages. See the documentation for | ||
| # a list of builtin themes. | ||
| # | ||
| html_theme = "furo" | ||
| html_title = "Metaseq Documentation" | ||
| html_theme_options = { | ||
| "source_repository": "https://github.com/facebookresearch/metaseq", | ||
| "source_branch": "main", | ||
| "source_directory": "docs/source", | ||
| } | ||
|
|
||
| # Add any paths that contain custom static files (such as style sheets) here, | ||
| # relative to this directory. They are copied after the builtin static files, | ||
| # so a file named "default.css" will overwrite the builtin "default.css". | ||
| html_static_path = ['_static'] | ||
| html_css_files = ["custom.css"] | ||
|
|
||
| # html_logo = "_static/images/logo.svg" | ||
| # html_favicon = '_static/images/logo.svg' | ||
|
|
||
| autodoc_typehints = 'none' | ||
| autodoc_member_order = 'groupwise' | ||
| autodoc_default_options = { | ||
| 'members': True, | ||
| 'member-order': 'bysource', | ||
| 'special-members': '__init__', | ||
| 'exclude-members': '__weakref__' | ||
| } | ||
|
|
||
| # allows us to automatically link to documentation from other libraries | ||
| intersphinx_mapping = { | ||
| "numpy": ("http://docs.scipy.org/doc/numpy/", None), | ||
| "python": ("https://docs.python.org/3.8", None), | ||
| "torch": ("https://pytorch.org/docs/master/", None), | ||
| } | ||
|
|
||
| # -- LaTeX output ------------------------------------------------- | ||
|
|
||
| latex_engine = "xelatex" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| --- | ||
| sd_hide_title: true | ||
| --- | ||
|
|
||
| # Dummy Title | ||
|
|
||
| ```{toctree} | ||
| :hidden: | ||
| :caption: Modifying This Documentation | ||
| :glob: | ||
|
|
||
| modifying_documentation/* | ||
| ``` | ||
|
|
||
| # Metaseq | ||
|
|
||
| Link to <a href="https://github.com/facebookresearch/metaseq" target="_blank">MetaSeq</a> repo |
21 changes: 21 additions & 0 deletions
21
docs/source/modifying_documentation/autodoc_syntax_example.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Embed Module or Function members | ||
|
|
||
| % For explanation of the autodoc generator check out: https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html | ||
|
|
||
| ## Module Members | ||
|
|
||
| ```{eval-rst} | ||
| .. automodule:: metaseq.cli.train | ||
| :members: | ||
| ``` | ||
|
|
||
| ## Method Members | ||
|
|
||
| ```{eval-rst} | ||
| .. automodule:: metaseq.cli.validate | ||
| .. automethod:: metaseq.cli.validate.main(cfg, override_args) | ||
|
|
||
| .. .. autoclass:: Run | ||
| .. :inherited-members: | ||
| .. :members: | ||
| ``` |
9 changes: 9 additions & 0 deletions
9
docs/source/modifying_documentation/interdoc_links_example.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Linking to other Sphinx documentation | ||
|
|
||
| You can link between Sphinx documentation using a `{ref}` instead of a typical URL. | ||
|
|
||
| ## Examples | ||
|
|
||
| - {ref}`Custom Link Text (Torch Utilities) <torch:torch:utilities>` | ||
| - {ref}`torch:generated/torch.cuda.streamcontext:streamcontext` | ||
| - {ref}`torch:community/contribution_guide:getting started` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Example using Mermaid | ||
|
|
||
| [Mermaid](https://mermaid.js.org/intro/) is a JavaScript based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams. | ||
|
|
||
| (section-two)= | ||
| ## Here's another section | ||
|
|
||
| % This comment won't make it into the outputs! | ||
|
|
||
| And here's {ref}`a reference to this section <section-two>`. | ||
| I can also reference the section {ref}`section-two` without specifying my title. | ||
|
|
||
| :::{note} | ||
| And here's a note with a colon fence! | ||
| ::: | ||
|
|
||
| And finally, here's a cool mermaid diagram! | ||
|
|
||
| ```{mermaid} | ||
| sequenceDiagram | ||
| participant Alice | ||
| participant Bob | ||
| Alice->John: Hello John, how are you? | ||
| loop Healthcheck | ||
| John->John: Fight against hypochondria | ||
| end | ||
| Note right of John: Rational thoughts <br/>prevail... | ||
| John-->Alice: Great! | ||
| John->Bob: How about you? | ||
| Bob-->John: Jolly good! | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Overview | ||
|
|
||
| ## Background | ||
|
|
||
| - HTML Documentation is generated using <a href="https://www.sphinx-doc.org/en/master/" target="_blank">Sphinx</a> | ||
| - Theme: [Furo](https://pradyunsg.me/furo/reference/) | ||
| - Here you find information about the reST or Markdown syntax processed by the theme | ||
| - Extensions: | ||
| - Support for <a href="https://www.markdownguide.org/" target="_blank">Markdown (.md)</a> and <a href="https://rstdoc.readthedocs.io/en/latest/readme.html" target="_blank">ReStructured Text (.rst)</a> using [Markedly Structured Text (MyST)](https://myst-parser.readthedocs.io/en/latest/intro.html) | ||
| - Support for <a href="https://mermaid.js.org/" target="_blank">Mermaid Diagrams</a> | ||
|
|
||
| ## Installing Sphinx Dependencies | ||
|
|
||
| If using the .devcontainer, this should already be done. However, you can do it manually by installing the `docs` extra: | ||
|
|
||
| ```bash | ||
| # From the root folder of the repo | ||
| pip install -e ".[docs]" | ||
| ``` | ||
|
|
||
| ## Building the Documentation | ||
|
|
||
| ```bash | ||
| # Watch /docs/source folder and rebuild the documentation on file change | ||
| make watch | ||
| ``` | ||
|
|
||
| This will output to the `/docs/build` folder | ||
|
|
||
| ## Viewing the Documentation | ||
|
|
||
| ```bash | ||
| # Start server to view the documentation | ||
| make serve | ||
| ``` | ||
|
|
||
| ### Open the URL in command output | ||
|
|
||
| http://127.0.0.1:7878/index.html | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see in the video of PR description, our documentation has many more files, but I removed almost all of them except for this PR
This folder to demonstrates how to use rST and markdown syntax within Sphinx to achieve what you want.