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

Jupyter server #1586

Merged
merged 5 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
WebApp uses notebook_dir or root_dir depending on the server applicat…
…ion (respectively notebook.notebookapp.NotebookApp or jupyter_server.serverapp.ServerApp)
  • Loading branch information
Nicolas Brichet committed May 22, 2022
commit 811019353a33b0c45fc31f31c660eb6b60db5c12
2 changes: 1 addition & 1 deletion nbgrader/exchange/abc/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Exchange(LoggingConfigurable):
help=dedent(
"""
Local path for storing student assignments. Defaults to '.'
which is normally Jupyter's notebook_dir.
which is normally Jupyter's root_dir.
"""
)
).tag(config=True)
Expand Down
21 changes: 18 additions & 3 deletions nbgrader/server_extensions/assignment_list/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def chdir(dirname):

class AssignmentList(LoggingConfigurable):

@property
def root_dir(self):
return self._root_dir

@root_dir.setter
def root_dir(self, directory):
self._root_dir = directory

def load_config(self):
paths = jupyter_config_path()
paths.insert(0, os.getcwd())
Expand All @@ -47,7 +55,7 @@ def load_config(self):
@contextlib.contextmanager
def get_assignment_dir_config(self):
# first get the exchange assignment directory
with chdir(self.parent.notebook_dir):
with chdir(self.root_dir):
config = self.load_config()

lister = ExchangeFactory(config=config).List(config=config)
Expand Down Expand Up @@ -96,9 +104,9 @@ def list_released_assignments(self, course_id=None):
else:
for assignment in assignments:
if assignment['status'] == 'fetched':
assignment['path'] = os.path.relpath(assignment['path'], self.parent.notebook_dir)
assignment['path'] = os.path.relpath(assignment['path'], self.root_dir)
for notebook in assignment['notebooks']:
notebook['path'] = os.path.relpath(notebook['path'], self.parent.notebook_dir)
notebook['path'] = os.path.relpath(notebook['path'], self.root_dir)
retvalue = {
"success": True,
"value": sorted(assignments, key=lambda x: (x['course_id'], x['assignment_id']))
Expand Down Expand Up @@ -360,6 +368,13 @@ def load_jupyter_server_extension(nbapp):
nbapp.log.info("Loading the assignment_list nbgrader serverextension")
webapp = nbapp.web_app
webapp.settings['assignment_list_manager'] = AssignmentList(parent=nbapp)

# compatibility between notebook.notebookapp.NotebookApp and jupyter_server.serverapp.ServerApp
if nbapp.name == 'jupyter-notebook':
webapp.settings['assignment_list_manager'].root_dir = nbapp.notebook_dir
else:
webapp.settings['assignment_list_manager'].root_dir = nbapp.root_dir

base_url = webapp.settings['base_url']
webapp.add_handlers(".*$", [
(ujoin(base_url, pat), handler)
Expand Down
8 changes: 7 additions & 1 deletion nbgrader/server_extensions/course_list/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,13 @@ def load_jupyter_server_extension(nbapp):
nbapp.log.info("Loading the course_list nbgrader serverextension")
webapp = nbapp.web_app
base_url = webapp.settings['base_url']
webapp.settings['assignment_dir'] = nbapp.notebook_dir

# compatibility between notebook.notebookapp.NotebookApp and jupyter_server.serverapp.ServerApp
if nbapp.name == 'jupyter-notebook':
webapp.settings['assignment_dir'] = nbapp.notebook_dir
else:
webapp.settings['assignment_dir'] = nbapp.root_dir

webapp.add_handlers(".*$", [
(ujoin(base_url, pat), handler)
for pat, handler in default_handlers
Expand Down
23 changes: 18 additions & 5 deletions nbgrader/server_extensions/formgrader/formgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class FormgradeExtension(NbGrader):
name = u'formgrade'
description = u'Grade a notebook using an HTML form'

@property
def root_dir(self):
return self._root_dir

@root_dir.setter
def root_dir(self, directory):
self._root_dir = directory

@default("classes")
def _classes_default(self):
classes = super(FormgradeExtension, self)._classes_default()
Expand All @@ -33,22 +41,20 @@ def init_tornado_settings(self, webapp):
# Init jinja environment
jinja_env = Environment(loader=FileSystemLoader([handlers.template_path]))

course_dir = self.coursedir.root
notebook_dir = self.parent.notebook_dir
relpath = os.path.relpath(course_dir, notebook_dir)
relpath = os.path.relpath(self.coursedir.root, self.root_dir)
if relpath.startswith("../"):
nbgrader_bad_setup = True
self.log.error(
"The course directory root is not a subdirectory of the notebook "
"server root. This means that nbgrader will not work correctly. "
"If you want to use nbgrader, please ensure the course directory "
"root is in a subdirectory of the notebook root: %s", notebook_dir)
"root is in a subdirectory of the notebook root: %s", self.root_dir)
else:
nbgrader_bad_setup = False

# Configure the formgrader settings
tornado_settings = dict(
nbgrader_url_prefix=os.path.relpath(self.coursedir.root, self.parent.notebook_dir),
nbgrader_url_prefix=relpath,
nbgrader_coursedir=self.coursedir,
nbgrader_authenticator=self.authenticator,
nbgrader_exporter=HTMLExporter(config=self.config),
Expand Down Expand Up @@ -84,6 +90,13 @@ def load_jupyter_server_extension(nbapp):
nbapp.log.info("Loading the formgrader nbgrader serverextension")
webapp = nbapp.web_app
formgrader = FormgradeExtension(parent=nbapp)

# compatibility between notebook.notebookapp.NotebookApp and jupyter_server.serverapp.ServerApp
if nbapp.name == 'jupyter-notebook':
formgrader.root_dir = nbapp.notebook_dir
else:
formgrader.root_dir = nbapp.root_dir

formgrader.log = nbapp.log
formgrader.initialize([])
formgrader.init_tornado_settings(webapp)
Expand Down
14 changes: 10 additions & 4 deletions nbgrader/server_extensions/validate_assignment/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
class ValidateAssignmentHandler(JupyterHandler):

@property
def notebook_dir(self):
return self.settings['notebook_dir']
def root_dir(self):
return self.settings['root_dir']

def load_config(self):
paths = jupyter_config_path()
Expand All @@ -38,7 +38,7 @@ def load_config(self):
return app.config

def validate_notebook(self, path):
fullpath = os.path.join(self.notebook_dir, path)
fullpath = os.path.join(self.root_dir, path)

try:
config = self.load_config()
Expand Down Expand Up @@ -132,7 +132,13 @@ def load_jupyter_server_extension(nbapp):
nbapp.log.info("Loading the validate_assignment nbgrader serverextension")
webapp = nbapp.web_app
base_url = webapp.settings['base_url']
webapp.settings['notebook_dir'] = nbapp.notebook_dir

# compatibility between notebook.notebookapp.NotebookApp and jupyter_server.serverapp.ServerApp
if nbapp.name == 'jupyter-notebook':
webapp.settings['root_dir'] = nbapp.notebook_dir
else:
webapp.settings['root_dir'] = nbapp.root_dir

webapp.add_handlers(".*$", [
(ujoin(base_url, pat), handler)
for pat, handler in default_handlers
Expand Down