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

Feature/eduhelx utils #3

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ for the frontend extension.

## Requirements

- JupyterLab >= 3.0.0
- JupyterLab >= 4.0.0

## Install

Expand Down Expand Up @@ -53,24 +53,27 @@ The `jlpm` command is JupyterLab's pinned version of
[yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use
`yarn` or `npm` in lieu of `jlpm` below.

Installing the extension
```bash
# Clone the repo to your local environment
# Change directory to the jupyterlab_eduhelx_submission directory
# Install package in development mode
pip install -e ".[test]"
pip install -ve ".[test]"
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Server extension must be manually installed in develop mode
jupyter server extension enable jupyterlab_eduhelx_submission
# Rebuild extension Typescript source after making changes
jlpm build
```

You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.

Frontend Development (after install)
```bash
# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm watch
```

Backend Development (after install)
```bash
cp .env.sample .env
source .env
# Run JupyterLab in another terminal
jupyter lab
```
Expand Down
37 changes: 22 additions & 15 deletions jupyterlab_eduhelx_submission/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,30 @@
from jupyter_server.utils import url_path_join
from pathlib import Path
from .config import ExtensionConfig
from .api import Api
from .git import (
from eduhelx_utils.git import (
InvalidGitRepositoryException,
get_remote, get_repo_root, clone_repository,
clone_repository,
get_tail_commit_id, get_repo_name, add_remote,
stage_files, commit, push
stage_files, commit, push, get_commit_info
)
from eduhelx_utils.api import Api
from .student_repo import StudentClassRepo, NotStudentClassRepositoryException
from .process import execute
from ._version import __version__

class DependencyContainer:
class AppContext:
def __init__(self, serverapp):
self.serverapp = serverapp
self.config = ExtensionConfig(self.serverapp)
self.api = Api(self.config)
self.api = Api(
api_url=self.config.GRADER_API_URL,
user_onyen=self.config.USER_ONYEN,
user_autogen_password=self.config.USER_AUTOGEN_PASSWORD,
jwt_refresh_leeway_seconds=self.config.JWT_REFRESH_LEEWAY_SECONDS
)

class BaseHandler(APIHandler):
context: DependencyContainer = None
context: AppContext = None

@property
def config(self) -> ExtensionConfig:
Expand Down Expand Up @@ -121,7 +126,7 @@ async def post(self):
class CourseAndStudentHandler(BaseHandler):
@tornado.web.authenticated
async def get(self):
student = await self.api.get_student()
student = await self.api.get_my_user()
course = await self.api.get_course()
self.finish(json.dumps({
"student": student,
Expand All @@ -134,8 +139,8 @@ async def get(self):
current_path: str = self.get_argument("path")
current_path_abs = os.path.realpath(current_path)

student = await self.api.get_student()
assignments = await self.api.get_assignments()
student = await self.api.get_my_user()
assignments = await self.api.get_my_assignments()
course = await self.api.get_course()

value = {
Expand Down Expand Up @@ -167,7 +172,9 @@ async def get(self):
# The student is in their repo, but we still need to check if they're actually in an assignment directory.
current_assignment = student_repo.current_assignment
if current_assignment is not None:
submissions = await self.api.get_assignment_submissions(current_assignment["id"], git_path=student_repo.repo_root)
submissions = await self.api.get_my_submissions(current_assignment["id"])
for submission in submissions:
submission["commit"] = get_commit_info(submission["commit_id"], path=student_repo.repo_root)
current_assignment["submissions"] = submissions

value["current_assignment"] = current_assignment
Expand All @@ -185,8 +192,8 @@ async def post(self):
current_path: str = data["current_path"]
current_path_abs = os.path.realpath(current_path)

student = await self.api.get_student()
assignments = await self.api.get_assignments()
student = await self.api.get_my_user()
assignments = await self.api.get_my_assignments()
course = await self.api.get_course()

try:
Expand Down Expand Up @@ -220,7 +227,7 @@ async def post(self):
)
push("origin", "master", path=student_repo.repo_root)
try:
await self.api.post_submission(
await self.api.create_submission(
student_repo.current_assignment["id"],
commit_id
)
Expand All @@ -242,7 +249,7 @@ async def get(self):

def setup_handlers(server_app):
web_app = server_app.web_app
BaseHandler.context = DependencyContainer(server_app)
BaseHandler.context = AppContext(server_app)

host_pattern = ".*$"

Expand Down
4 changes: 2 additions & 2 deletions jupyterlab_eduhelx_submission/student_repo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from pathlib import Path
from .git import InvalidGitRepositoryException
from . import git
from eduhelx_utils.git import InvalidGitRepositoryException
from eduhelx_utils import git

class NotStudentClassRepositoryException(Exception):
pass
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@
"watch:labextension": "jupyter labextension watch ."
},
"dependencies": {
"@jupyterlab/application": "^3.6.5",
"@jupyterlab/apputils": "^3.6.5",
"@jupyterlab/application": "^4.0.0",
"@jupyterlab/apputils": "^4.0.0",
"@jupyterlab/coreutils": "^6.0.0",
"@jupyterlab/filebrowser": "^3.6.5",
"@jupyterlab/filebrowser": "^4.0.11",
"@jupyterlab/services": "^7.0.0",
"@jupyterlab/ui-components": "^3.6.5",
"@lumino/commands": "^1.21.1",
"@lumino/coreutils": "^1.12.1",
"@lumino/disposable": "^1.10.4",
"@lumino/signaling": "^1.11.1",
"@jupyterlab/ui-components": "^4.0.11",
"@lumino/commands": "^2.0.0",
"@lumino/coreutils": "^2.1.2",
"@lumino/disposable": "^2.1.2",
"@lumino/signaling": "^2.1.2",
"@lumino/widgets": "^2.2.0",
"@material-ui/core": "^4.8.2",
"@material-ui/icons": "^4.5.1",
Expand All @@ -81,7 +81,7 @@
"uuid": "^9.0.0"
},
"devDependencies": {
"@jupyterlab/builder": "^3.6.5",
"@jupyterlab/builder": "^4.0.0",
"@jupyterlab/testutils": "^4.0.0",
"@types/jest": "^29.2.0",
"@types/json-schema": "^7.0.11",
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling>=1.5.0", "jupyterlab>=4.0.0,<5", "hatch-nodejs-version"]
requires = ["hatchling==1.10.0", "jupyterlab>=4.0.0,<5", "hatch-nodejs-version"]
build-backend = "hatchling.build"

[project]
Expand All @@ -25,7 +25,8 @@ dependencies = [
"jupyter_server>=2.0.1,<3",
"requests>=2.0.1,<3",
"httpx>=0,<1",
"PyJWT>=2.0.0,<3"
"PyJWT>=2.0.0,<3",
"eduhelx_utils@git+https://github.com/helxplatform/eduhelx-utils"
]
dynamic = ["version", "description", "authors", "urls", "keywords"]

Expand All @@ -41,6 +42,9 @@ test = [
[tool.hatch.version]
source = "nodejs"

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.metadata.hooks.nodejs]
fields = ["description", "authors", "urls"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export const AssignmentSubmissions = ({ ...props }: AssignmentSubmissionsProps)
<div className={ assignmentSubmissionsContainerClass } { ...props }>
<TextDivider innerStyle={{ fontSize: 'var(--jp-ui-font-size2)' }} style={{ padding: '0 12px' }}>Submissions</TextDivider>
<div className={ assignmentsListClass }>
{ submissionSource!.map((submission) => (
{ submissionSource!.map((submission, i) => (
<ExpansionPanel key={ submission.id } square>
<ExpansionPanelSummary expandIcon={ <ExpandMoreSharp /> }>
<ListItem>
<ListItemIcon style={{ minWidth: 0, marginRight: 16 }}>
<span>{ `#${ submission.id }` }</span>
<span>{ `#${ submissionSource!.length - i }` }</span>
</ListItemIcon>
<ListItemText disableTypography>
<div style={{ fontSize: 12, color: 'var(--jp-ui-font-color2)', marginBottom: 4 }}>
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application'
import { IFileBrowserFactory, FileBrowserModel } from '@jupyterlab/filebrowser'
import { FileBrowserModel, IDefaultFileBrowser } from '@jupyterlab/filebrowser'
import { Dialog, showErrorMessage } from '@jupyterlab/apputils'
import { IChangedArgs } from '@jupyterlab/coreutils'
import { getServerSettings, IServerSettings } from './api'
import { AssignmentWidget } from './widgets'
import { EduhelxSubmissionModel } from './model'
import { submissionIcon } from './style/icons'
import { IFileBrowserFactory } from '@jupyterlab/filebrowser'

async function activate (
app: JupyterFrontEnd,
fileBrowser: IDefaultFileBrowser,
restorer: ILayoutRestorer,
shell: ILabShell,
fileBrowserFactory: IFileBrowserFactory
) {
let serverSettings: IServerSettings
const fileBrowser = fileBrowserFactory.defaultBrowser
try {
serverSettings = await getServerSettings()
} catch (e: any) {
Expand All @@ -31,7 +31,7 @@ async function activate (
)
return
}

// await (fileBrowser.model as any)._restored.promise
const model = new EduhelxSubmissionModel()
Promise.all([app.restored, fileBrowser.model.restored]).then(() => {
model.currentPath = fileBrowser.model.path
Expand Down Expand Up @@ -61,9 +61,9 @@ const plugin: JupyterFrontEndPlugin<void> = {
description: 'A JupyterLab extension tfor submitting assignments in EduHeLx',
autoStart: true,
requires: [
IDefaultFileBrowser,
ILayoutRestorer,
ILabShell,
IFileBrowserFactory
],
activate
};
Expand Down
3 changes: 2 additions & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ export class EduhelxSubmissionModel implements IEduhelxSubmissionModel {
this.currentAssignment = undefined
this.assignments = undefined
this.student = undefined
await this._assignmentPoll.refresh()
// await this._assignmentPoll.refresh()
this._refreshModel()
await this._assignmentPoll.tick
}

Expand Down
Loading