Skip to content

Commit d836803

Browse files
committed
Port examples to sphinx_gallery
1 parent 997720f commit d836803

33 files changed

+2049
-3445
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ jobs:
2727
run: |
2828
# ignore formatting, it will be checked by black
2929
export FORMATTING_RULES="E101,E111,E114,E115,E116,E117,E12,E13,E2,E3,E401,E5,E70,W1,W2,W3,W5"
30-
flake8 --ignore=$FORMATTING_RULES .
30+
# D205 and D400 are incompatible with the requirements of sphinx-gallery
31+
export PER_FILE_IGNORES="examples/*:D205,D400"
32+
flake8 --ignore=$FORMATTING_RULES --per-file-ignores=$PER_FILE_IGNORES .
3133
- name: Lint with black
3234
run: |
3335
black --check .

.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/source/read-only-examples
11+
docs/source/examples

docs/requirements.txt

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

docs/source/conf.py

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,10 @@
1313
import os
1414
import sys
1515
import sphinx_rtd_theme
16-
from nbconvert import NotebookExporter
17-
from traitlets.config import Config
1816

1917
ROOT = os.path.abspath(os.path.join("..", ".."))
2018
sys.path.insert(0, ROOT)
2119

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

5822
# -- Project information -----------------------------------------------------
@@ -76,10 +40,33 @@
7640
extensions = [
7741
"sphinx.ext.autodoc",
7842
"sphinx.ext.napoleon",
79-
"nbsphinx",
43+
"sphinx_gallery.gen_gallery",
44+
"sphinx.ext.intersphinx",
8045
]
8146

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

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

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ decomposition, and selection of features and samples.
2626
intro
2727
installation
2828
reference
29-
tutorials
29+
examples/index
3030
contributing
3131
bibliography

docs/source/intro.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
What's in scikit-matter?
2-
=======================
2+
========================
33

44
``scikit-matter`` is a collection of `scikit-learn <https://scikit.org/>`_
55
compatible utilities that implement methods born out of the materials science

docs/source/tutorials.rst

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)