Skip to content

Commit 23cbd8a

Browse files
DOCS: Rework example documentation (#43)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent b155e6a commit 23cbd8a

File tree

16 files changed

+2265
-209
lines changed

16 files changed

+2265
-209
lines changed

.github/workflows/ci_cd.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ env:
1414
MEILISEARCH_API_KEY: ${{ secrets.MEILISEARCH_API_KEY }}
1515
MEILISEARCH_HOST_URL: ${{ vars.MEILISEARCH_HOST_URL }}
1616
MEILISEARCH_PUBLIC_API_KEY: ${{ secrets.MEILISEARCH_PUBLIC_API_KEY }}
17-
# LIBRARY_NAME: 'ansys-conceptev-core'
18-
# LIBRARY_NAMESPACE: 'ansys.conceptev.core'
1917

2018
concurrency:
2119
group: ${{ github.workflow }}-${{ github.ref }}
@@ -115,15 +113,15 @@ jobs:
115113
uses: actions/upload-artifact@v4
116114
if: env.MAIN_PYTHON_VERSION == matrix.python-version
117115
with:
118-
name: coverage-tests-{{ '${{ matrix.os }}' }}
116+
name: coverage-tests-${{ matrix.os }}
119117
path: .cov
120118
retention-days: 7
121119

122120
- name: Upload coverage results (as .coverage)
123121
uses: actions/upload-artifact@v4
124122
if: env.MAIN_PYTHON_VERSION == matrix.python-version
125123
with:
126-
name: coverage-file-tests-{{ '${{ matrix.os }}' }}
124+
name: coverage-file-tests-${{ matrix.os }}
127125
path: .coverage
128126
retention-days: 7
129127

@@ -132,7 +130,21 @@ jobs:
132130
runs-on: ubuntu-latest
133131
needs: [doc-style]
134132
steps:
135-
- uses: ansys/actions/doc-build@v6
133+
- name: Install dependencies
134+
run: |
135+
sudo apt-get update
136+
sudo apt-get install -y pandoc
137+
sudo apt-get install texlive-latex-extra texlive-xetex texlive-fonts-extra
138+
# sudo apt-get install libgl1-mesa-glx xvfb texlive-latex-extra latexmk graphviz texlive-xetex texlive-fonts-extra qpdf texlive-xetex xindy
139+
140+
- name: Verify Pandoc installation
141+
run: pandoc --version
142+
143+
- name: Build documentation
144+
env:
145+
CONCEPTEV_USERNAME: ${{ secrets.CONCEPTEV_USERNAME }}
146+
CONCEPTEV_PASSWORD: ${{ secrets.CONCEPTEV_PASSWORD }}
147+
uses: ansys/actions/doc-build@v6
136148
with:
137149
python-version: ${{ env.MAIN_PYTHON_VERSION }}
138150
check-links: false

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ repos:
2525
rev: v2.2.6
2626
hooks:
2727
- id: codespell
28-
args: ["--ignore-words", "doc/styles/config/vocabularies/ANSYS/accept.txt", "-w"]
28+
args: ["--ignore-words", "doc/styles/config/vocabularies/ANSYS/accept.txt", "-w", "--skip=poetry.lock"]
2929

3030
- repo: https://github.com/pycqa/pydocstyle
3131
rev: 6.3.0
3232
hooks:
3333
- id: pydocstyle
3434
additional_dependencies: [tomli]
35-
exclude: "tests/"
35+
exclude: "^(tests|examples)"
3636

3737
- repo: https://github.com/pre-commit/pre-commit-hooks
3838
rev: v4.4.0

doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ clean:
2828
# Customized pdf for svg format images
2929
pdf:
3030
@$(SPHINXBUILD) -M latex "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
31-
cd $(BUILDDIR)/latex && latexmk -r latexmkrc -pdf *.tex -interaction=nonstopmode || true
31+
cd $(BUILDDIR)/latex && latexmk -r latexmkrc -pdf -xelatex *.tex -interaction=nonstopmode || true
3232
(test -f $(BUILDDIR)/latex/*.pdf && echo pdf exists) || exit 1

doc/changelog.d/43.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DOCS: Rework example documentation

doc/make.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ goto end
4242
%SPHINXBUILD% -M latex %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
4343
cd "%BUILDDIR%\latex"
4444
for %%f in (*.tex) do (
45-
pdflatex "%%f" --interaction=nonstopmode)
45+
xelatex "%%f" --interaction=nonstopmode)
4646
if NOT EXIST ansys-conceptev-core.pdf (
4747
Echo "no pdf generated!"
4848
exit /b 1)

doc/source/_static/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

doc/source/_static/custom.css

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@import "../ansys-sphinx-theme.css";
2+
3+
/* Do not show number cells in notebooks */
4+
.nbinput .prompt,
5+
.nboutput .prompt {
6+
display: none !important;
7+
}
8+
9+
/* Ensure proper font size for notebook cells */
10+
.nboutput {
11+
font-size: 1.1em;
12+
}
13+
14+
.nbinput {
15+
font-size: 1em;
16+
}
17+
18+
/* Expand cell content output to the width of the notebook */
19+
div.nbinput.container div.input_area, div.nboutput.container div.output_area {
20+
display: block;
21+
}
22+
23+
/* Center images in notebook output cells */
24+
.nboutput img {
25+
display: block !important;
26+
margin: 0 auto !important;
27+
}
28+
29+
.sd-card .sd-card-img-top {
30+
height: 100px;
31+
width: 100px;
32+
margin-left: auto;
33+
margin-right: auto;
34+
}
35+
36+
.sd-card .sd-card-header {
37+
font-size: var(--pst-font-size-h5);
38+
font-weight: bold;
39+
padding: 1rem 0rem 1rem 0rem;
40+
}
41+
42+
.sd-card .sd-card-footer .sd-card-text {
43+
max-width: 220px;
44+
}
30.7 KB
Loading
36.3 KB
Loading

doc/source/conf.py

Lines changed: 116 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@
22

33
from datetime import datetime
44
import os
5+
import pathlib
6+
import shutil
57

68
from ansys_sphinx_theme import get_version_match
79
from ansys_sphinx_theme import pyansys_logo_black as logo
10+
import sphinx
11+
from sphinx.util import logging
812

913
from ansys.conceptev.core import __version__
1014

15+
logger = logging.getLogger(__name__)
16+
path = pathlib.Path(__file__).parent.parent.parent / "examples"
17+
EXAMPLES_DIRECTORY = path.resolve()
18+
1119
# Project information
1220
project = "ansys-conceptev-core"
1321
copyright = f"(c) 2023-{datetime.today().year} ANSYS, Inc. and/or its affiliates."
1422
author = "ANSYS, Inc."
1523
release = version = __version__
16-
cname = os.getenv("DOCUMENTATION_CNAME", "docs.pyansys.com")
24+
cname = os.getenv("DOCUMENTATION_CNAME", "conceptev.core.docs.pyansys.com")
1725
switcher_version = get_version_match(__version__)
1826

1927
# Select desired logo, theme, and declare the html title
@@ -29,7 +37,7 @@
2937

3038
# specify the location of your github repo
3139
html_theme_options = {
32-
"github_url": "https://github.com/pyconceptev-core",
40+
"github_url": "https://github.com/ansys/pyconceptev-core",
3341
"use_edit_page_button": True,
3442
"show_prev_next": False,
3543
"show_breadcrumbs": True,
@@ -45,7 +53,9 @@
4553

4654
# Sphinx extensions
4755
extensions = [
56+
"nbsphinx",
4857
"numpydoc",
58+
"recommonmark",
4959
"sphinx.ext.autodoc",
5060
"sphinx.ext.autosummary",
5161
"sphinx.ext.imgconverter",
@@ -81,23 +91,124 @@
8191
# type, unless multiple values are being returned"
8292
}
8393

84-
# static path
94+
# Static path
8595
html_static_path = ["_static"]
96+
html_css_files = [
97+
"custom.css",
98+
]
99+
100+
# List of patterns, relative to source directory, that match files and
101+
# directories to ignore when looking for source files.
102+
# This pattern also affects html_static_path and html_extra_path.
103+
exclude_patterns = [
104+
"_build",
105+
"*.txt",
106+
"conf.py",
107+
]
86108

87109
# Add any paths that contain templates here, relative to this directory.
88110
templates_path = ["_templates"]
89111

90112
# The suffix(es) of source filenames.
91-
source_suffix = ".rst"
113+
source_suffix = {
114+
".rst": "restructuredtext",
115+
".md": "markdown",
116+
}
92117

93118
# The master toctree document.
94119
master_doc = "index"
95120

96-
linkcheck_ignore = []
121+
# Examples gallery customization
122+
nbsphinx_execute = "always"
123+
nbsphinx_allow_errors = False
124+
nbsphinx_thumbnails = {
125+
"examples/simple_workflow": "_static/thumbnails/simple_workflow.png",
126+
}
127+
nbsphinx_custom_formats = {
128+
".py": ["jupytext.reads", {"fmt": ""}],
129+
}
130+
131+
# Activate fontawesome icons in LaTeX
132+
sd_fontawesome_latex = True
133+
134+
linkcheck_exclude_documents = ["index"]
135+
linkcheck_ignore = [
136+
r"https://download.ansys.com/",
137+
r".*/examples/.*.py",
138+
r"_static/assets/.*",
139+
]
140+
97141

98142
# If we are on a release, we have to ignore the "release" URLs, since it is not
99143
# available until the release is published.
100144
if switcher_version != "dev":
101145
linkcheck_ignore.append(
102146
f"https://github.com/ansys/pyconceptev-core/releases/tag/v{__version__}"
103147
)
148+
149+
# Sphinx event hooks
150+
151+
152+
def directory_size(directory_path):
153+
"""Compute the size (in mega bytes) of a directory."""
154+
res = 0
155+
for path, _, files in os.walk(directory_path):
156+
for f in files:
157+
fp = os.path.join(path, f)
158+
res += os.stat(fp).st_size
159+
# Convert in mega bytes
160+
res /= 1e6
161+
return res
162+
163+
164+
def check_pandoc_installed(app):
165+
"""Ensure that pandoc is installed."""
166+
import pypandoc
167+
168+
try:
169+
pandoc_path = pypandoc.get_pandoc_path()
170+
pandoc_dir = os.path.dirname(pandoc_path)
171+
if pandoc_dir not in os.environ["PATH"].split(os.pathsep):
172+
logger.info("Pandoc directory is not in $PATH.")
173+
os.environ["PATH"] += os.pathsep + pandoc_dir
174+
logger.info(f"Pandoc directory '{pandoc_dir}' has been added to $PATH")
175+
except OSError:
176+
logger.error("Pandoc was not found, please add it to your path or install pypandoc-binary")
177+
178+
179+
def copy_examples(app):
180+
"""Copy directory examples (root directory) files into the doc/source/examples directory."""
181+
destination_dir = pathlib.Path(app.srcdir, "examples").resolve()
182+
logger.info(f"Copying examples from {EXAMPLES_DIRECTORY} to {destination_dir}.")
183+
184+
if os.path.exists(destination_dir):
185+
size = directory_size(destination_dir)
186+
logger.info(f"Directory {destination_dir} ({size} MB) already exist, removing it.")
187+
shutil.rmtree(destination_dir)
188+
logger.info(f"Directory removed.")
189+
190+
shutil.copytree(EXAMPLES_DIRECTORY, destination_dir)
191+
logger.info(f"Copy performed")
192+
193+
194+
def remove_examples(app, exception):
195+
"""Remove the doc/source/examples directory created during the documentation build."""
196+
destination_dir = pathlib.Path(app.srcdir) / "examples"
197+
198+
size = directory_size(destination_dir)
199+
logger.info(f"Removing directory {destination_dir} ({size} MB).")
200+
shutil.rmtree(destination_dir, ignore_errors=True)
201+
logger.info(f"Directory removed.")
202+
203+
204+
def setup(app: sphinx.application.Sphinx):
205+
"""Run different hook functions during the documentation build.
206+
207+
Parameters
208+
----------
209+
app : sphinx.application.Sphinx
210+
Sphinx instance containing all the configuration for the documentation build.
211+
"""
212+
app.connect("builder-inited", copy_examples)
213+
app.connect("builder-inited", check_pandoc_installed)
214+
app.connect("build-finished", remove_examples)

0 commit comments

Comments
 (0)