Skip to content

Commit 89073a9

Browse files
Port examples to sphinx_gallery (#170)
--------- Co-authored-by: victorprincipe <[email protected]>
1 parent 93f1b03 commit 89073a9

36 files changed

+2081
-3442
lines changed

.github/workflows/docs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ jobs:
1919
- name: install dependencies
2020
run: |
2121
python -m pip install tox
22-
sudo apt install pandoc
2322
- name: build documentation
2423
run: tox -e docs

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ __pycache__
88
.tox/
99
build/
1010
dist/
11-
docs/src/read-only-examples
11+
docs/src/examples

.readthedocs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ python:
2424
- requirements: docs/requirements.txt
2525
- method: pip
2626
path: .
27+
extra_requirements:
28+
- examples

docs/requirements.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
ipykernel
2-
jinja2 < 3.1
31
matplotlib
4-
nbconvert
5-
nbsphinx==0.8.12
6-
numpy
72
pandas
8-
scikit-learn >=0.24.0
9-
sphinx >=3.3
3+
sphinx
104
sphinx_rtd_theme
5+
sphinx-gallery
116
tqdm
12-
traitlets>=5.0

docs/src/conf.py

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,13 @@
1515
from datetime import datetime
1616

1717
import sphinx_rtd_theme
18-
from nbconvert import NotebookExporter
19-
from traitlets.config import Config
2018

2119
import skmatter
2220

2321

2422
ROOT = os.path.abspath(os.path.join("..", ".."))
2523
sys.path.insert(0, ROOT)
2624

27-
# Copying and Compiling of Examples
28-
if not os.path.exists(os.path.join(ROOT, "docs/src/read-only-examples")):
29-
os.mkdir(os.path.join(ROOT, "docs/src/read-only-examples"))
30-
31-
# Set up nbconvert configuration to strip empty cells and tables of contents
32-
c = Config()
33-
c.NotebookExporter.preprocessors = [
34-
"nbconvert.preprocessors.RegexRemovePreprocessor",
35-
"nbconvert.preprocessors.ExecutePreprocessor",
36-
]
37-
38-
# Remove any cells containing lines with the phrase "Table of Contents" or
39-
# consist solely of whitespace
40-
c.RegexRemovePreprocessor.enabled = True
41-
c.RegexRemovePreprocessor.patterns = [".*Table of Contents.*", "\\s*\\Z"]
42-
43-
# Execute each notebook in a python3 kernel to make sure the content is there
44-
c.ExecutePreprocessor.enabled = True
45-
c.ExecutePreprocessor.kernel = "python3"
46-
47-
exporter = NotebookExporter(config=c)
48-
49-
for nb in os.listdir(os.path.join(ROOT, "examples")):
50-
# Skip any non-notebooks
51-
if nb.endswith("ipynb") and "no-doc" not in nb:
52-
nb_in = os.path.join(ROOT, "examples", nb)
53-
nb_out = os.path.join(ROOT, "docs/src/read-only-examples", nb)
54-
55-
# Skip any notebooks which already exist
56-
if not os.path.exists(nb_out):
57-
with open(nb_out, "w") as out_stream:
58-
converted = exporter.from_filename(nb_in)[0]
59-
out_stream.write(converted)
60-
6125
# -- Project information -----------------------------------------------------
6226

6327
# The master toctree document.
@@ -79,10 +43,31 @@
7943
extensions = [
8044
"sphinx.ext.autodoc",
8145
"sphinx.ext.napoleon",
82-
"nbsphinx",
46+
"sphinx_gallery.gen_gallery",
47+
"sphinx.ext.intersphinx",
8348
]
8449

85-
nbsphinx_execute = "never"
50+
example_subdirs = ["pcovr", "selection", "regression", "reconstruction"]
51+
sphinx_gallery_conf = {
52+
"filename_pattern": "/*",
53+
"examples_dirs": [f"../../examples/{p}" for p in example_subdirs],
54+
"gallery_dirs": [f"examples/{p}" for p in example_subdirs],
55+
"min_reported_time": 60,
56+
# Make the code snippet for own functions clickable
57+
"reference_url": {"skmatter": None},
58+
}
59+
60+
# Configuration for intersphinx: refer to the Python standard library
61+
# and other packages
62+
intersphinx_mapping = {
63+
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
64+
"matplotlib": ("https://matplotlib.org/stable/", None),
65+
"numpy": ("https://numpy.org/doc/stable/", None),
66+
"python": ("https://docs.python.org/3/", None),
67+
"sklearn": ("https://scikit-learn.org/stable", None),
68+
"pandas": ("https://pandas.pydata.org/docs/", None),
69+
}
70+
8671

8772
# If set to False return type and description are put into one paragraph
8873
napoleon_use_rtype = False

docs/src/tutorials.rst

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,8 @@
1-
Examples
2-
########
3-
4-
For a thorough tutorial of the methods introduced in `scikit-matter`, we suggest you
5-
check out the pedagogic notebooks in our companion project `kernel-tutorials
6-
<https://github.com/lab-cosmo/kernel-tutorials/>`_.
7-
8-
.. toctree::
9-
:glob:
10-
:Caption: PCovR and KernelPCovR
11-
12-
read-only-examples/PCovR*
13-
14-
.. toctree::
15-
:glob:
16-
:Caption: Feature and Sample Selection
17-
18-
read-only-examples/FeatureSelection*
19-
read-only-examples/Selectors-Pipelines*
20-
21-
22-
.. toctree::
23-
:glob:
24-
:Caption: Orthogonal Regression
25-
26-
read-only-examples/OrthogonalRegressionNonAnalytic.ipynb
1+
.. include:: ../../examples/README.rst
272

283
.. toctree::
29-
:glob:
30-
:Caption: Feature Reconstruction Measures
314

32-
read-only-examples/PlotGFRE
33-
read-only-examples/PlotPointwiseGFRE.ipynb
34-
read-only-examples/PlotLFRE
5+
examples/pcovr/index
6+
examples/selection/index
7+
examples/regression/index
8+
examples/reconstruction/index

0 commit comments

Comments
 (0)