Skip to content

Commit

Permalink
Merge pull request #152 from edina/update_for_notebook_7
Browse files Browse the repository at this point in the history
Update for notebook 7
  • Loading branch information
alasdair-macleod authored Feb 19, 2024
2 parents 19ee804 + d057d3c commit 985796a
Show file tree
Hide file tree
Showing 28 changed files with 116 additions and 102 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/linted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v2
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.11"
- name: Install dependencies
run: pip install .
- name: Lint with black
Expand Down
12 changes: 3 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@master
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install nbexchange
run: |
python -m pip install .[test]
- name: Run tests
run: pytest --cov=nbexchange --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
name: edina=nbexchange
fail_ci_if_error: true
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

repos:
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 24.1.1
hooks:
- id: black
language_version: python3
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 7.0.0
hooks:
- id: flake8
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Changelog

## v1 4.0

* Update to nbgrader 9
* Deliberately *not* update to python 3.12 [there are jupyter issues with 3.12]
* Remove the CodeCoverage actions

## v1 3.1

* Minor updates to github actions

## v1.3.0

* Update to nbgrader 8
* update to python 3.11
* Minor documentation updates

## v1.2.9

* Update to nbgrader that works in lab (0.7.0+)
* Update to python 3.10
* Add addtional tests

## v1.2.8

Support for multiple markers
Expand All @@ -23,7 +45,6 @@ Move from setup.py to pyproject.toml

Add full names to gradebook when available


## v1.1.0

Update the exchange & plugin to use a fixed timestamp
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pip install .[test]

or
```bash
pip install .[test]
pip install -e '.[test]'
```
if zsh or similar

Expand Down Expand Up @@ -70,7 +70,7 @@ There is no such thing as _too many tests_
This is how I test, using a virtual environment

```sh
pip install .[test]
pip install -r '.[test]'
pytest nbexchange
```

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11.0
FROM python:3.11.7-slim-bullseye

ARG COMMIT=""
LABEL commit=${COMMIT}
Expand All @@ -7,7 +7,7 @@ RUN pip install --upgrade pip
WORKDIR /usr/src/app

# Sqlite for testing
RUN apt update && apt install sqlite3 -y && rm -rf /var/lib/apt/lists/*
RUN apt update && apt install sqlite3 && rm -rf /var/lib/apt/lists/*

# Supervisord
RUN pip install supervisor
Expand Down
33 changes: 9 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
![Linted](https://github.com/edina/nbexchange/workflows/Linted/badge.svg?branch=prepare_for_public_release)
[![codecov](https://codecov.io/gh/edina/nbexchange/branch/prepare_for_public_release/graph/badge.svg)](https://codecov.io/gh/edina/nbexchange)
[![Docker Repository](https://quay.io/repository/noteable/nbexchange/status "Docker Repository on Quay")](https://quay.io/repository/noteable/nbexchange)

A dockerised service that replaces the defaukt nbgrader Exchange.

<!-- TOC -->
Expand All @@ -16,9 +12,9 @@ A dockerised service that replaces the defaukt nbgrader Exchange.
- [Helm](#helm)
- [nbgrader plugin](#nbgrader-plugin)
- [Configuration](#configuration)
- [Configuring `nbexchange`](#configuring-nbexchange)
- [Configuring the `nbexchange` service](#configuring-the-nbexchange-service)
- [**`user_plugin_class`** revisited](#user_plugin_class-revisited)
- [Configuring `nbgrader`](#configuring-nbgrader)
- [Configuring `nbgrader` to use the alternative exchange](#configuring-nbgrader-to-use-the-alternative-exchange)
- [Contributing](#contributing)
- [Releasing new versions](#releasing-new-versions)

Expand Down Expand Up @@ -53,7 +49,7 @@ Following the lead of other Jupyter services, it is a `tornado` application.

## Compatibility

This version installs `nbgrader` 0.8.2 (which makes it compatible with JupyterLab too)
This version installs `nbgrader` 0.9.1 (which makes it compatible with JupyterLab & Notebook 7)

# Documentation

Expand Down Expand Up @@ -101,31 +97,20 @@ helm install --name nbexchange --namespace default ./chart -f myconfiguration.ya

## nbgrader plugin

Installing nbexchange will also install nbgrader.
Installing nbexchange in a jupyter notebook will automatically install nbgrader.

nbexchange is not released to Pypy or anaconda, however you can install direct from GitHub - eg:

```
pip install https://github.com/edina/nbexchange/archive/v1.3.0.tar.gz
jupyter nbextension install --sys-prefix --py nbgrader
jupyter nbextension enable --sys-prefix validate_assignment/main --section=tree
jupyter serverextension enable --sys-prefix nbgrader.server_extensions.validate_assignment
jupyter nbextension enable --sys-prefix assignment_list/main --section=tree
jupyter serverextension enable --sys-prefix nbgrader.server_extensions.assignment_list
pip install https://github.com/edina/nbexchange/archive/v1.4.0.tar.gz
....
```

Note that the jupyter *lab* extensions are installed and enabled automatically - you may wish to switch *off* `formgrader` and `create_assignment` for non-teachers: YMMV
Note that nbgrader installs and enables the jupyter extensions automatically - you may wish to switch *off* `formgrader` and `create_assignment` for non-teachers: YMMV

# Configuration

There are two parts to configuring `nbexchange`:

- Configure `nbexchange` itself
- Configure `nbgrader` to use `nbexchange`

## Configuring `nbexchange`
## Configuring the `nbexchange` service

The exchange uses `nbexchange_config.py` for configuration.

Expand Down Expand Up @@ -163,7 +148,7 @@ See below for more details on that.

- **`base_url`**

This is the _service_ url for jupyterhub, and defaults to `/services/nbexchange/`
This is the _service_ url used by jupyterhub, and defaults to `/services/nbexchange/`

Can also be defined in the environment variable `JUPYTERHUB_SERVICE_PREFIX`

Expand Down Expand Up @@ -208,7 +193,7 @@ For the exchange to work, it needs some details about the user connecting to it
- `org_id`: As mentioned above, nbexchange divides courses and users across organisations. This is an id (numeric) for the org_id for the user.
- `cust_id`: Whilst most of the exchange is keyed on the `org_id`, knowing _customer_ can be useful. This is an id (numeric) for the org_id for the user.

## Configuring `nbgrader`
## Configuring `nbgrader` to use the alternative exchange

The primary reference for this should be the `nbgrader` documentation - but in short:

Expand Down
4 changes: 2 additions & 2 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v1
appVersion: "1.0"
appVersion: "1.4.0"
description: Nbexchange is a server-side component to nbgrader for keeping track of notebook assignments
name: nbexchange
version: 1.2.1
version: 1.4.0
3 changes: 2 additions & 1 deletion nbexchange/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Nbexchange
"""
VERSION = (1, 2, 6)

VERSION = (1, 4, 0)

__version__ = ".".join(map(str, VERSION))
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2019-04-02 15:40
"""

from enum import Enum

import sqlalchemy as sa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2021-08-20 15:24:21.878350
"""

from alembic import op

# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Revises: f26d6a79159d
Create Date: 2020-06-23 13:58:38.781382
"""

from datetime import datetime

from alembic import op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2020-10-21 13:55:01.264068
"""

from enum import Enum

import sqlalchemy as sa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2021-04-13 11:42:48.373791
"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2018-10-29 16:08:09.549850
"""

from datetime import datetime
from enum import Enum

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2020-03-17 11:28:26.163498
"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2020-11-12 08:28:58.059493
"""

import sqlalchemy as sa
from alembic import op

Expand Down
13 changes: 6 additions & 7 deletions nbexchange/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from getpass import getuser

import sentry_sdk
from jupyterhub.log import CoroutineLogFormatter, log_request
from jupyterhub.utils import url_path_join
from jupyter_server.log import log_request
from jupyter_server.utils import url_path_join as ujoin
from sentry_sdk.integrations.tornado import TornadoIntegration
from sqlalchemy.exc import OperationalError
from tornado import web
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.log import access_log, app_log, gen_log
from tornado.log import LogFormatter, access_log, app_log, gen_log
from tornado_prometheus import MetricsHandler, PrometheusMixIn
from traitlets import Bool, Dict, Integer, Type, Unicode, default
from traitlets.config import Application, catch_config_error
Expand Down Expand Up @@ -81,7 +81,7 @@ def version(self):

tornado_settings = Dict()

_log_formatter_cls = CoroutineLogFormatter
_log_formatter_cls = LogFormatter

@default("log_level")
def _log_level_default(self):
Expand All @@ -104,7 +104,7 @@ def add_url_prefix(prefix, handlers):
"""add a url prefix to handlers"""
for i, tup in enumerate(handlers):
lis = list(tup)
lis[0] = url_path_join(prefix, tup[0])
lis[0] = ujoin(prefix, tup[0])
handlers[i] = tuple(lis)

return handlers
Expand Down Expand Up @@ -236,7 +236,7 @@ def init_handlers(self):

for handler in handlers.default_handlers:
for url in handler.urls:
self.handlers.append((url_path_join(self.base_url, url), handler))
self.handlers.append((ujoin(self.base_url, url), handler))

self.handlers.append((r"/metrics", MetricsHandler))

Expand All @@ -260,7 +260,6 @@ def initialize(self, *args, **kwargs):
if self.subapp:
return
self.init_db()
# self.init_hub_auth()
self.init_tornado_settings()
self.init_handlers()
self.init_tornado_application()
Expand Down
1 change: 1 addition & 0 deletions nbexchange/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
and reduces noise in code by not having to manually
commit or rollback the db if a exception occurs.
"""

import os
from contextlib import contextmanager

Expand Down
1 change: 1 addition & 0 deletions nbexchange/dbutil.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Database utilities for NbExchange"""

# Completely derived from the Jupyterhub code!!
import os
import shutil
Expand Down
1 change: 1 addition & 0 deletions nbexchange/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
must be imported below the declaration for `Alembic`
autogenerate to work.
"""

# import sqlalchemy.orm as orm
from sqlalchemy.orm import declarative_base

Expand Down
1 change: 1 addition & 0 deletions nbexchange/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
in your root `nbgrader_config.py` file.
"""

from .collect import ExchangeCollect
from .exchange import Exchange, ExchangeError
from .fetch import ExchangeFetch
Expand Down
1 change: 1 addition & 0 deletions nbexchange/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""pytest fixtures for nbexchange"""

import logging
import os
from getpass import getuser
Expand Down
Loading

0 comments on commit 985796a

Please sign in to comment.