Skip to content

Commit

Permalink
Unsure
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:ucfai/bot
  • Loading branch information
John M committed Dec 16, 2019
2 parents 718fb5a + 2235de7 commit 409902f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
1 change: 1 addition & 0 deletions autobot/lib/apis/kaggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

def push_kernel(meeting: Meeting):
# TODO: prevent Kaggle from pushing every notebook, every time
# TODO: absorb the output from shell and parse it, potentially handling
if "KAGGLE_CONFIG_DIR" not in os.environ:
os.environ["KAGGLE_CONFIG_DIR"] = str(
Path(__file__).parent.parent.parent.parent
Expand Down
55 changes: 34 additions & 21 deletions autobot/lib/utils/meetings.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,31 +181,44 @@ def update_or_create_notebook(meeting: Meeting, overwrite: bool = False):
# region Generate workbook by splitting solution manual
# this was determined by looking at the `nbgrader` source code in checks for
# thie `ClearSolutions` Preprocessor
nbgrader_cell_metadata = {"nbgrader": {"solution": True}}
sources = []
try:
nbgrader_cell_metadata = {"nbgrader": {"solution": True}}

for cell in nb["cells"]:
if cell["cell_type"] is not "code":
continue
workbook = copy.deepcopy(nb)
for cell in workbook["cells"]:
if str(cell["cell_type"]) != "code":
continue

source = "".join(cell["source"])
if Solution.BEGIN_FLAG in source and Solution.END_FLAG in source:
cell["metadata"].update(nbgrader_cell_metadata)
elif "nbgrader" in cell["metadata"]:
del cell["metadata"]["nbgrader"]
sources.append(cell)
source = "".join(cell["source"])
if Solution.BEGIN in source and Solution.END in source:
cell["metadata"].update(nbgrader_cell_metadata)
elif "nbgrader" in cell["metadata"]:
del cell["metadata"]["nbgrader"]

nbf.write(nb, open(path, "w"))
nbf.write(workbook, open(path, "w"))

workbook_exporter = nbc.NotebookExporter(
preprocessors=[ClearSolutions, ClearOutput]
)
workbook, _ = workbook_exporter.from_notebook_node(nb)

# this is a nightmare. we're going from `.solution.ipynb` to `.ipynb`, but
# have to remove the `.solution` suffix. which seems only doable by going
# down the entire tree of suffixes and removing them.
workbook_path = path.with_suffix("").with_suffix("").with_suffix(Suffixes.WORKBOOK)
with open(workbook_path, "w") as f_nb:
f_nb.write(workbook)
workbook_exporter = nbc.NotebookExporter(
preprocessors=[ClearSolutions, ClearOutput]
)
workbook_processed, _ = workbook_exporter.from_notebook_node(workbook)

# this is a nightmare. we're going from `.solution.ipynb` to `.ipynb`, but
# have to remove the `.solution` suffix. which seems only doable by going
# down the entire tree of suffixes and removing them.
workbook_path = path.with_suffix("").with_suffix("").with_suffix(Suffixes.WORKBOOK)
with open(workbook_path, "w") as f_nb:
f_nb.write(workbook_processed)

except RuntimeError:
nbf.write(nb, open(path, "w"))

from pprint import pprint
print(f"Something is wrong with the solution blocks of `{path}`...")
print("Dumping notebook JSON")
pprint(workbook["cells"])
pprint(sources)
# endregion


Expand Down
2 changes: 1 addition & 1 deletion envs/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ dependencies:
- imgkit==1.0.1
- kaggle
# you need to also run: `brew install wkhtmltopdf` for `imgkit` to work!
- git+https://github.com/ucfai/bot@master
# - git+https://github.com/ucfai/bot@master
2 changes: 1 addition & 1 deletion envs/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ dependencies:
- imgkit==1.0.1
- kaggle
# you need to also run: `brew install wkhtmltopdf` for `imgkit` to work!
- git+https://github.com/ucfai/bot@master
# - git+https://github.com/ucfai/bot@master

0 comments on commit 409902f

Please sign in to comment.