Skip to content

Commit

Permalink
Merge pull request #153 from materialsproject/fix-tests
Browse files Browse the repository at this point in the history
Run Notebooks To Ensure The Work
  • Loading branch information
Shyam Dwaraknath authored Jul 28, 2021
2 parents d012e11 + c9eeadb commit 8fb187f
Show file tree
Hide file tree
Showing 20 changed files with 1,977 additions and 4,617 deletions.
52 changes: 52 additions & 0 deletions .github/run_notebooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
""" Python script to run notebooks in the directory they exist in """
import os

import nbformat
import yaml
from nbclient import NotebookClient
from nbclient.exceptions import CellExecutionError


def recursive_get(items):
if isinstance(items, dict):
for v in items.values():
yield from recursive_get(v)
elif isinstance(items, list):
for v in items:
yield from recursive_get(v)
else:
yield items


with open("mkdocs.yml") as f:
mkdocs_config = yaml.load(f)

notebooks = [
item
for item in recursive_get(mkdocs_config.get("nav", {}))
if item.endswith(".ipynb")
]

os.chdir("workshop")
for notebook in notebooks:
print(f"Loading {notebook}")
nb = nbformat.read(notebook, as_version=4)

for cell in nb.cells:
if cell.get("cell_type", "") == "code" and "no-execute" in cell.get(
"metadata", {}
).get("tags", []):
cell["cell_type"] = "markdown"

client = NotebookClient(
nb,
timeout=600,
resources={"metadata": {"path": os.path.dirname(notebook)}},
)
try:
client.execute()
nbformat.write(nb, notebook)
except CellExecutionError:
msg = 'Error executing the notebook "%s".\n\n' % notebook
print(msg)
raise
7 changes: 5 additions & 2 deletions .github/workflows/dependabot-merge.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: Merge me!

on:
check_suite:
workflow_run:
types:
- completed
workflows:
# List all required workflow names here.
- 'testing'

jobs:
merge-me:
Expand All @@ -13,4 +16,4 @@ jobs:
- name: Merge me!
uses: ridedott/merge-me-action@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 16 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ jobs:
- name: Install workshop package
run: pip install -e .

- name: Install workshop data
run: python ./binder/populate_nobel_database.py

- name: Run Notebooks
env:
PMG_MAPI_KEY: ${{ secrets.MAPI_KEY }}
run: python .github/run_notebooks.py

- name: Build
run: mkdocs build

Expand Down Expand Up @@ -105,6 +113,14 @@ jobs:
- name: Install workshop package
run: pip install -e .

- name: Install workshop data
run: python ./binder/populate_nobel_database.py

- name: Run Notebooks
env:
PMG_MAPI_KEY: ${{ secrets.MAPI_KEY }}
run: python .github/run_notebooks.py

- name: Build
run: mkdocs build

Expand Down
2 changes: 1 addition & 1 deletion binder/apt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ vim
graphviz
mongodb
gfortran
zip
zip
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ copyright: Built by The Materials Project
site_url: https://workshop.materialsproject.org
repo_url: https://github.com/materialsproject/workshop
docs_dir: workshop
extra_css:
extra_css:
- assets/workshop.css
extra_javascript:
- assets/config.js
Expand Down
5 changes: 4 additions & 1 deletion python_module/mp_workshop/fireworks_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@

dumpfn(fw_config, fw_config_dir / "FW_config.yaml")
dumpfn(
fworker, fw_config_dir / "my_fworker.yaml", indent=4, default_flow_style=False,
fworker,
fw_config_dir / "my_fworker.yaml",
indent=4,
default_flow_style=False,
)


Expand Down
2 changes: 1 addition & 1 deletion requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ mkdocs==1.2.1
mkdocs-material==7.1.8
mkdocs-material-extensions==1.0.1
mkdocs-minify-plugin==0.4.0
mknotebooks==0.6.2
mknotebooks==0.6.2
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ atomate==0.9.9
pymongo==3.12.0
robocrys==0.2.7
crystal-toolkit==2021.4.29
ipywidgets==7.5.1
mpcontribs-client==3.12.0
graphviz==0.17
mp-api==0.5.1
mp-api==0.5.1
2 changes: 1 addition & 1 deletion workshop/assets/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ window.MathJax = {
ignoreHtmlClass: ".*|",
processHtmlClass: "arithmatex"
}
};
};
Loading

0 comments on commit 8fb187f

Please sign in to comment.