Skip to content

Commit

Permalink
Merge pull request #762 from ucbds-infra/temp
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispyles authored Jan 17, 2024
2 parents f5c31b4 + d6788aa commit 298632e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- master
- beta
- release
- temp
workflow_dispatch:

jobs:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* Updated Otter Assign to throw a `ValueError` when invalid Python code is encountered in test cells per [#756](https://github.com/ucbds-infra/otter-grader/issues/756)
* Fixed an error causing intercell seeding code to be added to cells using cell magic commands which caused syntax errors per [#754](https://github.com/ucbds-infra/otter-grader/issues/754)

**v5.2.3:**

* Fixed the no PDF acknowledgement feature to handle when PDF exports throw an error instead of failing silently

**v5.2.2:**

* Fixed an `AttributeError` when using `Notebook.check_all` per [#746](https://github.com/ucbds-infra/otter-grader/issues/746)
Expand Down
11 changes: 7 additions & 4 deletions otter/check/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,11 @@ def export(
zf = zipfile.ZipFile(zip_path, mode="w")
zf.write(nb_path)

pdf_created = True
pdf_path, pdf_created, pdf_error = None, True, None
if pdf:
pdf_path = export_notebook(nb_path, filtering=filtering, pagebreaks=pagebreaks)
if os.path.isfile(pdf_path):
try: pdf_path = export_notebook(nb_path, filtering=filtering, pagebreaks=pagebreaks)
except Exception as e: pdf_error = e
if pdf_path and os.path.isfile(pdf_path):
pdf_created = True
zf.write(pdf_path)
self._logger.debug(f"Wrote PDF to zip file: {pdf_path}")
Expand Down Expand Up @@ -520,10 +521,12 @@ def continue_export():
display(HTML(out_html))

if pdf_created or not self._nbmeta_config.require_no_pdf_confirmation:
if pdf_error is not None:
raise pdf_error
continue_export()
else:
display_pdf_confirmation_widget(
self._nbmeta_config.export_pdf_failure_message, continue_export)
self._nbmeta_config.export_pdf_failure_message, pdf_error, continue_export)

@grading_mode_disabled
@logs_event(EventType.END_CHECK_ALL)
Expand Down
10 changes: 7 additions & 3 deletions otter/check/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from ..nbmeta_config import NBMetadataConfig
from ..test_files import GradingResults
from ..utils import import_or_raise
from ..utils import format_exception, import_or_raise


T = TypeVar("T")
Expand Down Expand Up @@ -332,7 +332,7 @@ def resolve_test_info(
return test_path, test_name


def display_pdf_confirmation_widget(message: Optional[str], callback: Callable) -> None:
def display_pdf_confirmation_widget(message: Optional[str], pdf_error: Optional[Exception], callback: Callable) -> None:
"""
Display a widget to the user to acknowledge that a PDF will not be included in their submission
zip.
Expand All @@ -349,7 +349,11 @@ def wrapped_callback(*args):
message = "Your notebook could not be exported as a PDF. To continue exporting your " \
"submission, please click the button below."

t = HTML(f"""<p style="margin: 0">{message}</p>""")
message_html = f"""<p style="margin: 0">{message}</p>"""
if pdf_error is not None:
message_html += f"""<pre>{format_exception(pdf_error)}</pre>"""

t = HTML(message_html)
b = Button(description="Continue export", button_style="warning")
b.on_click(wrapped_callback)
m = HTML("""<div style="height: 10px; width: 100%"></div>""")
Expand Down
9 changes: 2 additions & 7 deletions otter/test_files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import nbformat as nbf
import os
import pickle
import traceback

from typing import Any, Dict, List, Optional

Expand All @@ -16,7 +15,7 @@
from .ottr_test import OttrTestFile

from ..nbmeta_config import NBMetadataConfig, OK_FORMAT_VARNAME
from ..utils import QuestionNotInLogException
from ..utils import format_exception, QuestionNotInLogException


__all__ = [
Expand Down Expand Up @@ -414,11 +413,7 @@ def to_gradescope_dict(self, ag_config):
"output": "The autograder failed to produce any results. Please alert your instructor to this failure for assistance in debugging it.",
"status": "failed",
})
tb = "".join(traceback.format_exception(
type(self._catastrophic_error),
self._catastrophic_error,
self._catastrophic_error.__traceback__,
))
tb = format_exception(self._catastrophic_error)
output["tests"].append({
"name": "Autograder Exception",
"visibility": "hidden",
Expand Down
14 changes: 14 additions & 0 deletions otter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import string
import shutil
import tempfile
import traceback
import yaml

from contextlib import contextmanager
Expand Down Expand Up @@ -398,3 +399,16 @@ class QuestionNotInLogException(Exception):
"""
Exception that indicates that a specific question was not found in any entry in the log
"""


def format_exception(e: Exception) -> str:
"""
Formats an exception for display with its traceback using the ``traceback`` module.
Args:
e (``Exception``): the exception to format
Returns:
``str``: the formatted exception
"""
return "".join(traceback.format_exception(type(e), e, e.__traceback__))

0 comments on commit 298632e

Please sign in to comment.