Skip to content

Commit

Permalink
feat: use dataset handle sqlite data store
Browse files Browse the repository at this point in the history
  • Loading branch information
NewByVector committed Nov 30, 2023
1 parent 068f1f2 commit 6a9fcce
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 310 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,5 @@ dist
/.ijwb/
/.aswb/
/.clwb/

.secretnote
22 changes: 14 additions & 8 deletions packages/secretnote/src/modules/server/server-manager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { ServerConnection, URL } from '@difizen/libro-jupyter';
import { Emitter, inject, prop, singleton } from '@difizen/mana-app';

import { uuid } from '@/utils';

import type { IServer } from './protocol';
import { ServerStatus } from './protocol';

Expand Down Expand Up @@ -30,6 +28,11 @@ export class SecretNoteServerManager {
if (response.status === 200) {
const data = (await response.json()) as IServer[];
for (const item of data) {
/**
* For historical reasons, the server id front-end uses a string and the server returns an int,
* preserving the distinction for now
*/
item.id = item.id.toString();
const spec = await this.getServerSpec(item);
if (spec) {
item.status = ServerStatus.running;
Expand All @@ -49,7 +52,6 @@ export class SecretNoteServerManager {

async addServer(server: Partial<IServer>) {
const newServer = {
id: uuid(),
name: server.name || 'Someone',
address: server.address || '',
status: ServerStatus.closed,
Expand All @@ -62,7 +64,6 @@ export class SecretNoteServerManager {
const init = {
method: 'POST',
body: JSON.stringify({
id: newServer.id,
name: newServer.name,
address: newServer.address,
}),
Expand All @@ -71,8 +72,13 @@ export class SecretNoteServerManager {
if (response.status === 200) {
newServer.status = ServerStatus.running;
newServer.kernelspec = spec;
this.servers.push(newServer);
this.onServerAddedEmitter.fire(newServer);
const data = await response.json();
const added = {
...newServer,
id: data.id,
};
this.servers.push(added);
this.onServerAddedEmitter.fire(added);
return newServer;
}
} catch (e) {
Expand Down Expand Up @@ -147,14 +153,14 @@ export class SecretNoteServerManager {
}
}

getServerSettings(server: IServer) {
getServerSettings(server: Partial<IServer>) {
return {
baseUrl: `http://${server.address}/`,
wsUrl: `ws://${server.address}/`,
};
}

private async getServerSpec(server: IServer) {
private async getServerSpec(server: Partial<IServer>) {
const settings = {
...this.serverConnection.settings,
...this.getServerSettings(server),
Expand Down
7 changes: 1 addition & 6 deletions pyprojects/secretnote/.jupyter/config_dev.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import subprocess
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand All @@ -18,11 +17,7 @@

c.ServerApp.token = ""

c.ServerApp.root_dir = subprocess.run(
["git", "rev-parse", "--show-toplevel"],
capture_output=True,
text=True,
).stdout.strip()
c.ServerApp.root_dir = "../../.secretnote"

c.LanguageServerManager.language_servers = {
"pyright-extended": {
Expand Down
1 change: 1 addition & 0 deletions pyprojects/secretnote/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies = [
"rich>=13.7.0",
"stack_data>=0.6.3",
"tqdm>=4.66.1",
"dataset>=1.6.2"
]
description = "Notebook suite for SecretFlow"
dynamic = ["version"]
Expand Down
17 changes: 4 additions & 13 deletions pyprojects/secretnote/src/secretnote/server/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import sys # noqa: I001
import sys

from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin

from secretnote._resources import require

from . import JUPYTER_SERVER_EXTENSION_MODULE
from .handlers import SinglePageApplicationHandler
from .node.handler import nodes_handlers
from .services.nodes.handlers import nodes_handlers
from .services.pages.handlers import pages_handlers


class SecretNoteApp(ExtensionAppJinjaMixin, ExtensionApp):
Expand All @@ -30,16 +30,7 @@ def template_paths(self):
def initialize_handlers(self):
routes = [
*nodes_handlers,
(
r"/secretnote/preview(.*)",
SinglePageApplicationHandler,
{"path": self.static_paths},
),
(
r"/secretnote(.*)",
SinglePageApplicationHandler,
{"path": self.static_paths},
),
*pages_handlers,
]
self.handlers.extend(routes)

Expand Down
114 changes: 0 additions & 114 deletions pyprojects/secretnote/src/secretnote/server/db.py

This file was deleted.

121 changes: 0 additions & 121 deletions pyprojects/secretnote/src/secretnote/server/node/handler.py

This file was deleted.

Loading

0 comments on commit 6a9fcce

Please sign in to comment.