Skip to content

Commit 2628c0e

Browse files
svekarsfacebook-github-bot
authored andcommitted
Fix index.rst links to tutorials (#737)
Summary: Pull Request resolved: #737 - Fix links to tutorials - Add logic to copy .md files from "tutorials_source/" to "tutorials/" so that they can be added to the build and have urls like tutorials/<tutorial_name>.html instead of tutorials_source/... * Update instructions on how to add a tutorial from a dir outside of doc build. Reviewed By: dbort Differential Revision: D50091328 fbshipit-source-id: 1632fc027fd9a91b44306c5bd697e5c7223aba99
1 parent f529443 commit 2628c0e

File tree

6 files changed

+147
-61
lines changed

6 files changed

+147
-61
lines changed

docs/README.md

Lines changed: 114 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# ExecuTorch Documentation
22

3-
Welcome to the ExecuTorch documentation! This README.md will provide an
4-
overview of the ExecuTorch docs and its features, as well as instructions on
5-
how to contribute and build locally.
3+
Welcome to the ExecuTorch documentation! This README.md will provide an overview
4+
of the ExecuTorch docs and its features, as well as instructions on how to
5+
contribute and build locally.
66

77
All current documentation is located in the `docs/source` directory.
88

@@ -13,12 +13,11 @@ All current documentation is located in the `docs/source` directory.
1313
- [Using Custom Variables](#using-custom-variables)
1414
- [Including READMEs to the Documentation Build](#including-readmes-to-the-documentation-build)
1515
- [Contributing](#contributing)
16+
- [Adding Tutorials](#adding-tutorials)
1617
- [Auto-generated API documentation](#auto-generated-api-documentation)
1718
- [Python APIs](#python-apis)
1819
- [C++ APIs](#c-apis)
19-
20-
<!-- tocstop -->
21-
20+
<!-- tocstop -->
2221

2322
## Toolchain Overview
2423

@@ -73,12 +72,12 @@ To build the documentation locally:
7372
make html
7473
```
7574

76-
This should build both documentation and tutorials. The build will be
77-
placed in the `_build` directory.
75+
This should build both documentation and tutorials. The build will be placed
76+
in the `_build` directory.
7877

79-
1. You can preview locally by using [sphinx-serve](https://pypi.org/project/sphinx-serve/).
80-
To install sphinx-serve, run: `pip3 install sphinx-serve`. To serve
81-
your documentation:
78+
1. You can preview locally by using
79+
[sphinx-serve](https://pypi.org/project/sphinx-serve/). To install
80+
sphinx-serve, run: `pip3 install sphinx-serve`. To serve your documentation:
8281

8382
```
8483
sphinx-serve -b _build
@@ -89,11 +88,10 @@ To build the documentation locally:
8988

9089
## Using Custom Variables
9190

92-
You can use custom variables in your `.md` and `.rst` files.
93-
The variables take their values from the files listed in the
94-
`./.ci/docker/ci_commit_pins/` directory.
95-
For example, to insert a variable that specifies the latest Buck2 version,
96-
use the following syntax:
91+
You can use custom variables in your `.md` and `.rst` files. The variables take
92+
their values from the files listed in the `./.ci/docker/ci_commit_pins/`
93+
directory. For example, to insert a variable that specifies the latest Buck2
94+
version, use the following syntax:
9795

9896
```
9997
The current version of Buck2 is ${executorch_version:buck2}.
@@ -105,59 +103,120 @@ This will result in the following output:
105103

106104
We have the following custom variables defined in this docset:
107105

108-
* `${executorch_version:buck2}`
109-
* `${executorch_version:nightly}`
110-
* `${executorch_version:pytorch}`
111-
* `${executorch_version:vision}`
112-
* `${executorch_version:audio}`
113-
106+
- `${executorch_version:buck2}`
107+
- `${executorch_version:nightly}`
108+
- `${executorch_version:pytorch}`
109+
- `${executorch_version:vision}`
110+
- `${executorch_version:audio}`
114111

115112
You can use the variables in both regular text and code blocks.
116113

117-
118114
## Including READMEs to the Documentation Build
119115

120-
You might want to include some of the `README.md` files from various
121-
directories in this repositories in your documentation build.
122-
To do that, create an `.md` file and use the `{include}` directive to
123-
insert your `.md` files. Example:
116+
You might want to include some of the `README.md` files from various directories
117+
in this repositories in your documentation build. To do that, create an `.md`
118+
file and use the `{include}` directive to insert your `.md` files. Example:
124119

125-
```
120+
````
126121
```{include} ../README.md
127-
```
122+
````
128123

129-
**NOTE:** Many `README.md` files are written as placeholders with limited information
130-
provided. Some of that content you might want to keep in the repository rather
131-
than on the website. If you still want to add it, make sure to check
132-
the content for accuracy, structure, and overall quality.
124+
**NOTE:** Many `README.md` files are written as placeholders with limited
125+
information provided. Some of that content you might want to keep in the
126+
repository rather than on the website. If you still want to add it, make sure to
127+
check the content for accuracy, structure, and overall quality.
133128

134129
## Contributing
135130

136-
Use the [PyTorch contributing guidelines](https://github.com/pytorch/pytorch/blob/main/CONTRIBUTING.md#writing-documentation)
131+
Use the
132+
[PyTorch contributing guidelines](https://github.com/pytorch/pytorch/blob/main/CONTRIBUTING.md#writing-documentation)
137133
to contribute to the documentation.
138134

139-
In addition to that, see [Markdown in Sphinx Tips and Tricks](https://pytorch.org/executorch/markdown-sphinx-tips-tricks.html)
135+
In addition to that, see
136+
[Markdown in Sphinx Tips and Tricks](https://pytorch.org/executorch/markdown-sphinx-tips-tricks.html)
140137
for tips on how to author high-quality markdown pages with Myst Parser.
141138

139+
## Adding Tutorials
140+
141+
You can add both interactive (`.py`) and non-interactive tutorials (`.md`) to
142+
this documentation. All tutorials should go to the `tutorials_source/`
143+
directory. Use one of the following templates:
144+
145+
- [Python Template](https://github.com/pytorch/executorch/blob/main/docs/source/tutorials_source/template_tutorial.py)
146+
- [Markdown template](https://github.com/pytorch/executorch/blob/main/docs/source/tutorial-template.md)
147+
148+
After creating a tutorial, make sure to add the corresponding path in the
149+
[index.rst](./source/index.rst) file in the following places:
150+
151+
- In the
152+
[tutorials torctree](https://github.com/pytorch/executorch/blob/main/docs/source/index.rst?plain=1#L183)
153+
- In the
154+
[customcard section](https://github.com/pytorch/executorch/blob/main/docs/source/index.rst?plain=1#L201)
155+
156+
If you want to include a Markdown tutorial that is stored in another directory
157+
outside of the `docs/source` directory, complete the following steps:
158+
159+
1. Create an `.md` file under `source/tutorials_source`. Name that file after
160+
your tutorial.
161+
2. Include the following in that file:
162+
163+
````
164+
---
165+
orphan: true
166+
---
167+
```{include} ../path-to-your-file/outside-of-the-docs-dir.md```
168+
````
169+
170+
**NOTE:** Your tutorial source file needs to follow the tutorial template.
171+
172+
3. Add the file that you have created in **Step 1** to the `index.rst` toctree
173+
and add a `customcarditem` with the link to that file.
174+
175+
For example, if I wanted to include the `README.md` file from
176+
`examples/selective_build` as a tutorial under
177+
`pytorch.org/executorch/tutorials`, I could create a file called
178+
`tutorials_source/selective-build-tutorial.md` and add the following to that
179+
file:
180+
181+
````
182+
---
183+
orphan: true
184+
---
185+
186+
```{include} ../../../examples/selective_build/README.md
187+
````
188+
189+
In the `index.rst` file, I would add `tutorials/selective-build-tutorial` in
190+
both the `toctree` and the `cusotmcarditem` sections.
191+
142192
# Auto-generated API documentation
143193

144194
On a high level (will go into detail later), we use Sphinx to generate both
145195
Python and C++ documentation in the form of HTML pages.
146196

147197
### Python APIs
148198

149-
We generate Python API documentation through Sphinx, bootstrapping [PyTorch's
150-
Sphinx theme](https://github.com/pytorch/pytorch_sphinx_theme) for
151-
a cohesive look with the existing PyTorch API documentation.
199+
We generate Python API documentation through Sphinx, bootstrapping
200+
[PyTorch's Sphinx theme](https://github.com/pytorch/pytorch_sphinx_theme) for a
201+
cohesive look with the existing PyTorch API documentation.
152202

153203
The setup for Python documentation lies within `source_py/`. To set up Sphinx, a
154204
`conf.py` configuration file is required. We can specify ways to generate
155205
documentation here. Specifically, the most important/relevant parts are:
156206

157-
* Make sure to add a path to the directory above the directory you're trying to generate documentation for. For example, since we want to generate documentation for the `executorch/` directory. This tells Sphinx where to find the code to generate docs for.
207+
- Make sure to add a path to the directory above the directory you're trying to
208+
generate documentation for. For example, since we want to generate
209+
documentation for the `executorch/` directory. This tells Sphinx where to find
210+
the code to generate docs for.
158211

159-
* `extensions` contains extension modules. For auto-generating APIs, make sure to include `sphinx.ext.autodoc`.
160-
* `autodoc_mock_imports` is where you put imports that Sphinx is unable to access. Sphinx runs your code in order to autogenerate the docs, so for any libraries that it unable to access due to it being outside of the directory, or containing c++ bindings, we need to specify it in the `autodoc_mock_imports` list. You can see what modules Sphinx is confused by when you run into importing errors when generating docs.
212+
- `extensions` contains extension modules. For auto-generating APIs, make sure
213+
to include `sphinx.ext.autodoc`.
214+
- `autodoc_mock_imports` is where you put imports that Sphinx is unable to
215+
access. Sphinx runs your code in order to autogenerate the docs, so for any
216+
libraries that it unable to access due to it being outside of the directory,
217+
or containing c++ bindings, we need to specify it in the
218+
`autodoc_mock_imports` list. You can see what modules Sphinx is confused by
219+
when you run into importing errors when generating docs.
161220

162221
Additionally, RST files are needed in order to specify the structure of the
163222
auto-generated pages and to tell Sphinx what modules to generate documentation
@@ -177,22 +236,21 @@ executorch.exir
177236
:show-inheritance:
178237
```
179238

180-
These separate RST files should all be linked together, with the initial
181-
landing page under `index.rst`. A sample of this structure can be found in
182-
`source_py/`.
239+
These separate RST files should all be linked together, with the initial landing
240+
page under `index.rst`. A sample of this structure can be found in `source_py/`.
183241

184-
A diagram of how the files work together:
185-
![image](python_docs.png)
242+
A diagram of how the files work together: ![image](python_docs.png)
186243

187244
To view your changes on the ExecuTorch website, you can follow the same steps
188245
listed in the "General Documentation" section.
189246

190247
To view just the auto-generated pages:
248+
191249
1. `cd executorch/docs/`
192-
2. `sphinx-build -M html source_py sphinxbuild_py`
193-
to build Sphinx and generate APIs any packages.
194-
3. `python3 -m http.server 8000 --directory sphinxbuild_py/html` to view your HTML
195-
files at `localhost:8000`.
250+
2. `sphinx-build -M html source_py sphinxbuild_py` to build Sphinx and generate
251+
APIs any packages.
252+
3. `python3 -m http.server 8000 --directory sphinxbuild_py/html` to view your
253+
HTML files at `localhost:8000`.
196254

197255
### C++ APIs
198256

@@ -212,22 +270,21 @@ To configure Doxygen, we can run `doxygen -g` in the root of our repository (ex.
212270
generating c++ documentation. Specifically, the most important/relevant parts
213271
are:
214272

215-
* `OUTPUT_DIRECTORY` specifies where to output the auto-generated XML files
216-
* `INPUT` specifies which files to generate documenation for
217-
* `GENERATE_XML = YES`
273+
- `OUTPUT_DIRECTORY` specifies where to output the auto-generated XML files
274+
- `INPUT` specifies which files to generate documenation for
275+
- `GENERATE_XML = YES`
218276

219277
Following PyTorch's `conf.py`
220278
[file](https://github.com/pytorch/pytorch/blob/master/docs/cpp/source/conf.py),
221279
we can set up our own `conf.py` file to take in the directory in which we
222280
generated the XML files, and output HTML to another directory. A sample of this
223281
structure can be found in `source_cpp/`.
224282

225-
A diagram of how the files work together:
226-
![image](cpp_docs.png)
283+
A diagram of how the files work together: ![image](cpp_docs.png)
227284

228285
To view the C++ API documentation locally, run:
229286

230287
1. `cd executorch/docs/`
231288
2. `sphinx-build -M html source_cpp sphinxbuild_cpp`
232-
3. `python3 -m http.server 8000 --directory sphinxbuild_py/html` to view your HTML
233-
files at `localhost:8000`.
289+
3. `python3 -m http.server 8000 --directory sphinxbuild_py/html` to view your
290+
HTML files at `localhost:8000`.

docs/source/_templates/layout.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
</script>
5555

5656
{{ super() }}
57-
// Patch up links to point to ExecuTorch URLs instead of to
58-
// pytorch/pytorch URLs.
5957
<script type="text/javascript">
6058
$(document).ready(function () {
6159
// Patch links on interactive tutorial pages to point

docs/source/build-run-xtensa.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ On top of being able to run on the Xtensa HiFi4 DSP another goal of this tutoria
4141

4242
::::{grid} 2
4343
:::{grid-item-card} What you will learn in this tutorial:
44-
:class-card: card-learn
44+
:class-card: card-prerequisites
4545
* In this tutorial you will learn how to export a quantized model with linear and batch norm ops targeted for the Xtensa HiFi4 DSP.
4646
* You will also learn how to compile and deploy the ExecuTorch runtime with the kernels required for running the quantized model generated in the previous step on the Xtensa HiFi4 DSP.
4747
:::

docs/source/conf.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
# add these directories to sys.path here. If the directory is relative to the
1919
# documentation root, use os.path.abspath to make it absolute, like shown here.
2020
#
21+
import distutils.file_util
22+
import glob
2123
import os
2224
import sys
2325

@@ -93,6 +95,22 @@
9395
"first_notebook_cell": ("%matplotlib inline"),
9496
}
9597

98+
assert len(sphinx_gallery_conf["examples_dirs"]) == len(
99+
sphinx_gallery_conf["gallery_dirs"]
100+
), "Lengths of galery_dirs and examples_dir must be same."
101+
102+
for i in range(len(sphinx_gallery_conf["examples_dirs"])):
103+
gallery_dir = sphinx_gallery_conf["gallery_dirs"][i]
104+
source_dir = sphinx_gallery_conf["examples_dirs"][i]
105+
106+
# Create gallery dirs if it doesn't exist
107+
os.makedirs(gallery_dir, exist_ok=True)
108+
109+
# Copy .md files from source dir to gallery dir
110+
for f in glob.glob(os.path.join(source_dir, "*.md")):
111+
112+
distutils.file_util.copy_file(f, gallery_dir, update=True)
113+
96114
source_suffix = [".rst", ".md"]
97115

98116

docs/source/executorch_custom_versions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,17 @@ def replace_variables(app, doctree, docname):
6262
# CSS classes. Otherwise, the sphinx-gallery generated outputs are
6363
# formatted as regular code blocks with gray background instead of pink.
6464
is_sphinx_gallery = any("sphx-glr" in class_ for class_ in classes)
65+
66+
language = node.get("language")
67+
6568
if is_sphinx_gallery:
6669
new_literal_block = nodes.literal_block(new_text, new_text, classes=classes)
6770
else:
6871
new_literal_block = nodes.literal_block(
69-
new_text, new_text, classes=["highlight-none", "notranslate"]
72+
new_text,
73+
new_text,
74+
classes=["highlight-none", "notranslate"],
75+
language=language,
7076
)
7177

7278
node.parent.replace(node, new_literal_block)

docs/source/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,12 @@ ExecuTorch tutorials.
226226
:image: _static/img/android_app.png
227227
:link: demo-apps-android.html
228228
:tags: Delegation,Android
229+
230+
.. customcarditem::
231+
:header: Building and Running ExecuTorch on Xtensa HiFi4 DSP
232+
:card_description: A tutorial that walks you through the process of building ExecuTorch for an Xtensa Hifi4 DSP.
233+
:image: _static/img/generic-pytorch-logo.png
234+
:link: build-run-xtensa.html
235+
:tags: DSP
229236

230237
.. customcardend::

0 commit comments

Comments
 (0)