### Initialize nbgrader Course Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/installation.rst Create a directory with example course files using the quickstart command. ```bash nbgrader quickstart course_id ``` -------------------------------- ### Get Help for nbgrader Quickstart Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/installation.rst View detailed usage information for the nbgrader quickstart command. ```bash nbgrader quickstart --help ``` -------------------------------- ### Install envkernel Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/advanced.rst Install the envkernel tool directly from the GitHub repository. ```bash pip install https://github.com/NordicHPC/envkernel/archive/master.zip ``` -------------------------------- ### Setup Instructor Account Source: https://github.com/jupyter/nbgrader/wiki/Multi-course-multi-grader-setup-using-nginx-and-Shibboleth Enable course list extensions for an instructor account. ```bash su - mech-tutor jupyter-server extension enable --user nbgrader.server_extensions.course_list jupyter-labextension enable --level=user nbgrader:course-list ``` -------------------------------- ### Install notebook package Source: https://github.com/jupyter/nbgrader/wiki/Multi-course-multi-grader-setup-using-nginx-and-Shibboleth Install the notebook package if not using nbgrader. ```bash docker-compose exec jhub pip install notebook ``` -------------------------------- ### Install Bootstrap with Bower Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/bootstrap/README.md Install Bootstrap using Bower, a package manager for the web. Ensure Bower is installed globally. ```bash bower install bootstrap ``` -------------------------------- ### Create and Setup Students Source: https://github.com/jupyter/nbgrader/wiki/Multi-course-multi-grader-setup-using-nginx-and-Shibboleth This script creates student accounts in JupyterHub and registers their IDs. It requires a `students.csv` file with at least an 'id' column. Student accounts are created with UID starting from 3000. ```bash docker-compose exec jhub bash tail -n +2 students.csv |cut -f1 -d, |tr -d '"' |tr [A-Z] [a-z] |while read id; adduser -q --gecos "" --firstuid 3000 --gid 3000 --disabled-password $id su - $id -c "chmod go-rwx ." echo -n "." done python3 api_request.py users add `tail -n +2 students.csv |cut -f1 -d, |tr -d '"'` ``` ```bash su - grader-COURSE_ID -c "nbgrader db student import students.csv" exit ``` -------------------------------- ### Verify and Install Grunt Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/jquery-color/README.md Commands to check the installed version of Grunt and install it globally if missing. ```shell grunt -version ``` ```shell npm install -g grunt ``` -------------------------------- ### Install nbgrader in Development Mode Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/contributor_guide/installation_developer.rst Install nbgrader with development, documentation, and testing dependencies using pip. ```bash pip install -e ".[dev,docs,tests]" ``` -------------------------------- ### Install via npm Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/datatables.net-bs/Readme.md Use npm to install the datatables.net-bs package. ```bash npm install datatables.net-bs ``` -------------------------------- ### Install via bower Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/datatables.net-bs/Readme.md Use bower to install and save the datatables.net-bs package. ```bash bower install --save datatables.net-bs ``` -------------------------------- ### Run nbgrader and jupyter notebook in the same directory Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/configuration/nbgrader_config.rst Commands to initialize a course and start the notebook server from the same location. ```bash nbgrader quickstart course101 cd ./course101 jupyter notebook ``` -------------------------------- ### Install nbgrader in editable mode Source: https://github.com/jupyter/nbgrader/wiki/Multi-course-multi-grader-setup-using-nginx-and-Shibboleth Commands to install nbgrader from source and enable necessary server and notebook extensions system-wide. ```bash docker-compose exec jhub bash apt install git cd /usr/local pip install -e git+https://github.com/jupyter/nbgrader#egg=nbgrader jupyter-nbextension install nbgrader --system --py --overwrite jupyter-nbextension enable nbgrader --system --py jupyter-serverextension enable nbgrader --system --py ``` -------------------------------- ### PyTorch Conv2d Layer Example Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/tests/preprocessors/files/warning-pattern.ipynb Demonstrates the basic usage of a PyTorch Conv2d layer for image convolution. Requires PyTorch installation. ```python import torch layer = torch.nn.Conv2d(1, 32, 3, stride=1, padding=1) x = torch.randn(1, 1, 28, 28) y = layer(x) 5 ``` -------------------------------- ### Clone and Install jQuery Color Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/jquery-color/README.md Commands to clone the repository and install necessary dependencies. ```shell git clone git://github.com/jquery/jquery-color.git ``` ```shell cd jquery-color && npm install ``` -------------------------------- ### Automate course setup with Makefile Source: https://github.com/jupyter/nbgrader/wiki/Multi-course-multi-grader-setup-using-nginx-and-Shibboleth Makefile targets to create user accounts, configure course directories, and enable extensions for specific courses. ```makefile grader-%: adduser -q --gecos "" --disabled-password $@ su - $@ -c "chmod go-rwx ." @c_id=`echo $* |tr [a-z] [A-Z]`; \ cdir="$$(grep $@ /etc/passwd |cut -f6 -d:)/OPTIONAL_PREFIX-$$c_id"; \ nbconf="c=get_config\(\)\|\ c.CourseDirectory.root = \'$$cdir\'\|\ c.CourseDirectory.course_id = \'$$c_id\'";\ su - $@ -c "if ! [ -e .jupyter ]; then mkdir .jupyter; fi; \ echo $$nbconf |tr '|' '\n' >.jupyter/nbgrader_config.py; \ nbgrader quickstart $$cdir && rm -rf $$cdir/source/ps1; \ sed -ri '/course_id/s/^/#/' $$cdir/nbgrader_config.py" su - $@ -c "jupyter-nbextension enable formgrader/main --user --section=tree" su - $@ -c "jupyter-serverextension enable nbgrader.server_extensions.formgrader --user" su - $@ -c "jupyter-nbextension enable create_assignment/main --user" su - $@ -c "jupyter-nbextension disable assignment_list/main --user --section=tree" su - $@ -c "jupyter-serverextension disable nbgrader.server_extensions.assignment_list --user" gr-%: grader-% @c_id=`echo $* |tr [a-z] [A-Z]`; \ echo -e "Add this snippet to the appropriate sections in jupyterhub_config.py (replace UNIQUE_PORT!):\\n\ --- 8< ---\\n\ #c.JupyterHub.service = [\\n\ { 'name': '$$c_id',\\n\ 'url': 'http://127.0.0.1:UNIQUE_PORT',\\n\ 'command': [\\n\ 'jupyterhub-singleuser',\\n\ '--group=formgrade-$$c_id',\\n\ '--debug'\\n\ ],\\n\ 'environment': { 'JHUB_API_TOKEN': jhub_api_token },\\n\ 'user': '$<',\\n\ 'cwd': '/home/$<',\\n\ #'api_token': '$$(openssl rand -hex 16)'\\n\ },\\n\ #]\\n\ #c.JupyterHub.load_groups = {\\n\ 'formgrade-$$c_id': [ '$<' ],\\n\ 'nbgrader-$$c_id': [],\\n\ #}\\n\ #c.JupyterHub.load_roles = [\\n\ { 'name': 'role-$*',\\n\ 'scopes': [ 'access:services!service=$$c_id' ],\\n\ 'groups': [ 'formgrade-$$c_id' ]\\n\ },\\n\ #]\\n\ --- >8 ---" ``` -------------------------------- ### Deploy nbgrader demo files Source: https://github.com/jupyter/nbgrader/blob/main/demos/README.md Installs the demo configuration files onto the target server using root access. ```bash ./deploy_demos.sh root@demo-server ``` -------------------------------- ### Install Autosize via Bower Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/autosize/readme.md Use this command to install the Autosize library using the Bower package manager. ```bash bower install autosize ``` -------------------------------- ### Install Autosize via NPM Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/autosize/readme.md Use this command to install the Autosize library using the Node Package Manager. ```bash npm install autosize ``` -------------------------------- ### Manage Docker containers Source: https://github.com/jupyter/nbgrader/wiki/Multi-course-multi-grader-setup-using-nginx-and-Shibboleth Commands to start the stack and monitor logs. ```bash docker-compose up -d docker-compose logs -f --tail 50 # create /var/log: #docker-compose logs -f jhub > /var/log/jhub.log & # and create /etc/logrotate.d/jhub.conf ... ``` -------------------------------- ### Implement Exchange start method Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/exchange/exchange_api.rst The convenience method used to execute the exchange action sequence. ```python def start(self): self.set_timestamp() self.init_src() self.init_dest() self.copy_files() ``` -------------------------------- ### Setup Grader User Environment Source: https://github.com/jupyter/nbgrader/wiki/Multi-course-multi-grader-setup-using-nginx-and-Shibboleth Create the grader user, configure nbgrader_config.py, and enable necessary Jupyter extensions. ```bash adduser -q --gecos "" --disabled-password grader-mech su - grader-mech ![ -e .jupyter ] && mkdir .jupyter ![ -d .jupyter ] && echo ".jupyter is not directory" && exit 1 echo <.jupyter/nbgrader_config.py c = get_config() c.CourseDirectory.course_id = 'MECH' c.CourseDirectory.root = '/home/grader-mech/Course-MECH' c.IncludeHeaderFooter.header = "source/header.ipynb" EOF jupyter-server extension disable --user nbgrader.server_extensions.assignment_list jupyter-server extension enable --user nbgrader.server_extensions.formgrader jupyter-labextension disable --level=user nbgrader:assignment-list jupyter-labextension enable --level=user nbgrader:formgrader jupyter-labextension enable --level=user nbgrader:create-assignment ``` -------------------------------- ### Install Playwright for Labextensions Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/contributor_guide/testing.rst Initialize Playwright for testing labextensions. This command must be run before testing labextensions. ```bash npx playwright install ``` -------------------------------- ### Verify Nbgrader Installation Source: https://github.com/jupyter/nbgrader/wiki/Multi-course-multi-grader-setup-using-nginx-and-Shibboleth List installed packages to confirm nbgrader and related dependencies are present. ```bash pip list |egrep '(^jupyter..b |nbg|noteb)|idle' jupyterhub 4.0.2 jupyterhub-idle-culler 1.2.1 jupyterlab ==4.0.12 nbgrader 0.9.1 notebook ==7.0.8 notebook_shim 0.2.4 ``` -------------------------------- ### Install JavaScript Dependencies Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/contributor_guide/js_dependencies.rst Run this command after modifying package.json to download and install JavaScript dependencies. Ensure JupyterLab is installed for the `jlpm` command. ```bash python tasks.py js ``` -------------------------------- ### Install jQuery for Node.js Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/jquery/README.md To use jQuery in a Node.js environment, first install it using npm. This command installs the package locally. ```sh npm install jquery ``` -------------------------------- ### Install nbgrader using conda Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/installation.rst Install nbgrader and its dependencies using conda. This method also installs Jupyter. ```bash conda install jupyter conda install -c conda-forge nbgrader ``` -------------------------------- ### Run Jekyll Serve for Documentation Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/bootstrap/README.md This command serves the Bootstrap documentation locally using Jekyll. Ensure you have Jekyll installed and are in the root '/bootstrap' directory. ```bash jekyll serve ``` -------------------------------- ### Create and Setup Tutors (Instructors) Source: https://github.com/jupyter/nbgrader/wiki/Multi-course-multi-grader-setup-using-nginx-and-Shibboleth Use this script to create tutor accounts, assign them to courses, and enable necessary Jupyter extensions. It requires a `tutor_ids.txt` file mapping tutor IDs to course IDs. ```bash docker-compose exec jhub bash for id in `cut -f1 tutor_ids.txt |tr [A-Z] [a-z]`; do adduser -q --gecos "" --firstuid 2000 --gid 2000 --disabled-password $id su - $id -c "chmod go-rwx ." su - $id -c "jupyter-nbextension enable course_list/main --user --section=tree" su - $id -c "jupyter-serverextension enable nbgrader.server_extensions.course_list --user" # the following three lines are optional: su - $id -c "jupyter-nbextension enable create_assignment/main --user" su - $id -c "jupyter-nbextension disable assignment_list/main --user --section=tree" su - $id -c "jupyter-serverextension disable nbgrader.server_extensions.assignment_list --user" done python3 api_request.py users add `cut -f1 tutor_ids.txt` # see api_request.py below... ``` ```bash cat course_graders.txt |while read COURSE_ID GRADER_LIST; do python3 api_request.py groups add formgrade-${COURSE_ID} ${GRADER_LIST}` done exit ``` -------------------------------- ### Enable nbgrader extensions for system Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/installation.rst Install or enable nbgrader lab and server extensions for all users on the system, using the --system flag. ```bash jupyter labextension enable --level=system @jupyter/nbgrader jupyter server extension enable --system --py nbgrader ``` -------------------------------- ### Install nbgrader using pip Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/installation.rst Use this command to install the current version of nbgrader and its command-line tools via pip. ```bash pip install nbgrader ``` -------------------------------- ### Install jupyterhub-idle-culler Source: https://github.com/jupyter/nbgrader/wiki/Multi-course-multi-grader-setup-using-nginx-and-Shibboleth Install the idle-culler service into a running JupyterHub container. ```bash docker-compose exec jhub pip install jupyterhub-idle-culler ``` -------------------------------- ### Install Bootstrap with npm Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/bootstrap/README.md Use npm to install Bootstrap. This is a common method for managing front-end dependencies in modern web development projects. ```bash npm install bootstrap ``` -------------------------------- ### Install a new kernel with envkernel Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/advanced.rst Create and install a new Jupyter kernel that runs within a specified Docker image. ```bash ./envkernel.py docker --name=NAME --display-name=DNAME DOCKER-IMAGE ``` -------------------------------- ### Example return structure for ExchangeList Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/exchange/exchange_api.rst The expected list of dictionaries returned by the ExchangeList.start() method. ```json [ {'course_id': 'course_2', 'assignment_id': 'car c2', 'status': 'released', 'path': '/tmp/exchange/course_2/outbound/car c2', 'notebooks': [{'notebook_id': 'Assignment', 'path': '/tmp/exchange/course_2/outbound/car c2/Assignment.ipynb'}]}, {'course_id': 'course_2', 'assignment_id': 'tree c2', 'status': 'released', 'path': '/tmp/exchange/course_2/outbound/tree c2', 'notebooks': [{'notebook_id': 'Assignment', 'path': '/tmp/exchange/course_2/outbound/tree c2/Assignment.ipynb'}]} ] ``` -------------------------------- ### Install DataTables via bower Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/datatables.net/Readme.md Use this command to install the DataTables package and save it to your bower configuration. ```bash bower install --save datatables.net ``` -------------------------------- ### Default JavaScript Solution Stub Example Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/configuration/student_version.rst Shows the default solution stub replacement for JavaScript code when BEGIN/END SOLUTION delimiters are absent. ```javascript function foo (bar){ // BEGIN SOLUTION console.log(bar); // END SOLUTION } ``` -------------------------------- ### Install Rouge Gem Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/bootstrap/README.md Install the Rouge gem, a Ruby-based syntax highlighter required for running the Bootstrap documentation locally. This is a prerequisite for 'jekyll serve'. ```bash gem install rouge ``` -------------------------------- ### List Jupyter Extensions Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/installation.rst Use these commands to verify the installation status of Jupyter lab and server extensions. ```bash jupyter labextension list jupyter server extension list ``` -------------------------------- ### Get Help for Jupyter Extensions Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/installation.rst Access full help documentation for Jupyter extension management commands. ```bash jupyter labextension --help-all jupyter server extension --help-all ``` -------------------------------- ### Example of Autogenerated Test Code Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/creating_and_grading_assignments.ipynb This is an example of how the autotest syntax is converted into actual test code that students will see during autograding. ```python import unittest class TestSquares(unittest.TestCase): def test_squares(self): squares = nbgrader.exercise.Exercise.squares self.assertEqual(squares(1), 1) self.assertEqual(squares(2), 4) self.assertEqual(squares(3), 9) ``` -------------------------------- ### Fetch feedback using ExchangeFetchFeedback Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/exchange/exchange_api.rst Initializes and starts the feedback fetching process within the nbgrader server extension. ```python with self.get_assignment_dir_config() as config: try: config = self.load_config() config.CourseDirectory.course_id = course_id config.CourseDirectory.assignment_id = assignment_id coursedir = CourseDirectory(config=config) authenticator = Authenticator(config=config) exchange = ExchangeFactory(config=config) fetch = exchange.FetchFeedback( coursedir=coursedir, authenticator=authenticator, config=config) fetch.start() ..... ``` -------------------------------- ### Enable nbgrader extensions for current user Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/installation.rst Install or enable nbgrader lab and server extensions specifically for the current user, using the --user flag. ```bash jupyter labextension enable --level=user @jupyter/nbgrader jupyter server extension enable --user --py nbgrader ``` -------------------------------- ### Define upgrade and downgrade migration logic Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/contributor_guide/database.rst Example implementation of schema changes within an Alembic migration file. ```python def upgrade(): op.add_column('grade', sa.Column('extra_credit', sa.Float)) def downgrade(): op.drop_column('grade', 'extra_credit') ``` -------------------------------- ### Example Custom Collector Command Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/plugins/zipcollect-plugin.rst Use this command to specify a custom filename collector plugin. Ensure your plugin is in a Python file and accessible. ```bash nbgrader zip_collect --collector=mycollector.MyCollector ``` -------------------------------- ### Example Custom Extractor Command Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/plugins/zipcollect-plugin.rst Use this command to specify a custom extractor plugin. Ensure your plugin is in a Python file and accessible. ```bash nbgrader zip_collect --extractor=myextractor.MyExtractor ``` -------------------------------- ### Import sha1 for Hashing Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/advanced.rst This setup code imports the sha1 function from the hashlib library, which is necessary for generating hashed tests. ```python from hashlib import sha1 ``` -------------------------------- ### Create and Activate Conda Environment Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/contributor_guide/installation_developer.rst Create a new conda environment named 'nbgrader' with Python and Node.js installed using conda-forge, then activate it. ```bash # create a new environment mamba create -n nbgrader -c conda-forge python nodejs -y # activate the environment mamba activate nbgrader ``` -------------------------------- ### Python Warning Example Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/tests/preprocessors/files/warning-pattern.ipynb Shows how to issue a user warning in Python using the warnings module. This is useful for notifying users of potential issues without stopping execution. ```python import warnings warnings.warn("This is a warning message") ``` -------------------------------- ### Indented Python Solution Stub Example Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/configuration/student_version.rst Demonstrates how nbgrader indents the default solution stub based on the original code's indentation. ```python def foo(bar): """Prints `bar`. """ # YOUR CODE HERE raise NotImplementedError ``` -------------------------------- ### Set up Student Home Directory and Configuration Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/managing_assignment_files.ipynb Create a temporary directory to simulate a student's home directory and configure nbgrader to use the specified exchange directory for that student. ```bash %%bash # remove the fake student home directory if it exists, for demo purposes rm -rf /tmp/student_home # create the fake student home directory and switch to it mkdir /tmp/student_home ``` -------------------------------- ### Display instructor configuration Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/managing_assignment_files.ipynb View the current instructor configuration file. ```bash %%bash cat nbgrader_config.py ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/contributor_guide/documentation.rst Run this command to build the documentation locally. It executes notebooks, generates command-line documentation, and converts rst files to HTML. ```bash python tasks.py docs ``` -------------------------------- ### Launch a specific nbgrader demo Source: https://github.com/jupyter/nbgrader/blob/main/demos/README.md Connects to the server via SSH and executes the restart script for a chosen demo configuration. ```bash ssh root@demo-server ./restart_demo.sh demo_one_class_one_grader ``` -------------------------------- ### Execute course creation command Source: https://github.com/jupyter/nbgrader/wiki/Multi-course-multi-grader-setup-using-nginx-and-Shibboleth Command to trigger the Makefile target for a new course. ```bash docker-compose exec jhub make gr-NEW_COURSE_ID ``` -------------------------------- ### NotImplementedError Traceback Example Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem1.ipynb This is an example of a traceback for a NotImplementedError in Python, showing the error message and the call stack leading to the error. ```python --------------------------------------------------------------------------- NotImplementedError Traceback (most recent call last) Cell In[10], line 2 1 # YOUR CODE HERE ----> 2 raise NotImplementedError() NotImplementedError: ``` -------------------------------- ### Run Full nbgrader Test Suite Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/contributor_guide/testing.rst Execute the complete test suite for nbgrader. This command should be run from the root of the repository. ```bash python tasks.py tests ``` -------------------------------- ### Reset nbgrader database Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/managing_the_database.ipynb Removes the existing database file to start with a fresh state. ```bash %%bash # remove the existing database, to start fresh rm gradebook.db ``` -------------------------------- ### Command Line Interface Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/plugins/export-plugin.rst How to execute a custom export plugin via the command line. ```APIDOC ## CLI: nbgrader export ### Description Executes the grade export process using a specified exporter plugin. ### Command `nbgrader export --exporter=module.ClassName` ### Parameters - **--exporter** (string) - Required - The import path to the custom exporter class (e.g., myexporter.MyExporter). ``` -------------------------------- ### Install DataTables via npm Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/datatables.net/Readme.md Use this command to add the DataTables package to your project dependencies. ```bash npm install datatables.net ``` -------------------------------- ### List Available Assignments (Bash) Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/managing_assignment_files.ipynb Use this command to see assignments released by instructors for a specific course. Ensure the HOME environment variable is set and you are in the desired directory. ```bash export HOME=/tmp/student_home && cd $HOME nbgrader list ``` -------------------------------- ### Import students via CSV Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/managing_the_database.ipynb Creates a CSV file and imports multiple student records into the database. ```bash %%file students.csv id,last_name,first_name,email bitdiddle,Bitdiddle,Ben, hacker,Hacker,Alyssa, ``` ```bash %%bash nbgrader db student import students.csv ``` -------------------------------- ### Identify common student loop errors Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/autograding_resources.rst Examples of incorrect versus correct loop implementations in Python. ```python for i in x: y[i] = f(x[i]) ``` ```python for i in range(len(x)): y[i] = f(x[i]) ``` -------------------------------- ### Configure Custom Solution Delimiters and Stubs Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/configuration/student_version.rst Configure custom BEGIN/END SOLUTION delimiters and language-specific code stubs in nbgrader_config.py. ```python c = get_config() c.ClearSolutions.begin_solution_delimeter = "BEGIN MY SOLUTION" c.ClearSolutions.end_solution_delimeter = "END MY SOLUTION" c.ClearSolutions.code_stub = { "python": "# your code here\nraise NotImplementedError", "javascript": "// your code here\nthrow new Error();" } ``` -------------------------------- ### Configure nbgrader course directory Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/configuration/jupyterhub_config.rst Set the root course directory in the instructor's nbgrader_config.py file. ```python c = get_config() c.CourseDirectory.root = '/home/instructor/course101' ``` -------------------------------- ### Clone Bootstrap Repository Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/bootstrap/README.md Clone the Bootstrap repository directly from GitHub to get the latest source code. ```bash git clone https://github.com/twbs/bootstrap.git ``` -------------------------------- ### Configure course directory root for separate notebook server Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/configuration/nbgrader_config.rst Specify the absolute path to the course directory when the notebook server runs outside the course folder. ```python c = get_config() c.CourseDirectory.root = "/path/to/course/directory" ``` -------------------------------- ### Animate Colors with jQuery Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/jquery-color/README.md Example HTML page demonstrating how to animate background colors using jQuery Color. ```html
Hello!
``` -------------------------------- ### Detect reliance on global variables Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/autograding_resources.rst Example of a function incorrectly using a global variable instead of the provided argument. ```python def f(x): return arr * 2 ``` -------------------------------- ### Initialize ExchangeFactory for feedback release Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/exchange/exchange_api.rst Initializes the ExchangeFactory to prepare for releasing feedback. ```python exchange = ExchangeFactory(config=config) ``` -------------------------------- ### Disable specific nbgrader extensions for sys_prefix Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/installation.rst Commands to disable specific nbgrader extensions when they were installed with the --sys-prefix option. ```bash jupyter labextension disable --level=sys_prefix @jupyter/nbgrader:assignment-list jupyter server extension disable --sys-prefix nbgrader.server_extensions.assignment_list ``` ```bash jupyter labextension disable --level=sys_prefix @jupyter/nbgrader:create-assignment ``` ```bash jupyter labextension disable --level=sys_prefix @jupyter/nbgrader:formgrader jupyter server extension disable --sys-prefix nbgrader.server_extensions.formgrader ``` ```bash jupyter labextension disable --level=sys_prefix @jupyter/nbgrader:course-list jupyter server extension disable --sys-prefix nbgrader.server_extensions.course_list ``` -------------------------------- ### List local directory contents Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/managing_assignment_files.ipynb Verify the existence of the assignment folder in the student home directory. ```bash %%bash export HOME=/tmp/student_home && cd $HOME ls -l "/tmp/student_home" ``` -------------------------------- ### Upgrade packages in jhub container Source: https://github.com/jupyter/nbgrader/wiki/Multi-course-multi-grader-setup-using-nginx-and-Shibboleth Execute system updates and install additional utilities inside the running jhub container. ```bash docker-compose exec jhub bash apt update apt upgrade apt install mc nano less # etc. chmod o-rx /home # it is worth denying access to list /home exit ``` -------------------------------- ### Create and Set Permissions for Exchange Directory Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/managing_assignment_files.ipynb Ensure the exchange directory exists and is readable/writable by all users. This is crucial for nbgrader's operation. ```bash %%bash # remove existing directory, so we can start fresh for demo purposes rm -rf /tmp/exchange # create the exchange directory, with write permissions for everyone mkdir /tmp/exchange chmod ugo+rw /tmp/exchange ``` -------------------------------- ### Student Configuration for Exchange Directory Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/managing_assignment_files.ipynb Provide students with a configuration file that points to the correct exchange directory and sets the course ID. This is necessary if not using the default exchange location. ```python %%file /tmp/student_home/nbgrader_config.py c = get_config() c.Exchange.root = '/tmp/exchange' c.CourseDirectory.course_id = "example_course" ``` -------------------------------- ### Develop Jupyter Lab Extension Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/contributor_guide/installation_developer.rst Install a Jupyter Lab extension in developer mode. This command should be run from the nbgrader root directory. ```bash jupyter labextension develop --overwrite . ``` -------------------------------- ### Install Bootstrap with Meteor Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/bootstrap/README.md Add Bootstrap to your Meteor project using the provided package. This command integrates Bootstrap into your Meteor application. ```bash meteor add twbs:bootstrap ``` -------------------------------- ### Enable nbgrader lab extensions Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/installation.rst Commands to individually enable nbgrader lab extensions. Use these if extensions were previously disabled. ```bash jupyter labextension enable @jupyter/nbgrader:formgrader ``` ```bash jupyter labextension enable @jupyter/nbgrader:assignment-list ``` ```bash jupyter labextension enable @jupyter/nbgrader:course-list ``` ```bash jupyter labextension enable @jupyter/nbgrader:create-assignment ``` ```bash jupyter labextension enable @jupyter/nbgrader:validate-assignment ``` -------------------------------- ### Create and Manipulate Color Objects Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/jquery-color/README.md Examples of using the jQuery.Color factory to parse strings, create objects from values, or extract colors from elements. ```javascript // Parsing String Colors: jQuery.Color( "#abcdef" ); jQuery.Color( "rgb(100, 200, 255)" ); jQuery.Color( "rgba(100, 200, 255, 0.5)" ); jQuery.Color( "aqua" ); // Creating Color Objects in Code: // use null or undefined for values you wish to leave out jQuery.Color( red, green, blue, alpha ); jQuery.Color([ red, green, blue, alpha ]); jQuery.Color({ red: red, green: green, blue: blue, alpha: alpha }); jQuery.Color({ hue: hue, saturation: saturation, lightness: lightness, alpha: alpha }); // Helper to get value from CSS jQuery.Color( element, cssProperty ); ``` -------------------------------- ### Initialize and Generate Assignment with NbGraderAPI Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/api/high_level_api.rst Instantiate NbGraderAPI with a custom configuration to set course details, then use it to generate an assignment. Ensure the assignment source directory exists. ```python from nbgrader.apps import NbGraderAPI from traitlets.config import Config # create a custom config object to specify options for nbgrader config = Config() config.CourseDirectory.course_id = "course101" api = NbGraderAPI(config=config) # assuming source/ps1 exists api.generate_assignment("ps1") ``` -------------------------------- ### Display nbgrader configuration Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/managing_assignment_files.ipynb View the contents of the student's nbgrader_config.py file. ```bash %%bash cat /tmp/student_home/nbgrader_config.py ``` -------------------------------- ### List students in database Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/managing_the_database.ipynb Displays all students currently registered in the database. ```bash %%bash nbgrader db student list ``` -------------------------------- ### Define solution and manual tests Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/advanced.rst Standard solution definition and manual assertion-based testing in nbgrader. ```python ### BEGIN SOLUTION def foo(x): return x + 5 ### END SOLUTION ``` ```python assert isinstance(foo(3), int), "incrementing an int by 5 should return an int" assert foo(3) == 8, "3+5 should be 8" ``` -------------------------------- ### Import jQuery with Babel (ES6 Modules) Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/jquery/README.md Use this method when working with ES6 modules and a transpiler like Babel. Ensure jQuery is installed as a dependency. ```javascript import $ from "jquery"; ``` -------------------------------- ### Initialize Python Variables Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/tests/apps/files/autotest-multi-changed.ipynb Initializes variables of different types including integers, strings, lists, dictionaries, and booleans. This serves as a setup for subsequent tests. ```python # YOUR CODE HERE a = 5 b = "hello" c = [1, 2, "test"] d = {1 : 6, 3: 5} #right type, wrong value e = [5, -3.3, 'd'] #right values, wrong type f = True # wrong value def fun(x): if x < 0: raise ValueError else: return x ``` -------------------------------- ### Define Name and Collaborators Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/docs/source/user_guide/release/ps1/problem1.ipynb Initialize variables for student name and collaborators. ```python NAME = "" COLLABORATORS = "" ``` -------------------------------- ### Require jQuery with Browserify/Webpack Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/server_extensions/formgrader/static/node_modules/jquery/README.md This is the standard way to include jQuery when using module bundlers like Browserify or Webpack. jQuery must be installed via npm. ```javascript var $ = require( "jquery" ); ``` -------------------------------- ### Python Recursive Function Example Source: https://github.com/jupyter/nbgrader/blob/main/nbgrader/tests/preprocessors/files/infinite-recursion.ipynb This Python code defines a recursive function that calls itself. It demonstrates a simple recursive pattern that can lead to a RuntimeError if not properly managed. ```python def foo():\n foo()\n \nfoo() ```