-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from materialsproject/fix-tests
Run Notebooks To Ensure The Work
- Loading branch information
Showing
20 changed files
with
1,977 additions
and
4,617 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ vim | |
graphviz | ||
mongodb | ||
gfortran | ||
zip | ||
zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ window.MathJax = { | |
ignoreHtmlClass: ".*|", | ||
processHtmlClass: "arithmatex" | ||
} | ||
}; | ||
}; |
Oops, something went wrong.