Skip to content

Commit 47543e3

Browse files
authored
Merge pull request #821 from rgaiacs/819-nox-script
Minor improvements to noxfile.py
2 parents 28b1d76 + 0577a3d commit 47543e3

File tree

7 files changed

+55
-52
lines changed

7 files changed

+55
-52
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
__pycache__
22
_build
3-
docs/_data/contributors/contributors-jupyterhub.txt
4-
docs/_data/outreachy/*.txt
3+
docs/_data/generated/*
54
.ipynb_checkpoints
65
.vscode
76
.nox

docs/_data/contributors/gen_contributors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
# Load data that we'll use for the table
1010
path_data = Path(__file__).parent
11+
path_output = path_data.parent / "generated"
1112
path_contributor_data = path_data / "contributors-jupyterhub.yaml"
13+
path_output_contributor_data = path_output / "contributors-jupyterhub.txt"
1214
contributors = safe_load(path_contributor_data.read_text())
1315
keyvals = pd.read_csv(path_data / "contributor_key.csv", index_col=0)
1416

@@ -109,4 +111,4 @@ def _short_contributor(contributor):
109111
snippet += ", ".join(map(_short_contributor, inactive_contributors))
110112

111113
# Write a snippet that we will include in our docs
112-
path_contributor_data.with_suffix(".txt").write_text(snippet + "\n")
114+
path_output_contributor_data.write_text(snippet + "\n")

docs/_data/generated/.gitkeep

Whitespace-only changes.

docs/_data/outreachy/outreachy_participants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
# Set filepath to participants data file
1010
data_path = Path(__file__).resolve().parent
11+
generated_output = data_path.parent / "generated"
1112
participants_data_file = data_path.joinpath("outreachy_participants.json")
1213
participants_schema_file = data_path.joinpath("outreachy_participants.schema.json")
13-
output_path = data_path.joinpath("outreachy_participants.txt")
14+
output_path = generated_output.joinpath("outreachy_participants.txt")
1415

1516
# Read in json defining Outreachy participants
1617
with open(participants_data_file) as f:

docs/contribute/documentation.md

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
# Writing documentation
22

3-
All of the team's repositories are documented using [the Sphinx documentation engine](https://sphinx-doc.org).
4-
This page contains resources to help you understand Sphinx and the configurations we commonly use in our repositories.
3+
All of the team's repositories are documented using the [Sphinx] documentation engine.
4+
This page contains resources to help you understand [Sphinx] and the configurations we commonly use in our repositories.
5+
6+
[Sphinx]: https://sphinx-doc.org
57

68
## MyST Markdown
79

8-
Many of our repositories use [MyST Markdown](https://myst-parser.readthedocs.io).
10+
Our repositories use [MyST Markdown](https://myst-parser.readthedocs.io).
911
This is enabled via the [`myst-parser` Sphinx extension](https://myst-parser.readthedocs.io).
1012

11-
## reStructuredText
12-
13-
The default markup language used by Sphinx is [reStructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/).
14-
It is a rich and extensible way to write content for our documentation.
15-
See [the Sphinx reStructuredText documentation](https://www.sphinx-doc.org/en/master/usage/restructuredtext/) for an in-depth guide of how to use it.
16-
1713
## Build documentation locally
1814

1915
There are a few ways to build the documentation in our repositories.
@@ -22,41 +18,35 @@ Here are a few common ways to do so, from most- to least-automated.
2218

2319
### Building with `nox`
2420

25-
We often use [the `nox` command line tool](https://nox.thea.codes/en/stable/) to build documentation locally.
21+
We use [the `nox` command line tool](https://nox.thea.codes/en/stable/) to automate the build documentation locally.
2622
`nox` is a tool for quickly running commands in an isolated build environment.
2723
It is similar to `Make`, but with a Python configuration and with local build environments that are isolated to each job that you run.
2824

2925
`nox` is configured with [a file called `noxfile.py`](https://nox.thea.codes/en/stable/config.html).
3026

31-
**To install `nox`**, run this command:
27+
**To install `nox`**, follow the [steps in Nox's documentation](https://nox.thea.codes/en/stable/tutorial.html#installation).
28+
29+
**To see a list of available commands**, run
3230

3331
```bash
34-
pip install nox
32+
nox -l
3533
```
3634

37-
**To see a list of available commands**, run this command:
35+
**To install the requirements for documentation, build them locally, and have a live preview**, run
3836

3937
```bash
40-
nox -l
38+
nox -s docs -- live
4139
```
4240

43-
For example, we often name our documentation command `docs`.
44-
**To install the requirements for documentation and build them locally**, run:
41+
``````{note}
42+
If you don't want the live preview, run
4543
46-
```
44+
```bash
4745
nox -s docs
4846
```
4947
5048
This will place the built HTML files in `docs/_build/html` for you to inspect as you wish.
51-
52-
We often add an extra parameter to instead run a live server via [the `sphinx-autobuild` extension](https://github.com/executablebooks/sphinx-autobuild).
53-
**To build docs with a live serve that auto-reloads as you change things**, run this command:
54-
55-
```
56-
nox -s docs -- live
57-
```
58-
59-
Note that this will **only work for repositories that have a `noxfile.py` added**.
49+
``````
6050

6151
(docs:build-make)=
6252
### Building with `Makefile`s
@@ -66,18 +56,17 @@ Many of our repositories also have a `Makefile` that runs commands in your curre
6656
To do so, follow these steps:
6757

6858
1. Install the requirements for the documentation. This is often in a `docs/requirements.txt` file.
69-
Assuming a file in this location, run this command:
59+
Assuming a file in this location, run
7060

7161
```bash
7262
pip install -r docs/requirements.txt
7363
```
7464
2. Look for a `Makefile` in the `docs` repository.
75-
This is auto-generated by Sphinx to help you build the documentation.
76-
To build the `html` for our documentation, run this command:
65+
This is auto-generated by [Sphinx] to help you build the documentation.
66+
To build the `html` for our documentation, run
7767

7868
```bash
79-
cd docs
80-
make html
69+
make -C docs html
8170
```
8271

8372
It will put the built documentation in `_build/html` (depending on our configuration this may change a bit).

docs/team/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Here is the current JupyterHub team (listed alphabetically, with affiliation, an
1010
**Min Ragan-Kelley** acts as the team lead for the JupyterHub organization.
1111

1212
```{eval-rst}
13-
.. include:: ../_data/contributors/contributors-jupyterhub.txt
13+
.. include:: ../_data/generated/contributors-jupyterhub.txt
1414
```
1515

1616
(emoji-keys)=
@@ -33,5 +33,5 @@ internships with us. This includes the interns themselves who worked with us to
3333
improve JupyterHub, and the community members that donated their time and skills
3434
as mentors, coordinators and volunteers.
3535

36-
```{include} ../_data/outreachy/outreachy_participants.txt
36+
```{include} ../_data/generated/outreachy_participants.txt
3737
```

noxfile.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
"""A nox configuration file so that we can build the documentation easily with nox.
2-
- see the README.md for information about nox.
3-
- ref: https://nox.thea.codes/en/stable/
4-
"""
1+
import os.path
2+
53
import nox
64

75
nox.options.reuse_existing_virtualenvs = True
86

9-
build_command = ["-b", "dirhtml", "docs", "docs/_build/html"]
107

11-
@nox.session()
8+
@nox.session(default=False)
129
def docs(session):
13-
session.install("-r", "docs/requirements.txt")
10+
"""
11+
Build the documentation and, optionally with '-- live', run a web server.
12+
"""
13+
docs_dir = "docs"
14+
source_dir = os.path.join(docs_dir, "") # where conf.py is located
15+
data_dir = os.path.join(source_dir, "_data")
16+
output_dir = os.path.join(docs_dir, "_build")
17+
18+
session.install("-r", os.path.join(docs_dir, "requirements.txt"))
19+
20+
doc_build_default_args = ["-b", "dirhtml", source_dir, output_dir]
21+
1422
if "live" in session.posargs:
15-
# Add relative paths to this if we ever need to ignore them
16-
AUTOBUILD_IGNORE = [
17-
"docs/_data",
18-
"docs/_build",
19-
]
23+
# For live preview, sphinx-autobuild is used.
24+
# To avoid sphinx-autobuild be missing,
25+
# sphinx-autobuild is installed explicitly.
26+
session.install("sphinx-autobuild")
2027
cmd = ["sphinx-autobuild"]
21-
for folder in AUTOBUILD_IGNORE:
28+
29+
# Add relative paths to this if we ever need to ignore them
30+
autobuild_ignore = [output_dir, os.path.join(data_dir, "generated")]
31+
32+
for folder in autobuild_ignore:
2233
cmd.extend(["--ignore", f"*/{folder}/*"])
23-
cmd.extend(build_command)
34+
35+
cmd.extend(doc_build_default_args)
2436
session.run(*cmd)
2537
else:
26-
session.run("sphinx-build", *build_command)
38+
session.run("sphinx-build", *doc_build_default_args)

0 commit comments

Comments
 (0)