Skip to content

Commit ddea452

Browse files
yuxqiuKD-7
andauthored
Add doc examples (#59)
* fix: hide stdout output * docs: document how we gen gallery in `conf.py` * fix: fix random shuffle in rose plotter * docs: update rose plotter doc * refactor: make line plotter more robust * feat: add more examples * fix: let linguist work correctly * chore: add a contributing guide * chore: add pull request template * test: add a test for line plotter * build: add a `noplot` target to makefile * docs: add visualisations design considerations * fix: fix a typo * docs: replace note with warning * docs: update `show` doc * docs: remove the warning from word plotter example * ci: specify the backend for matplotlib in case that the test fails in Windows * ci: reformat the workflows files * chore: try bumping word plotter support again * docs: adjust the warnings * fix: resolve some issues * docs: fix typos * docs: add docs for no-plot build * docs: update bubble plotter doc --------- Co-authored-by: KD-7 <[email protected]>
1 parent ebfe38a commit ddea452

30 files changed

+459
-72
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
truelearn/tests/baseline_files/* linguist-vendored

.github/CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Welcome! We’re happy to have you here. Thank you in advance for your contribution to TrueLearn.
2+
Please see: [Contributing Guide](https://truelearn.readthedocs.io/en/latest/dev/index.html) for more information!

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--
2+
Thanks for contributing a pull request to TrueLearn!
3+
4+
Please ensure you have taken a look at the contribution guidelines:
5+
https://truelearn.readthedocs.io/en/latest/dev/index.html
6+
-->
7+
8+
### Reference Issues/PRs
9+
10+
<!--
11+
Example: Fixes #1234. See also #3456.
12+
13+
Please use keywords (e.g., Fixes) to create link to the issues or pull requests
14+
you resolved, so that they will automatically be closed when your pull request
15+
is merged. See https://github.com/blog/1506-closing-issues-via-pull-requests
16+
-->
17+
18+
19+
### What are the changes/fixes in this PR?
20+
21+
<!--
22+
Here is an example of what you can write in this section:
23+
24+
1. What did you do?
25+
2. Why? Explain the motivation.
26+
3. The design choices you make and the reasons behind them
27+
4. [Optional] Any new benchmarks and tests added that are worth mentioning?
28+
-->

.github/workflows/black.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ on:
33
pull_request:
44
# filter on files that should trigger this workflow
55
paths:
6-
- 'pyproject.toml'
7-
- '**.py'
8-
- '.github/workflows/black.yml'
6+
- "pyproject.toml"
7+
- "**.py"
8+
- ".github/workflows/black.yml"
99
workflow_dispatch:
1010
workflow_call:
1111

.github/workflows/coverage.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ on:
55
- main
66
# filter on files that should trigger this workflow
77
paths:
8-
- 'pyproject.toml'
9-
- '**.py'
10-
- '.github/workflows/coverage.yml'
8+
- "pyproject.toml"
9+
- "**.py"
10+
- ".github/workflows/coverage.yml"
1111
pull_request:
1212
# filter on files that should trigger this workflow
1313
paths:
14-
- 'pyproject.toml'
15-
- '**.py'
16-
- '.github/workflows/coverage.yml'
14+
- "pyproject.toml"
15+
- "**.py"
16+
- ".github/workflows/coverage.yml"
1717
workflow_dispatch:
1818

1919
# Only cancel concurrent runs of the same workflow

.github/workflows/python_publish.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ on:
99

1010
workflow_dispatch:
1111
inputs:
12-
pypi_release_type:
13-
description: 'Release to TestPyPI or PyPI (testpypi or pypi)'
14-
required: true
15-
default: 'testpypi'
16-
12+
pypi_release_type:
13+
description: "Release to TestPyPI or PyPI (testpypi or pypi)"
14+
required: true
15+
default: "testpypi"
1716

1817
permissions:
1918
contents: read
@@ -78,4 +77,3 @@ jobs:
7877
with:
7978
user: __token__
8079
password: ${{ secrets.PYPI_API_TOKEN }}
81-

.github/workflows/static_analysis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ on:
55
- main
66
# filter on files that should trigger this workflow
77
paths:
8-
- 'pyproject.toml'
9-
- '**.py'
10-
- '.github/workflows/static_analysis.yml'
8+
- "pyproject.toml"
9+
- "**.py"
10+
- ".github/workflows/static_analysis.yml"
1111
pull_request:
1212
# filter on files that should trigger this workflow
1313
paths:
14-
- 'pyproject.toml'
15-
- '**.py'
16-
- '.github/workflows/static_analysis.yml'
14+
- "pyproject.toml"
15+
- "**.py"
16+
- ".github/workflows/static_analysis.yml"
1717
workflow_dispatch:
1818
workflow_call:
1919

.github/workflows/unit_tests.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,27 @@ on:
55
- main
66
# filter on files that should trigger this workflow
77
paths:
8-
- 'pyproject.toml'
9-
- '**.py'
10-
- '.github/workflows/unit_tests.yml'
8+
- "pyproject.toml"
9+
- "**.py"
10+
- ".github/workflows/unit_tests.yml"
1111
pull_request:
1212
# filter on files that should trigger this workflow
1313
paths:
14-
- 'pyproject.toml'
15-
- '**.py'
16-
- '.github/workflows/unit_tests.yml'
14+
- "pyproject.toml"
15+
- "**.py"
16+
- ".github/workflows/unit_tests.yml"
1717
workflow_dispatch:
1818
workflow_call:
1919
inputs:
2020
environment:
2121
required: true
22-
default: 'testing'
22+
default: "testing"
2323
type: string
24-
description: 'Environment to run tests in (testing)'
24+
description: "Environment to run tests in (testing)"
2525
secrets:
2626
WIKIFIER_API_KEY:
2727
required: true
28-
description: 'Wikifier API Key'
29-
28+
description: "Wikifier API Key"
3029

3130
# Only cancel concurrent runs of the same workflow
3231
concurrency:
@@ -44,6 +43,9 @@ jobs:
4443

4544
env:
4645
WIKIFIER_API_KEY: ${{ secrets.WIKIFIER_API_KEY }}
46+
# necessary for matplotlib to work properly in Windows
47+
# it fails occasionally if we don't set this
48+
MPLBACKEND: "Agg"
4749
steps:
4850
- name: Checkout Repo
4951
uses: actions/checkout@v3

docs/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ BUILDDIR = _build
1212
help:
1313
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1414

15+
# Generate doc without running the examples
16+
# Can speed up doc build time when you don't need the examples
17+
html-noplot:
18+
$(SPHINXBUILD) -D plot_gallery=0 -b html $(ALLSPHINXOPTS) $(SOURCEDIR) $(BUILDDIR)/html
19+
@echo
20+
@echo "No-plot build finished. The HTML pages are in $(BUILDDIR)/html."
21+
1522
.PHONY: help Makefile
1623

1724
# Catch-all target: route all unknown targets to Sphinx using the new

docs/conf.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
88

99
import inspect
10+
import warnings
1011
import os
1112
import shutil
1213
import sys
@@ -46,6 +47,16 @@
4647
"sphinx.ext.intersphinx",
4748
"sphinx.ext.doctest",
4849
"sphinx_copybutton",
50+
# for some mysterious reason, if we put sphinx_gallery
51+
# below autosummary (which means if it is loaded after autosummary),
52+
# trueskill in truelearn.learning will not be properly
53+
# imported (``dir(trueskill)`` does not include trueskill
54+
# methods and classes and ``trueskill.__all__`` is an empty list)
55+
#
56+
# Note: An alternative solution is to add a higher priority of
57+
# ``generate_gallery_rst`` method in ``sphinx_gallery.gen_gallery``
58+
# which controls the gallery generation. It is registered via
59+
# app.connect('builder-inited', generate_gallery_rst).
4960
"sphinx_gallery.gen_gallery",
5061
"sphinx.ext.autosummary",
5162
]
@@ -108,6 +119,7 @@ def find_source():
108119

109120
# -- Gallery configuration ---------------------------------------------------
110121
from plotly.io._sg_scraper import plotly_sg_scraper
122+
from sphinx_gallery.sorting import ExampleTitleSortKey
111123

112124
image_scrapers = (
113125
"matplotlib",
@@ -122,12 +134,27 @@ def find_source():
122134
"examples_dirs": "../examples", # path to your example scripts
123135
"gallery_dirs": "examples", # path to where to save gallery generated output,
124136
"download_all_examples": False, # disable download file buttons
137+
"within_subsection_order": ExampleTitleSortKey, # sort examples by title
125138
"remove_config_comments": True,
126139
"show_memory": False,
127140
"show_signature": False,
141+
"plot_gallery": "True",
128142
"image_scrapers": image_scrapers,
129143
}
130144

145+
# filter WordPlotter warnings because we already have
146+
# an admonition in the WordPlotter example
147+
warnings.filterwarnings(
148+
"ignore",
149+
category=FutureWarning,
150+
message=(
151+
"WordPlotter may be removed in a future release "
152+
"because wordcloud library does not have "
153+
r"cross-platform support for Python 3.11\+, "
154+
r"and it is not actively maintained\."
155+
),
156+
)
157+
131158
# -- Options for napoleon extension ------------------------------------------
132159
# https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
133160
napoleon_include_special_with_doc = False

0 commit comments

Comments
 (0)