-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate_docs.sh
executable file
·70 lines (56 loc) · 2.26 KB
/
generate_docs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
PACKAGE_DIR="mdopt"
DOCS_DIR="docs"
SPHINX_SOURCE_DIR="docs/source"
SPHINX_BUILD_DIR="docs/build"
# Ensure the script is executed from the project root
if [ ! -d "$PACKAGE_DIR" ] || [ ! -d "$DOCS_DIR" ]; then
echo "Error: Script must be run from the root of the project."
exit 1
fi
# Convert README.md to README.rst
echo "Converting README.md to README.rst..."
pandoc "./README.md" -o "$SPHINX_SOURCE_DIR/README.rst"
# Delete existing Jupyter Notebooks in the Sphinx source directory
echo "Deleting existing Jupyter Notebooks in Sphinx source directory..."
find "$SPHINX_SOURCE_DIR" -name "*.ipynb" -exec rm {} +
# Copy Jupyter Notebooks to the Sphinx source directory
# Skip the notebooks whose names start with "tmp" or "plotting"
for notebook in examples/*/*.ipynb; do
notebook_name=$(basename "$notebook")
if [[ $notebook_name != tmp* && $notebook_name != plotting* ]]; then
cp "$notebook" "$SPHINX_SOURCE_DIR/"
fi
done
# Path to examples.rst
EXAMPLES_RST="$SPHINX_SOURCE_DIR/examples.rst"
# Check if examples.rst exists. If yes, delete it.
if [ -f "$EXAMPLES_RST" ]; then
echo "examples.rst already exists. Deleting and recreating..."
rm "$EXAMPLES_RST"
fi
# Proceed to create (or recreate) examples.rst and fill it
echo "Creating examples.rst..."
echo "Examples" > "$EXAMPLES_RST"
echo "========" >> "$EXAMPLES_RST"
echo "" >> "$EXAMPLES_RST"
echo ".. toctree::" >> "$EXAMPLES_RST"
echo " :maxdepth: 2" >> "$EXAMPLES_RST"
echo " :caption: Notebook Examples:" >> "$EXAMPLES_RST"
echo "" >> "$EXAMPLES_RST"
# Dynamically list notebooks in examples.rst
for notebook in "$SPHINX_SOURCE_DIR"/*.ipynb; do
notebook_name=$(basename "$notebook")
echo " $notebook_name" >> "$SPHINX_SOURCE_DIR/examples.rst"
done
# Generate .rst files with sphinx-apidoc
echo "Generating .rst files with sphinx-apidoc..."
sphinx-apidoc -o "$SPHINX_SOURCE_DIR" "$PACKAGE_DIR" --force
echo "Cleaning up previous builds..."
rm -rf "$SPHINX_BUILD_DIR"
# Build the Sphinx documentation
echo "Building Sphinx documentation..."
sphinx-build -b html "$SPHINX_SOURCE_DIR" "$SPHINX_BUILD_DIR"
# Alternatively, if you're using the Makefile generated by Sphinx:
# make -C "$DOCS_DIR" html
echo "Documentation generation complete. Check the $SPHINX_BUILD_DIR directory."