Skip to content

Commit dcfee7b

Browse files
authored
Merge pull request #381 from oliver-sanders/autobuild
make: Add sphinx-autobuild support
2 parents a03de67 + 368b3a4 commit dcfee7b

File tree

4 files changed

+112
-2
lines changed

4 files changed

+112
-2
lines changed

Makefile

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,33 @@ clean:
2222
rm -rf src/plugins/install/built-in
2323
rm -rf src/user-guide/task-implementation/job-runner-handlers
2424

25+
watch: clean
26+
# rebuild incrementally whenever documentation files are changed
27+
sphinx-autobuild "$(SOURCEDIR)" "$(BUILDDIR)" \
28+
--ignore='**plugins/main-loop/built-in/*.rst' \
29+
--ignore='**plugins/install/built-in/*.rst' \
30+
--ignore='**/job-runner-handlers/*.rst' \
31+
--open-browser
32+
33+
watch-cylc:
34+
# rebuild non-incrementally (SLOW) whenever docs files OR Cylc source
35+
# code files are changed
36+
sphinx-autobuild "$(SOURCEDIR)" "$(BUILDDIR)" \
37+
-a \
38+
--pre-build='make clean' \
39+
--ignore='**plugins/main-loop/built-in/*.rst' \
40+
--ignore='**plugins/install/built-in/*.rst' \
41+
--ignore='**/job-runner-handlers/*.rst' \
42+
--watch="$(shell bin/c-locate cylc.flow)" \
43+
--watch="$(shell bin/c-locate cylc.uiserver)" \
44+
--watch="$(shell bin/c-locate cylc.rose)" \
45+
--open-browser
46+
2547
cleanall:
2648
(cd doc; echo [0-9]*.*)
2749
rm -rI doc/[0-9]*.*
2850

29-
.PHONY: help clean Makefile .EXPORT_ALL_VARIABLES
51+
.PHONY: help clean watch Makefile .EXPORT_ALL_VARIABLES
3052

3153
# Catch-all target: route all unknown targets to Sphinx using the new
3254
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,56 @@ We use a few custom Sphinx extensions, for details see
8686
$ git clone [email protected]:cylc/cylc-doc.git cylc-doc
8787
$ cd cylc-doc
8888
$ pip install -e .
89+
```
90+
91+
### Simple Build
92+
93+
Build the docs using `make`:
94+
95+
```console
8996
$ make html
9097
```
9198

99+
The documentation builds incrementally, if you make changes to the Cylc source
100+
files run `make clean`:
101+
102+
```console
103+
$ make clean html
104+
```
105+
106+
### Automatic Build
107+
108+
You can also get Sphinx to rebuild automatically when documentation files are
109+
modified. Fist install the optional dependency `watch`:
110+
111+
```console
112+
$ pip install -e .[watch]
113+
114+
```
115+
116+
Then build the `watch` target:
117+
118+
```console
119+
$ make watch # you do not need to `make clean` with the `watch` target
120+
```
121+
122+
This will monitor for changes in the `cylc-doc` repository and rebuild the
123+
documentation incrementally.
124+
125+
To also monitor for changes in the `cylc-flow`, `cylc-uiserver` and `cylc-rose`
126+
repositories use the `watch-cylc` target:
127+
128+
```console
129+
$ make watch-cylc # you do not need to `make clean` with the `watch` target
130+
```
131+
132+
This forces a complete rebuild every time a file is changed which is slow, but
133+
allows it to pick up changes to autodocumented items in the source code.
134+
135+
> **Note:** Your Cylc repositories must be installed in editible mode
136+
> i.e. `pip install -e <repo>` for this to work.
137+
> **Note:** This might not work for all filesystems.
138+
92139
## Testing
93140

94141
```console

bin/c-locate

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
3+
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
"""Locate Python repository installations."""
19+
20+
from pathlib import Path
21+
import sys
22+
23+
24+
def main(arg):
25+
if arg == 'cylc.flow':
26+
import cylc.flow
27+
print(Path(cylc.flow.__file__).parent)
28+
elif arg == 'cylc.uiserver':
29+
import cylc.uiserver
30+
print(Path(cylc.uiserver.__file__).parent)
31+
elif arg == 'cylc.rose':
32+
import cylc.rose
33+
print(Path(cylc.rose.__file__).parent)
34+
else:
35+
raise ValueError(f'Unsupported arg: {arg}')
36+
37+
38+
if __name__ == '__main__':
39+
main(sys.argv[1])

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def get_version(module, path):
5959
'flake8-mutable>=1.2.0',
6060
'flake8-simplify>=0.14.0',
6161
],
62-
62+
'watch': [
63+
'sphinx-autobuild',
64+
],
6365
}
6466
EXTRAS_REQUIRE['all'] = [y for x in EXTRAS_REQUIRE.values() for y in x]
6567

0 commit comments

Comments
 (0)