Skip to content

Commit bac7ccc

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent caa289a commit bac7ccc

File tree

10 files changed

+133
-130
lines changed

10 files changed

+133
-130
lines changed

jupyter_server_proxy/__init__.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from jupyter_server.utils import url_path_join as ujoin
22

33
from .api import (
4-
IconHandler, ServersInfoHandler, ServersAPIHandler, ListServersAPIHandler
4+
IconHandler,
5+
ListServersAPIHandler,
6+
ServersAPIHandler,
7+
ServersInfoHandler,
58
)
69
from .config import ServerProxy as ServerProxyConfig
7-
from .config import (
8-
get_entrypoint_server_processes, make_handlers, make_server_process
9-
)
10+
from .config import get_entrypoint_server_processes, make_handlers, make_server_process
1011
from .handlers import setup_handlers
1112

1213

@@ -62,10 +63,10 @@ def _load_jupyter_server_extension(nbapp):
6263
for sp in server_processes:
6364
if sp.launcher_entry.enabled and sp.launcher_entry.icon_path:
6465
icon_handlers.append(
65-
(
66+
(
6667
ujoin(base_url, f"server-proxy/icon/{sp.name}"),
6768
IconHandler,
68-
{"path": sp.launcher_entry.icon_path}
69+
{"path": sp.launcher_entry.icon_path},
6970
)
7071
)
7172

@@ -77,15 +78,10 @@ def _load_jupyter_server_extension(nbapp):
7778
ServersInfoHandler,
7879
{"server_processes": server_processes},
7980
),
80-
(
81-
ujoin(base_url, r"api/server-proxy"),
82-
ListServersAPIHandler
83-
),
84-
(
85-
ujoin(base_url, r"api/server-proxy/(?P<name>.*)"),
86-
ServersAPIHandler
87-
),
88-
] + icon_handlers,
81+
(ujoin(base_url, r"api/server-proxy"), ListServersAPIHandler),
82+
(ujoin(base_url, r"api/server-proxy/(?P<name>.*)"), ServersAPIHandler),
83+
]
84+
+ icon_handlers,
8985
)
9086

9187

jupyter_server_proxy/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ class IconHandler(web.StaticFileHandler):
4141
"""A singular handler for serving the icon."""
4242

4343
def get(self):
44-
return super().get('')
44+
return super().get("")
4545

4646
@classmethod
4747
def get_absolute_path(cls, root, path):
4848
"""We only serve one file, ignore relative path"""
4949
import os
50+
5051
return os.path.abspath(root)
5152

5253

jupyter_server_proxy/handlers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
from traitlets import Bytes, Dict, Instance, Integer, Unicode, Union, default, observe
2121
from traitlets.traitlets import HasTraits
2222

23+
from .manager import manager
2324
from .unixsock import UnixResolver
2425
from .utils import call_with_asked_args
2526
from .websocket import WebSocketHandlerMixin, pingable_ws_connect
26-
from .manager import manager
2727

2828

2929
class RewritableResponse(HasTraits):
@@ -801,7 +801,6 @@ async def ensure_process(self):
801801
# Invariant here should be: when lock isn't being held, either 'proc' is in state &
802802
# running, or not.
803803
async with self.state["proc_lock"]:
804-
805804
# If the server process is terminated via Runningsessions or killed
806805
# outside of jsp, we should be able to restart the process. If
807806
# process is not in running stated, remove proc object and restart
@@ -848,7 +847,9 @@ async def ensure_process(self):
848847

849848
# If process started succesfully, add it to manager
850849
# Add the server proxy app to manager
851-
await manager.add_server_proxy_app(self.name, self.base_url, cmd, self.port, proc)
850+
await manager.add_server_proxy_app(
851+
self.name, self.base_url, cmd, self.port, proc
852+
)
852853
except:
853854
# Make sure we remove proc from state in any error condition
854855
del self.state["proc"]

jupyter_server_proxy/manager.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
"""Manager for jupyter server proxy"""
22

33
from collections import namedtuple
4-
from tornado.ioloop import PeriodicCallback
4+
55
from jupyter_server.utils import url_path_join as ujoin
6+
from tornado.ioloop import PeriodicCallback
67

78
from .utils import check_pid
89

9-
10-
ServerProxy = namedtuple('ServerProxy', [
11-
'name', 'url', 'cmd', 'port', 'managed'
12-
])
13-
ServerProxyProc = namedtuple('ServerProxyProc', [
14-
'name', 'proc'
15-
])
10+
ServerProxy = namedtuple("ServerProxy", ["name", "url", "cmd", "port", "managed"])
11+
ServerProxyProc = namedtuple("ServerProxyProc", ["name", "proc"])
1612

1713

1814
async def monitor_server_proxy_procs():
@@ -53,25 +49,31 @@ async def add_server_proxy_app(self, name, base_url, cmd, port, proc):
5349
# Add proxy server metadata
5450
self.server_proxy_apps.append(
5551
ServerProxy(
56-
name=name,
57-
url=ujoin(base_url, name),
58-
cmd=' '.join(cmd),
59-
port=port,
60-
managed=True if proc else False,
61-
))
52+
name=name,
53+
url=ujoin(base_url, name),
54+
cmd=" ".join(cmd),
55+
port=port,
56+
managed=True if proc else False,
57+
)
58+
)
6259

6360
# Add proxy server proc object so that we can send SIGTERM
6461
# when user chooses to shut it down
6562
self._server_proxy_procs.append(
6663
ServerProxyProc(
67-
name=name,
68-
proc=proc,
69-
))
64+
name=name,
65+
proc=proc,
66+
)
67+
)
7068

7169
async def del_server_proxy_app(self, name):
7270
"""Remove a launched proxy server from list"""
73-
self.server_proxy_apps = [app for app in self.server_proxy_apps if app.name != name]
74-
self._server_proxy_procs = [app for app in self._server_proxy_procs if app.name != name]
71+
self.server_proxy_apps = [
72+
app for app in self.server_proxy_apps if app.name != name
73+
]
74+
self._server_proxy_procs = [
75+
app for app in self._server_proxy_procs if app.name != name
76+
]
7577
self.num_active_server_proxy_apps -= 1
7678

7779
def get_server_proxy_app(self, name):
@@ -121,5 +123,5 @@ async def terminate_all(self):
121123
manager = ServerProxyAppManager()
122124

123125
# Create a Periodic call back function to check the status of processes
124-
pc = PeriodicCallback(monitor_server_proxy_procs, 1e4)
126+
pc = PeriodicCallback(monitor_server_proxy_procs, 1e4)
125127
pc.start()

jupyter_server_proxy/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
23
from traitlets import TraitType
34

45

@@ -53,7 +54,7 @@ def validate(self, obj, value):
5354

5455

5556
def check_pid(pid):
56-
""" Check For the existence of a unix pid"""
57+
"""Check For the existence of a unix pid"""
5758
try:
5859
os.kill(pid, 0)
5960
except OSError:

labextension/src/index.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ import {
55
} from "@jupyterlab/application";
66
import { ILauncher } from "@jupyterlab/launcher";
77
import { PageConfig } from "@jupyterlab/coreutils";
8-
import { IRunningSessionManagers, IRunningSessions } from '@jupyterlab/running';
8+
import { IRunningSessionManagers, IRunningSessions } from "@jupyterlab/running";
99
import { IFrame, MainAreaWidget, WidgetTracker } from "@jupyterlab/apputils";
10-
import { LabIcon } from '@jupyterlab/ui-components';
11-
import { ServerProxyManager } from './manager';
12-
import { IModel as IServerProxyModel } from './serverproxy';
13-
import serverProxyAppSvgstr from '../style/icons/proxy.svg';
10+
import { LabIcon } from "@jupyterlab/ui-components";
11+
import { ServerProxyManager } from "./manager";
12+
import { IModel as IServerProxyModel } from "./serverproxy";
13+
import serverProxyAppSvgstr from "../style/icons/proxy.svg";
1414

1515
export const ServerProxyAppIcon = new LabIcon({
16-
name: 'server-proxy:proxyAppIcon',
17-
svgstr: serverProxyAppSvgstr
16+
name: "server-proxy:proxyAppIcon",
17+
svgstr: serverProxyAppSvgstr,
1818
});
1919

2020
namespace CommandIDs {
21-
export const open = 'running-server-proxy:open';
21+
export const open = "running-server-proxy:open";
2222
}
2323

2424
function newServerProxyWidget(
@@ -52,21 +52,22 @@ function newServerProxyWidget(
5252
* User can shut down the applications as well to restart them in future
5353
*
5454
*/
55-
function addRunningSessionManager(
55+
function addRunningSessionManager(
5656
managers: IRunningSessionManagers,
5757
app: JupyterFrontEnd,
58-
manager: ServerProxyManager
58+
manager: ServerProxyManager,
5959
): void {
6060
managers.add({
61-
name: 'Server Proxy Apps',
61+
name: "Server Proxy Apps",
6262
running: () =>
6363
Array.from(manager.running()).map(
64-
model => new RunningServerProxyApp(model)
64+
(model) => new RunningServerProxyApp(model),
6565
),
6666
shutdownAll: () => manager.shutdownAll(),
6767
refreshRunning: () => manager.refreshRunning(),
6868
runningChanged: manager.runningChanged,
69-
shutdownAllConfirmationText: 'Are you sure you want to close all server proxy applications?'
69+
shutdownAllConfirmationText:
70+
"Are you sure you want to close all server proxy applications?",
7071
});
7172

7273
class RunningServerProxyApp implements IRunningSessions.IRunningItem {
@@ -103,7 +104,7 @@ async function activate(
103104
app: JupyterFrontEnd,
104105
launcher: ILauncher,
105106
restorer: ILayoutRestorer,
106-
sessions: IRunningSessionManagers | null
107+
sessions: IRunningSessionManagers | null,
107108
): Promise<void> {
108109
// Fetch configured server processes from {base_url}/server-proxy/servers-info
109110
const response = await fetch(
@@ -175,12 +176,12 @@ async function activate(
175176
});
176177

177178
commands.addCommand(CommandIDs.open, {
178-
execute: args => {
179-
const model = args['sp'] as IServerProxyModel;
179+
execute: (args) => {
180+
const model = args["sp"] as IServerProxyModel;
180181
const url = PageConfig.getBaseUrl() + model.url;
181-
window.open(url, '_blank');
182+
window.open(url, "_blank");
182183
return;
183-
}
184+
},
184185
});
185186

186187
for (let server_process of data.server_processes) {
@@ -222,7 +223,7 @@ const extension: JupyterFrontEndPlugin<void> = {
222223
autoStart: true,
223224
requires: [ILauncher, ILayoutRestorer],
224225
optional: [IRunningSessionManagers],
225-
activate: activate
226+
activate: activate,
226227
};
227228

228229
export default extension;

0 commit comments

Comments
 (0)