Skip to content

Commit

Permalink
Merge pull request #177 from edina/Yevgeny_updates_2
Browse files Browse the repository at this point in the history
Improve the information output, to match upstream nbgrader
  • Loading branch information
alasdair-macleod authored Oct 3, 2024
2 parents 6ba01a7 + 02e298e commit 6307867
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion nbexchange/plugin/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def do_collect(self):
f"No submissions of '{self.coursedir.assignment_id}' for course '{self.coursedir.course_id}' to collect"
)
else:
self.log.debug(
self.log.info(
f"Processing {len(submissions)} submissions of '{self.coursedir.assignment_id}' for course '{self.coursedir.course_id}'" # noqa: E501
)

Expand Down
3 changes: 2 additions & 1 deletion nbexchange/plugin/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def do_copy(self, src, dest):

def start(self):
self.log.debug(f"Called start on {self.__class__.__name__}")

self.set_timestamp()
self.log.info(f"timetamp: {self.timestamp}")
if self.coursedir and not self.coursedir.course_id:
self.coursedir.course_id = self.course_id

Expand Down
5 changes: 3 additions & 2 deletions nbexchange/plugin/fetch_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def do_copy(self, src, dest):

def copy_files(self):
self.log.debug(f"Source: {self.src_path}")
self.log.debug(f"Destination: {self.dest_path}")
self.log.info("Source: The exhange service")
self.log.info(f"Destination: {self.dest_path}")
self.do_copy(self.src_path, self.dest_path)
self.log.debug(f"Fetched as: {self.coursedir.course_id} {self.coursedir.assignment_id}")
self.log.info(f"Fetched as: {self.coursedir.course_id} {self.coursedir.assignment_id}")
8 changes: 3 additions & 5 deletions nbexchange/plugin/fetch_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def download(self):
# Feedback, here, is the time the feedback was generated, not the time of the submission
if "feedback" in content:
for f in content["feedback"]:
self.log.debug(f"##### fetch-feedback.download has {f['filename']}, {f['timestamp']}")
self.log.debug(f"fetch-feedback.download has {f['filename']}, {f['timestamp']}")
try:
# This matches nb_timestamp in list.parse_assignments, "status" == "submitted"
# The format should match the nbgrader default "%Y-%m-%d %H:%M:%S.%f %Z"
Expand All @@ -45,9 +45,7 @@ def download(self):
# )
timestamp = f["timestamp"]
os.makedirs(os.path.join(self.dest_path, timestamp), exist_ok=True)
self.log.debug(
f"##### fetch-feedback.download writing to {os.path.join(self.dest_path, timestamp)}"
)
self.log.info(f"Downloading feedback to {os.path.join(self.dest_path, timestamp)}")
with open(os.path.join(self.dest_path, timestamp, f["filename"]), "wb") as handle:
handle.write(base64.b64decode(f["content"]))
except Exception as e: # TODO: exception handling
Expand All @@ -56,6 +54,6 @@ def download(self):
self.fail(content.get("note", "could not get feedback"))

def copy_files(self):
self.log.debug(f"Destination: {self.dest_path}")
self.log.info(f"Destination: {self.dest_path}")
self.download()
self.log.debug(f"Fetched as: {self.coursedir.notebook_id}")
16 changes: 15 additions & 1 deletion nbexchange/plugin/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from urllib.parse import quote_plus

import nbgrader.exchange.abc as abc
from nbgrader.exchange.default.list import ExchangeList as DefaultExchangeList
from traitlets import Unicode

from .exchange import Exchange
Expand All @@ -13,6 +14,7 @@
# "inbound" is files submitted by students (on external service)
# "cached" is files submitted by students & collected by instructors (so on local disk)
class ExchangeList(abc.ExchangeList, Exchange):

def do_copy(self, src, dest):
pass

Expand Down Expand Up @@ -291,17 +293,29 @@ def list_files(self):
self.log.debug("ExchaneList.list_file starting")

assignments = self.parse_assignments()
if self.inbound or self.cached:
self.log.info("Submitted assignments:")
for assignment in assignments:
for info in assignment["submissions"]:
self.log.info(DefaultExchangeList.format_inbound_assignment(self, info))
else:
self.log.info("Released assignments:")
for info in assignments:
self.log.info(DefaultExchangeList.format_outbound_assignment(self, info))
return assignments

def remove_files(self):
if self.coursedir.course_id:
"""Delete assignment"""
self.log.info(
f"Unreleasing assignment_id {self.coursedir.assignment_id} on course code {self.coursedir.course_id}"
)

url = f"assignment?course_id={quote_plus(self.coursedir.course_id)}&assignment_id={quote_plus(self.coursedir.assignment_id)}" # noqa: E501

r = self.api_request(url, method="DELETE")

self.log.debug(f"Got back {r.status_code} after assignment unrelease")
self.log.info(f"Got back {r.status_code} after assignment unrelease")

def start(self):
#####
Expand Down
4 changes: 3 additions & 1 deletion nbexchange/plugin/release_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def get_notebooks(self):

def upload(self, file):
files = {"assignment": ("assignment.tar.gz", file)}
self.log.info(f"Source: {self.src_path}")
self.log.info("Destination: The exhange service")

url = f"assignment?course_id={quote_plus(self.coursedir.course_id)}&assignment_id={quote_plus(self.coursedir.assignment_id)}" # noqa: E501

Expand All @@ -84,7 +86,7 @@ def upload(self, file):
if not data["success"]:
self.fail(data["note"])

self.log.info("Successfully uploaded released assignment.")
self.log.info(f"Released as: {self.coursedir.course_id} {self.coursedir.assignment_id}")

def copy_files(self):
# Grab files from hard drive
Expand Down
12 changes: 8 additions & 4 deletions nbexchange/plugin/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import sys
from urllib.parse import quote_plus

import nbgrader.exchange.abc as abc
from nbgrader.exchange.abc import ExchangeSubmit as ABCExchangeSubmit
from nbgrader.utils import find_all_notebooks

from .exchange import Exchange
from .list import ExchangeList


class ExchangeSubmit(abc.ExchangeSubmit, Exchange):
class ExchangeSubmit(Exchange, ABCExchangeSubmit):
def do_copy(self, src, dest):
pass

Expand All @@ -34,9 +34,8 @@ def tar_source(self):
import tarfile
import time
from contextlib import closing
from datetime import datetime

timestamp = datetime.now().strftime(self.timestamp_format).strip()
timestamp = self.timestamp
tar_file = io.BytesIO()
with tarfile.open(fileobj=tar_file, mode="w:gz") as tar_handle:
tar_handle.add(self.src_path, arcname=".")
Expand All @@ -50,6 +49,9 @@ def tar_source(self):

def upload(self, file):
self.log.debug(f"ExchangeSubmit uploading to: {self.service_url()}")
self.log.info(f"Source: {self.src_path}")
self.log.info("Destination: The exhange service")

files = {"assignment": ("assignment.tar.gz", file)}
r = self.api_request(
f"submission?course_id={quote_plus(self.coursedir.course_id)}&assignment_id={quote_plus(self.coursedir.assignment_id)}", # noqa: E501
Expand All @@ -61,6 +63,8 @@ def upload(self, file):
if not data["success"]:
self.fail(data["note"])

self.log.info(f"Submitted as: {self.coursedir.course_id} {self.coursedir.assignment_id} {self.timestamp}")

# Like the default Submit, we log differences, and do not rener then in the display
# (not sure that's any ues to anyone - but that's what the original does)
def check_filename_diff(self):
Expand Down
1 change: 1 addition & 0 deletions nbexchange/tests/test_plugin_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_submit_methods(plugin_config, tmpdir, caplog):
)

plugin = ExchangeSubmit(coursedir=CourseDirectory(config=plugin_config), config=plugin_config)
plugin.set_timestamp()
plugin.init_src()
assert re.search(r"nbexchange/assign_1_1$", plugin.src_path)
plugin.init_dest()
Expand Down

0 comments on commit 6307867

Please sign in to comment.