Added: NbGrader as external service

This commit is contained in:
2025-09-15 22:13:37 +02:00
parent ded70d1c71
commit 2a0ae8a23f
4 changed files with 101 additions and 25 deletions

View File

@@ -1,30 +1,44 @@
# /srv/nbgrader/nbgrader_config.py
import os
c = get_config()
# 1. Course Configuration
c.CourseDirectory.course_id = "intro-to-python" # Change to your course name
c.CourseDirectory.root = '/srv/nbgrader/courses'
# Database configuration - use the same PostgreSQL as JupyterHub
p_user = os.environ.get("POSTGRES_USER", "")
p_pass = os.environ.get("POSTGRES_PASSWORD", "")
p_host = os.environ.get("POSTGRES_HOST", "postgres")
p_db = os.environ.get("POSTGRES_DB", "jupyterhub")
# 2. Exchange Directory (for submitting/collecting assignments)
c.Exchange.root = '/srv/nbgrader/exchange'
c.Exchange.path_includes_course = True
# NBgrader database URL
c.NbGrader.db_url = f"postgresql://{p_user}:{p_pass}@{p_host}:5432/{p_db}"
# 3. JupyterHub Integration
#c.NbGrader.hub_url = 'http://jupyterhub:8081/hub/api'
#c.NbGrader.hubapi_token = 'your-hub-token' # Generate with: openssl rand -hex 32
# Course configuration
course_id = os.environ.get("NBGRADER_COURSE_ID", "default_course")
c.CourseDirectory.course_id = course_id
c.CourseDirectory.root = "/srv/nbgrader"
# 4. Database Configuration
c.StudentAssignmentNotebook.database_url = 'sqlite:////srv/nbgrader/nbgrader.sqlite'
# Exchange directory configuration
exchange_dir = os.environ.get("NBGRADER_EXCHANGE_DIRECTORY", "/srv/nbgrader/exchange")
c.Exchange.root = exchange_dir
c.Exchange.course_id = course_id
# 5. Assignment Policies
c.ExecutePreprocessor.timeout = 300 # 5 minutes timeout per cell
c.ClearSolutions.code_stub = "# YOUR CODE HERE"
c.ClearSolutions.text_stub = "YOUR ANSWER HERE"
# Authentication
c.FormgradeApp.authenticator_plugin_class = "nbgrader.auth.JupyterHubAuthPlugin"
# 6. Formgrader UI Settings
# Logging
c.Application.log_level = "INFO"
# Formgrader settings
c.FormgradeApp.ip = "0.0.0.0"
c.FormgradeApp.port = 9999
c.FormgradeApp.authenticator_class = 'nbgrader.auth.hubauth.HubAuth'
c.FormgradeApp.ip = '0.0.0.0'
c.FormgradeApp.base_url = "/jupyter/services/nbgrader-formgrader/"
# 7. Permissions
c.CourseDirectory.groupshared = True
# Enable tornado debug mode for development
# c.FormgradeApp.tornado_settings = {'debug': True}
# Assignment settings
c.AssignmentListApp.assignment_dir = "/home/jovyan/assignments"
c.AssignmentListApp.exchange_directory = exchange_dir
# Grader settings
c.AutogradeApp.force = True
c.GenerateAssignmentApp.force = True