Skip to content
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

allows grading locally without providing checksum #9

Merged
merged 2 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions ldsagrader/ldsagrader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import io
import os
import sys
from typing import Dict

import click
import nbformat
Expand Down Expand Up @@ -106,29 +107,31 @@ def notebook_validate(notebook, checksum, timeout):
# noinspection PyShadowingNames
@notebook.command("grade")
@click.argument("notebook", type=click.Path(exists=True))
@click.option("--checksum", required=True, type=click.Path(exists=True))
@click.option("--checksum", type=click.Path(exists=True))
@click.option("--timeout", type=int, default=None)
def notebook_grade(notebook, checksum, timeout):
def notebook_grade(notebook, checksum, timeout) -> Dict[str, float]:
"""
Grade notebook running validations
"""
notebook = nbformat.read(notebook, as_version=nbformat.NO_CONVERT)

if not utils.is_valid(notebook, checksum):
if checksum and not utils.is_valid(notebook, checksum):
print("Checksum mismatch! (a)")
sys.exit(1)

print("Executing notebook...")
notebook = utils.execute(notebook, timeout)

print("Grading notebook...")
if not utils.is_valid(notebook, checksum):
if checksum and not utils.is_valid(notebook, checksum):
print("Checksum mismatch! (b)")
sys.exit(1)

total_score, max_score = utils.grade(notebook)
print(f"Score: {total_score}/{max_score}")

return {'total_score': total_score, 'max_score': max_score}


# noinspection PyShadowingNames
@notebook.command("execute")
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"Click",
"nbgrader",
"requests",
"jupyter_client==6.1.12"
]

setup_requirements = [
Expand Down