Skip to content

Commit 265d044

Browse files
kiukchungfacebook-github-bot
authored andcommitted
Fix //torchx/github/docs:doctest on devservers and rid a few warnings. (#1017)
Summary: Adds documentation and removes a few annoying warnings when building torchx (staticdocs) docs in a devserver. NOTE: The developer still has to manually install `pandoc` by running `dnf install -y pandoc` (this is documented in `//torchx/github/docs/TARGETS`) Reviewed By: andywag Differential Revision: D71421188
1 parent 5efd2b0 commit 265d044

File tree

5 files changed

+72
-31
lines changed

5 files changed

+72
-31
lines changed

docs/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ livehtml:
3333
sphinx-autobuild --watch ../torchx --watch ../examples --re-ignore ".*(examples_.*|.new|source/.*(Dockerfile|.py))" "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
3434

3535
papermill: html
36-
./papermill.sh
36+
./papermill.sh

docs/source/custom_components.md

+14-12
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ jupyter:
1414

1515
# Custom Components
1616

17-
This is a guide on how to build a simple app and custom component spec
18-
and launch it via two different schedulers.
17+
This is a guide on how to build a simple app and custom component spec and
18+
launch it via two different schedulers.
1919

2020
See the [Quickstart Guide](quickstart.md) for installation and basic usage.
2121

22-
2322
## Builtins
2423

25-
Before writing a custom component, check if any of the builtin components satisfy your needs. TorchX provides a number of builtin components with premade images. You can discover them via:
24+
Before writing a custom component, check if any of the builtin components
25+
satisfy your needs. TorchX provides a number of builtin components with premade
26+
images. You can discover them via:
2627

2728
```sh
2829
torchx builtins
@@ -35,7 +36,6 @@ you would any other component.
3536
torchx run utils.echo --msg "Hello :)"
3637
```
3738

38-
3939
## Hello World
4040

4141
Lets start off with writing a simple "Hello World" python app. This is just a
@@ -71,8 +71,8 @@ if __name__ == "__main__":
7171
main(args.user)
7272
```
7373

74-
Now that we have an app we can write the component file for it. This
75-
function allows us to reuse and share our app in a user friendly way.
74+
Now that we have an app we can write the component file for it. This function
75+
allows us to reuse and share our app in a user friendly way.
7676

7777
We can use this component from the `torchx` cli or programmatically as part of a
7878
pipeline.
@@ -99,8 +99,8 @@ def greet(user: str, image: str = "my_app:latest") -> specs.AppDef:
9999
)
100100
```
101101

102-
We can execute our component via `torchx run`. The
103-
`local_cwd` scheduler executes the component relative to the current directory.
102+
We can execute our component via `torchx run`. The `local_cwd` scheduler
103+
executes the component relative to the current directory.
104104

105105
```sh
106106
torchx run --scheduler local_cwd my_component.py:greet --user "your name"
@@ -137,13 +137,15 @@ We can then launch it on the local scheduler.
137137
torchx run --scheduler local_docker my_component.py:greet --image "my_app:latest" --user "your name"
138138
```
139139

140-
If you have a Kubernetes cluster you can use the [Kubernetes scheduler](schedulers/kubernetes.rst) to launch
141-
this on the cluster instead.
142-
140+
If you have a Kubernetes cluster you can use the
141+
[Kubernetes scheduler](schedulers/kubernetes.rst) to launch this on the cluster
142+
instead.
143143

144144
<!-- #md -->
145+
145146
```sh
146147
$ docker push my_app:latest
147148
$ torchx run --scheduler kubernetes my_component.py:greet --image "my_app:latest" --user "your name"
148149
```
150+
149151
<!-- #endmd -->

docs/source/ext/fbcode.py

+44-5
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,60 @@
99
import os
1010

1111
from docutils import nodes
12+
13+
from docutils.parsers.rst import directives
1214
from sphinx.util.docutils import SphinxDirective
1315
from sphinx.util.nodes import nested_parse_with_titles
1416

1517

1618
class FbcodeDirective(SphinxDirective):
19+
"""
20+
Includes the content of this directive if running in fbcode.
21+
22+
Used to add fb-specific (internal) documentation to display in
23+
StaticDocs (https://www.internalfb.com/intern/staticdocs/torchx).
24+
25+
To exclude the contents in the directive (e.g. for oss-only documentation)
26+
when building docs in fbcode, use the ``:exclude:`` option (see example below).
27+
28+
Usage:
29+
30+
```
31+
List of supported components:
32+
33+
* ``utils.python``
34+
35+
.. fbcode::
36+
:exclude:
37+
38+
* ``utils.echo``
39+
40+
.. fbcode::
41+
42+
* ``fb.dist.hpc``
43+
```
44+
45+
In the example above, ``utils.echo`` will be listed only when building outside of fbcode.
46+
Similarly ``fb.dist.hpc`` will be listed only when buildincg in fbcode.
47+
"""
48+
1749
# this enables content in the directive
1850
has_content = True
51+
option_spec = {
52+
"exclude": directives.flag, # if present, includes contents EXCEPT when in fbcode
53+
}
1954

2055
def run(self):
21-
if "fbcode" not in os.getcwd():
56+
exclude_in_fbcode = "exclude" in self.options
57+
is_fbcode = "fbcode" in os.getcwd()
58+
59+
if is_fbcode ^ exclude_in_fbcode:
60+
node = nodes.section()
61+
node.document = self.state.document
62+
nested_parse_with_titles(self.state, self.content, node)
63+
return node.children
64+
else:
2265
return []
23-
node = nodes.section()
24-
node.document = self.state.document
25-
nested_parse_with_titles(self.state, self.content, node)
26-
return node.children
2766

2867

2968
def setup(app):

docs/source/index.rst

-3
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,14 @@ Works With
111111

112112
Examples
113113
------------
114-
115114
.. toctree::
116115
:maxdepth: 1
117116
:caption: Examples
118117

119-
120118
examples_apps/index
121119
examples_pipelines/index
122120

123121

124-
125122
Components Library
126123
---------------------
127124
.. _Components:

docs/source/schedulers/ray.rst

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
Ray
22
=================
33

4-
.. automodule:: torchx.schedulers.ray_scheduler
4+
.. fbcode::
5+
:exclude:
56

6-
.. currentmodule:: torchx.schedulers.ray_scheduler
7+
.. automodule:: torchx.schedulers.ray_scheduler
78

8-
.. autoclass:: RayScheduler
9-
:members:
10-
:show-inheritance:
9+
.. currentmodule:: torchx.schedulers.ray_scheduler
1110

12-
.. autofunction:: create_scheduler
13-
.. autofunction:: has_ray
14-
.. autofunction:: serialize
11+
.. autoclass:: RayScheduler
12+
:members:
13+
:show-inheritance:
1514

16-
.. autoclass:: RayJob
17-
:members:
15+
.. autofunction:: create_scheduler
16+
.. autofunction:: has_ray
17+
.. autofunction:: serialize
18+
19+
.. autoclass:: RayJob
20+
:members:

0 commit comments

Comments
 (0)