-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run notebooks on RTD with sphinx-gallery and add WorkGraph tutorials #474
base: main
Are you sure you want to change the base?
Changes from all commits
1298f45
cd0c49b
8631643
f25fe8e
7430793
4c204df
db2e36a
ddbc440
1ea66fe
4bdba12
2b2c43e
e52d86c
5b48209
8e67630
4db0691
1fa3aaf
798304e
c87d18f
adfd2c0
86731fd
102d5e8
42ff514
43f6116
12e2872
3a2c005
8049b8c
ef349ac
0a06c78
15fb57a
a4cac3a
f89a812
8eb5d0f
6118d30
e38a372
32bde7f
7620580
e531860
55210f2
61ce7e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
name: continuous-integration | ||
|
||
on: [push, pull_request] | ||
on: | ||
push: | ||
# only pushes to main trigger | ||
branches: [main] | ||
pull_request: | ||
# always triggered | ||
|
||
jobs: | ||
|
||
|
@@ -11,29 +16,8 @@ jobs: | |
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.12 | ||
- name: Set up Python 3.11 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To build aiida-core in CI, I needed to use Python 3.11. For pre-commit it is not needed but I think we should just stick with Python 3.11 if there are issues with Python 3.12. |
||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.12 | ||
python-version: 3.11 | ||
- uses: pre-commit/[email protected] | ||
|
||
build: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now run in the RTD, check out the |
||
|
||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.12 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.12 | ||
- name: Install python dependencies | ||
run: | | ||
pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: "Build HTML docs" | ||
run: | | ||
make -C docs html linkcheck | ||
env: | ||
SPHINXOPTS: -nW --keep-going |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
"sphinx_copybutton", | ||
"sphinx_panels", | ||
"sphinx_tabs.tabs", | ||
"sphinx_gallery.gen_gallery", | ||
] | ||
|
||
myst_enable_extensions = [ | ||
|
@@ -68,7 +69,7 @@ | |
ipython_mplbackend = "" | ||
|
||
copybutton_selector = "div:not(.no-copy)>div.highlight pre" | ||
copybutton_prompt_text = ">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: " | ||
copybutton_prompt_text = ">>> |... |$ |In [d*]: | {2,5}...: | {5,8}: " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The escapes raised some warnings |
||
copybutton_prompt_is_regexp = True | ||
|
||
todo_include_todos = True | ||
|
@@ -391,13 +392,12 @@ | |
suppress_warnings = ["misc.highlighting_failure"] | ||
|
||
# Links we ignore, because they do not work temporary and we cannot fix it | ||
linkcheck_ignore = ["https://www.big-map.eu/"] | ||
|
||
|
||
def setup(app): | ||
"""Setup function called by sphinx.""" | ||
app.add_css_file("css/custom.css") | ||
|
||
linkcheck_ignore = [ | ||
"https://www.big-map.eu/", | ||
r".*concept/index.html", | ||
r".*howto/index.html", | ||
"http://127.0.0.1:8000/workgraph", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we ignore workgraph related files |
||
] | ||
|
||
# We are not installing a full aiida environment | ||
nb_execution_mode = "off" | ||
|
@@ -408,6 +408,29 @@ def setup(app): | |
"plumpy": ("https://plumpy.readthedocs.io/en/latest/", None), | ||
} | ||
|
||
gallery_src_relative_dir = "gallery" # relative path of the gallery src wrt. sphinx src | ||
|
||
# we mimik the structure in the sphinx src directory in the gallery src directory | ||
sphinx_src_autogen_dirs = ["sections/writing_workflows_with_workgraph/autogen"] | ||
|
||
gallery_src_dirs = [ | ||
os.path.join(gallery_src_relative_dir, autogen_dir) | ||
for autogen_dir in sphinx_src_autogen_dirs | ||
] # path of the python scripts that should be executed | ||
sphinx_gallery_conf = { | ||
"filename_pattern": "/*", | ||
"examples_dirs": gallery_src_dirs, # in sphinx-gallery doc referred as gallery source | ||
"gallery_dirs": sphinx_src_autogen_dirs, # path to where to gallery puts generated files | ||
} | ||
|
||
# ignore in the autogenerated ipynb files to surpress warning | ||
exclude_patterns.extend( | ||
[ | ||
os.path.join(sphinx_src_autogen_dir, "*ipynb") | ||
for sphinx_src_autogen_dir in sphinx_src_autogen_dirs | ||
] | ||
) | ||
|
||
# Compile all things needed before building the docs | ||
# For instance, convert the notebook templates to actual tutorial and solution versions | ||
print( | ||
|
@@ -416,3 +439,57 @@ def setup(app): | |
universal_newlines=True, | ||
) | ||
) | ||
|
||
import shutil | ||
from pathlib import Path | ||
|
||
|
||
def copy_html_files(app, exception): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copy paste from aiida-workgraph to move html files from the sphinx gallery folder to the sphinx source, so we can display the widgets |
||
""" | ||
Copy all .html files from source to build directory, maintaining the directory structure. | ||
""" | ||
print("Copying HTML files to build directory") | ||
copy_print_info = "Copying HTML files to build directory" | ||
print() | ||
print(copy_print_info) | ||
print(len(copy_print_info) * "=") | ||
if exception is not None: # Only copy files if the build succeeded | ||
print( | ||
"Build failed, but we still try to copy the HTML files to the build directory" | ||
) | ||
try: | ||
src_path = Path(app.builder.srcdir) | ||
build_path = Path(app.builder.outdir) | ||
|
||
copy_print_info = f"Copying html files from sphinx src directory {src_path}" | ||
print() | ||
print(copy_print_info) | ||
print(len(copy_print_info) * "-") | ||
for html_file in src_path.rglob("*.html"): | ||
relative_path = html_file.relative_to(src_path) | ||
destination_file = build_path / relative_path | ||
destination_file.parent.mkdir(parents=True, exist_ok=True) | ||
shutil.copy(html_file, destination_file) | ||
print(f"Copy {html_file} to {destination_file}") | ||
|
||
gallery_src_path = Path(app.builder.srcdir / Path(gallery_src_relative_dir)) | ||
|
||
copy_print_info = ( | ||
f"Copying html files from gallery src directory {gallery_src_path} to build" | ||
) | ||
print() | ||
print(copy_print_info) | ||
print(len(copy_print_info) * "-") | ||
for html_file in gallery_src_path.rglob("*.html"): | ||
relative_path = html_file.relative_to(gallery_src_path) | ||
destination_file = build_path / relative_path | ||
destination_file.parent.mkdir(parents=True, exist_ok=True) | ||
shutil.copy(html_file, destination_file) | ||
print(f"Copy {html_file} to {destination_file}") | ||
except Exception as e: | ||
print(f"Failed to copy HTML files: {e}") | ||
|
||
|
||
def setup(app): | ||
app.add_css_file("css/custom.css") | ||
app.connect("build-finished", copy_html_files) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
:orphan: | ||
|
||
================================ | ||
Running workflows with WorkGraph | ||
================================ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sphinx-gallery requires a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unrelated to this PR. It stops that the CI is run two time for each PR. I will put this in a separate PR