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

Add base URL to kernelspecs file path #149

Merged
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
12 changes: 8 additions & 4 deletions plugins/kernels/fps_kernels/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from fps_auth.models import User # type: ignore
from fps_auth.db import get_user_db # type: ignore
from fps_auth.config import get_auth_config # type: ignore
from fps_lab.config import get_lab_config # type: ignore

from .kernel_server.server import KernelServer, kernels # type: ignore
from .models import Session
Expand All @@ -31,13 +32,15 @@ async def stop_kernels():


@router.get("/api/kernelspecs")
async def get_kernelspecs():
async def get_kernelspecs(
lab_config=Depends(get_lab_config), user: User = Depends(current_user)
):
for path in (prefix_dir / "share" / "jupyter" / "kernels").glob("*/kernel.json"):
with open(path) as f:
spec = json.load(f)
name = path.parent.name
resources = {
f.stem: f"/kernelspecs/{name}/{f.name}"
f.stem: f"{lab_config.base_url}kernelspecs/{name}/{f.name}"
for f in path.parent.iterdir()
if f.is_file() and f.name != "kernel.json"
}
Expand All @@ -49,14 +52,15 @@ async def get_kernelspecs():
async def get_kernelspec(
kernel_name,
file_name,
user: User = Depends(current_user),
):
return FileResponse(
prefix_dir / "share" / "jupyter" / "kernels" / kernel_name / file_name
)


@router.get("/api/kernels")
async def get_kernels():
async def get_kernels(user: User = Depends(current_user)):
results = []
for kernel_id, kernel in kernels.items():
results.append(
Expand Down Expand Up @@ -97,7 +101,7 @@ async def rename_session(


@router.get("/api/sessions")
async def get_sessions():
async def get_sessions(user: User = Depends(current_user)):
for session in sessions.values():
kernel_id = session["kernel"]["id"]
kernel_server = kernels[kernel_id]["server"]
Expand Down
1 change: 1 addition & 0 deletions plugins/kernels/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ packages = find:
install_requires =
fps >=0.0.8
fps-auth
fps-lab
pyzmq
websockets

Expand Down