Skip to content

Commit 0692aff

Browse files
svekarsfacebook-github-bot
authored andcommitted
Fix formatting and cleanup (#593)
Summary: Pull Request resolved: #593 - Added a check to the custom role to ensure sphx-gallery outputs are not affected. - Removed template tutorial custom card from index.rst - Don't generate tutorials/index.html - because sphinx autogenerates a page with all tutorials that is hard to format. - Added sys.path so we can use autodoc in .md files. Reviewed By: mergennachin Differential Revision: D49878715 fbshipit-source-id: b9f649b17d81dca4879ca82887a6574bb8c33030
1 parent 79f3db2 commit 0692aff

File tree

5 files changed

+45
-20
lines changed

5 files changed

+45
-20
lines changed

docs/README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Welcome to the ExecuTorch documentation! This README.md will provide an
44
overview of the ExecuTorch docs and its features, as well as instructions on
55
how to contribute and build locally.
66

7+
All current documentation is located in the `docs/source` directory.
8+
79
<!-- toc -->
810

911
- [Toolchain Overview](#toolchain-overview)
@@ -31,28 +33,42 @@ We support both `.rst` and `.md` files but prefer the content to be authored in
3133

3234
## Building Locally
3335

34-
Documentation dependancies are stored in
36+
Documentation dependencies are stored in
3537
[.ci/docker/requirements-ci.txt](https://github.com/pytorch/executorch/blob/main/.ci/docker/requirements-ci.txt).
3638

3739
To build the documentation locally:
3840

39-
1. Clone the executorch repo to your machine.
41+
1. Clone the ExecuTorch repo to your machine.
4042

4143
1. Switch to the `docs/` directory.
4244

43-
1. Start a virtual environment:
45+
1. If you don't have it already, start a conda environment:
46+
47+
```{note}
48+
The below command generates a completely new environment and resets
49+
any existing dependencies. If you have an environment already, skip
50+
the `conda create` command.
51+
```
52+
53+
```bash
54+
conda create -yn executorch python=3.10.0
55+
conda activate executorch
56+
```
57+
58+
1. Install dependencies:
4459

4560
```bash
46-
virtualenv venv
47-
source venv/bin/activate
61+
pip3 install -r ./.ci/docker/requirements-ci.txt
4862
```
4963

50-
1. Install dependancies:
64+
1. Run:
5165

5266
```bash
53-
pip3 install -r ../.ci/docker/requirements-ci.txt
67+
bash install_requirements.sh
5468
```
5569

70+
1. Go to the `docs/` directory.
71+
5672
1. Build the documentation set:
5773

5874
```
@@ -132,15 +148,15 @@ Python and C++ documentation in the form of HTML pages.
132148

133149
### Python APIs
134150

135-
We generate Python API documentation through Sphinx, bootstrapping [Pytorch's
151+
We generate Python API documentation through Sphinx, bootstrapping [PyTorch's
136152
Sphinx theme](https://github.com/pytorch/pytorch_sphinx_theme) for
137-
a cohesive look with the existing Pytorch API documentation.
153+
a cohesive look with the existing PyTorch API documentation.
138154

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

143-
* 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 documenation for the `executorch/` directory. This tells Sphinx where to find the code to generate docs for.
159+
* 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.
144160

145161
* `extensions` contains extension modules. For auto-generating APIs, make sure to include `sphinx.ext.autodoc`.
146162
* `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.
@@ -170,7 +186,7 @@ landing page under `index.rst`. A sample of this structure can be found in
170186
A diagram of how the files work together:
171187
![image](python_docs.png)
172188

173-
To view your changes on the executorch website, you can follow the same steps
189+
To view your changes on the ExecuTorch website, you can follow the same steps
174190
listed in the "General Documentation" section.
175191

176192
To view just the auto-generated pages:

docs/source/_templates/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@
4343
{% block footer %}
4444
{{ super() }}
4545
<script script type="text/javascript">
46-
var collapsedSections = ['Introduction', 'Getting Started', 'Exporting to ExecuTorch', 'IR Specification', 'Compiler Entry Points', 'Runtime', 'Quantization', 'Kernel Library', 'SDK', 'Tutorials']
46+
var collapsedSections = ['Introduction', 'Getting Started', 'Exporting to ExecuTorch', 'API Reference', 'IR Specification', 'Compiler Entry Points', 'Runtime', 'Quantization', 'Kernel Library', 'SDK', 'Tutorials']
4747
</script>
4848
{% endblock %}

docs/source/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585

8686
sphinx_gallery_conf = {
8787
"examples_dirs": ["tutorials_source"],
88+
"ignore_pattern": "template_tutorial.py",
8889
"gallery_dirs": ["tutorials"],
8990
"filename_pattern": "/tutorials_source/",
9091
"promote_jupyter_magic": True,
@@ -104,6 +105,8 @@
104105
# directories to ignore when looking for source files.
105106
# This pattern also affects html_static_path and html_extra_path.
106107
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "tutorial-template.md"]
108+
exclude_patterns += sphinx_gallery_conf["examples_dirs"]
109+
exclude_patterns += ["*/index.rst"]
107110

108111
# autosectionlabel throws warnings if section names are duplicated.
109112
# The following tells autosectionlabel to not throw a warning for

docs/source/executorch_custom_versions.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,20 @@ def replace_variables(app, doctree, docname):
5656
new_text = node.astext()
5757
for var, value in variables.items():
5858
new_text = new_text.replace(var, value)
59-
node.parent.replace(node, nodes.literal_block(new_text, new_text))
59+
60+
classes = node.get("classes", [])
61+
# check if the output is generated by sphinx-gallery and if yes, keep the original
62+
# CSS classes. Otherwise, the sphinx-gallery generated outputs are
63+
# formatted as regular code blocks with gray background instead of pink.
64+
is_sphinx_gallery = any("sphx-glr" in class_ for class_ in classes)
65+
if is_sphinx_gallery:
66+
new_literal_block = nodes.literal_block(new_text, new_text, classes=classes)
67+
else:
68+
new_literal_block = nodes.literal_block(
69+
new_text, new_text, classes=["highlight-none", "notranslate"]
70+
)
71+
72+
node.parent.replace(node, new_literal_block)
6073

6174

6275
def setup(app):

docs/source/index.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,6 @@ ExecuTorch tutorials.
186186

187187
.. customcardstart::
188188

189-
.. customcarditem::
190-
:header: Template Tutorial
191-
:card_description: A template tutorial. To be deleted.
192-
:image: _static/img/generic-pytorch-logo.png
193-
:link: tutorials/template_tutorial.html
194-
:tags: Template
195-
196189
.. customcarditem::
197190
:header: Exporting to ExecuTorch Tutorial
198191
:card_description: A tutorial for exporting a model and lowering a it to be runnable on the ExecuTorch runtime.

0 commit comments

Comments
 (0)