nbcollate

Latest PyPI Version Documentation Status Build Status Updates License

This package provides an API, and a command-line interface, to combine a set of Jupyter notebooks into a single notebook.

The provided functions combine a Jupyter notebook that contains a set of prompts, and copies of this notebook that answer the prompts, into a single notebook that lists all the answers after each prompt.

This is intended for use in a classroom setting, to collect assignment submissions into a notebook that can be quickly reviewed. The notebook can include student names, or it can be anonymous for use in classroom review. In the latter case, functionality exists to remove duplicate answers, and to sort answers by length.

Installation

pip install nbcollate

Command-Line Usage

nbcollate assignment.ipynb student-*.ipynb

Creates the file assignment-collated.ipynb from the student-* files in test/files.

nbcollate assignment.ipynb student-*.ipynb --label

Same as above, but labels each student with a name derived from the notebook file name.

nbcollate --help

Contributing

Set Up

Install pipenv <https://docs.pipenv.org/>. Then:

pipenv install
pipenv shell

Test

pytest

Release

tox
bumpversion release
flit publish
git push --tags

Acknowledgements

This package is inspired by original work paulruvolo/SoftDesSp16Prep by Paul Ruvolo at Olin College, extended at osteele/assignment-tools.

License

MIT

API

Collate Jupyter classroom assignment and submission notebooks

nbcollate.nbcollate(assignment_nb, answer_nbs, *, ids=None, labels=None, clear_outputs=False)[source]

Create a notebook based on assignment_nb, that incorporates answers from answer_nbs.

Parameters:
  • assignment_nb (Notebook) – A Jupyter notebook with the assignment.
  • answer_nbs (object) – A dict or iterable whose values are notebooks with answers. If this value is a dict, its keys are ids and its values are the corresponding notebooks.
  • labels ([str]) – If non-empty, this should have the same length as answer_nbs. A header is placed before each run of cells from a notebook in answer_nbs.
  • ids (bool) – If non-empty, this should have the same length as answer_nbs. Each cell from an answer notebook has metadata nbcollate_source set to the element from ids.
  • ids – If true, cell output is cleared.
Returns:

Notebook

Return type:

A Jupyter notebook

nbcollate.nb_clear_outputs(nb)[source]

Clear the output cells in a Jupyter notebook.

Parameters:nb (Notebook) – a Jupyter notebook
nbcollate.remove_duplicate_answers(nb)[source]

Modify a notebook to remove duplicate answers within each section.

Parameters:nb (Notebook) – A Jupyter notebook. This is modified in place.
nbcollate.sort_answers(nb)[source]

Sort the answers within each section by length, and then alphabetically.

Parameters:nb (Notebook) – A Jupyter notebook. This is modified in place.
nbcollate.get_answer_tuples(nb)[source]

Return a set of tuples (student_id, prompt_title) of answered prompts.

Parameters:nb (Notebook) – a Jupyter notebook
nbcollate.Notebook

A Jupyter notebook, represented as nbformat.NotebookNode from the nbformat package.