Skip to content

Commit 9424e3f

Browse files
dependabot[bot]lresendepre-commit-ci[bot]
authored
Bump ruff from 0.0.270 to 0.0.290 (#1331)
Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Luciano Resende <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Luciano Resende <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent cdbe1ca commit 9424e3f

File tree

17 files changed

+90
-145
lines changed

17 files changed

+90
-145
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ repos:
3737
- id: black
3838

3939
- repo: https://github.com/charliermarsh/ruff-pre-commit
40-
rev: v0.0.270
40+
rev: v0.0.290
4141
hooks:
4242
- id: ruff
4343
args: ["--fix"]

enterprise_gateway/client/gateway_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ def interrupt(self):
237237
self.log.debug(f"Kernel {self.kernel_id} interrupted")
238238
return True
239239
else:
240-
msg = "Unexpected response interrupting kernel {}: {}".format(
241-
self.kernel_id, response.content
242-
)
240+
msg = f"Unexpected response interrupting kernel {self.kernel_id}: {response.content}"
243241
raise RuntimeError(msg)
244242

245243
def restart(self, timeout=REQUEST_TIMEOUT):

enterprise_gateway/enterprisegatewayapp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import sys
1313
import time
1414
import weakref
15-
from typing import List, Optional
15+
from typing import ClassVar, List, Optional
1616

1717
from jupyter_client.kernelspec import KernelSpecManager
1818
from jupyter_core.application import JupyterApp, base_aliases
@@ -78,7 +78,7 @@ class EnterpriseGatewayApp(EnterpriseGatewayConfigMixin, JupyterApp):
7878
"""
7979

8080
# Also include when generating help options
81-
classes = [
81+
classes: ClassVar = [
8282
KernelSpecCache,
8383
FileKernelSessionManager,
8484
WebhookKernelSessionManager,
@@ -369,7 +369,7 @@ def _signal_stop(self, sig, frame) -> None:
369369
self.io_loop.add_callback_from_signal(self.io_loop.stop)
370370

371371
_last_config_update = int(time.time())
372-
_dynamic_configurables = {}
372+
_dynamic_configurables: ClassVar = {}
373373

374374
def update_dynamic_configurables(self) -> bool:
375375
"""
@@ -403,7 +403,7 @@ def update_dynamic_configurables(self) -> bool:
403403

404404
self.log.info(
405405
"Configuration file changes detected. Instances for the following "
406-
"configurables have been updated: {}".format(configs)
406+
f"configurables have been updated: {configs}"
407407
)
408408
return updated
409409

enterprise_gateway/mixins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import traceback
1010
from distutils.util import strtobool
1111
from http.client import responses
12-
from typing import Any, Awaitable, Dict, List, Optional, Set
12+
from typing import Any, Awaitable, ClassVar, Dict, List, Optional, Set
1313

1414
from tornado import web
1515
from tornado.log import LogFormatter
@@ -36,7 +36,7 @@ class CORSMixin:
3636
Mixes CORS headers into tornado.web.RequestHandlers.
3737
"""
3838

39-
SETTINGS_TO_HEADERS = {
39+
SETTINGS_TO_HEADERS: ClassVar = {
4040
"eg_allow_credentials": "Access-Control-Allow-Credentials",
4141
"eg_allow_headers": "Access-Control-Allow-Headers",
4242
"eg_allow_methods": "Access-Control-Allow-Methods",

enterprise_gateway/services/kernels/remotemanager.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import signal
1111
import time
1212
import uuid
13-
from typing import Any
13+
from typing import Any, ClassVar
1414

1515
from jupyter_client.ioloop.manager import AsyncIOLoopKernelManager
1616
from jupyter_client.kernelspec import KernelSpec
@@ -136,7 +136,7 @@ class TrackPendingRequests:
136136
"""
137137

138138
_pending_requests_all = 0
139-
_pending_requests_user = {}
139+
_pending_requests_user: ClassVar = {}
140140

141141
def increment(self, username: str) -> None:
142142
"""Increment the requests for a username."""
@@ -570,9 +570,7 @@ async def _launch_kernel(
570570
del env["KG_AUTH_TOKEN"]
571571

572572
self.log.debug(
573-
"Launching kernel: '{}' with command: {}".format(
574-
self.kernel_spec.display_name, kernel_cmd
575-
)
573+
f"Launching kernel: '{self.kernel_spec.display_name}' with command: {kernel_cmd}"
576574
)
577575

578576
proxy = await self.process_proxy.launch_process(kernel_cmd, **kwargs)
@@ -660,7 +658,7 @@ async def signal_kernel(self, signum: int) -> None:
660658
if alt_sigint:
661659
try:
662660
sig_value = getattr(signal, alt_sigint)
663-
if type(sig_value) is int: # Python 2
661+
if isinstance(sig_value, int): # Python 2
664662
self.sigint_value = sig_value
665663
else: # Python 3
666664
self.sigint_value = sig_value.value

enterprise_gateway/services/kernelspecs/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def apply_user_filter(
2020
kernelspec_model: Dict[str, object],
2121
global_authorized_list: Set,
2222
global_unauthorized_list: Set,
23-
kernel_user: str = None,
23+
kernel_user: Optional[str] = None,
2424
) -> Optional[Dict[str, object]]:
2525
"""
2626
If authorization lists are configured - either within the kernelspec or globally, ensure

enterprise_gateway/services/kernelspecs/kernelspec_cache.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
import os
7-
from typing import Dict, Optional, Union
7+
from typing import ClassVar, Dict, Optional, Union
88

99
from jupyter_client.kernelspec import KernelSpec
1010
from jupyter_server.utils import ensure_async
@@ -105,11 +105,7 @@ def get_item(self, kernel_name: str) -> Optional[KernelSpec]:
105105
pass
106106
if not kernelspec:
107107
self.cache_misses += 1
108-
self.log.debug(
109-
"Cache miss ({misses}) for kernelspec: {kernel_name}".format(
110-
misses=self.cache_misses, kernel_name=kernel_name
111-
)
112-
)
108+
self.log.debug(f"Cache miss ({self.cache_misses}) for kernelspec: {kernel_name}")
113109
return kernelspec
114110

115111
def get_all_items(self) -> Dict[str, CacheItemType]:
@@ -147,11 +143,7 @@ def put_item(self, kernel_name: str, cache_item: Union[KernelSpec, CacheItemType
147143
observed_dir = os.path.dirname(resource_dir)
148144
if observed_dir not in self.observed_dirs:
149145
# New directory to watch, schedule it...
150-
self.log.debug(
151-
"KernelSpecCache: observing directory: {observed_dir}".format(
152-
observed_dir=observed_dir
153-
)
154-
)
146+
self.log.debug(f"KernelSpecCache: observing directory: {observed_dir}")
155147
self.observed_dirs.add(observed_dir)
156148
self.observer.schedule(KernelSpecChangeHandler(self), observed_dir, recursive=True)
157149

@@ -186,19 +178,15 @@ def _initialize(self):
186178
for kernel_dir in self.kernel_spec_manager.kernel_dirs:
187179
if kernel_dir not in self.observed_dirs:
188180
if os.path.exists(kernel_dir):
189-
self.log.info(
190-
"KernelSpecCache: observing directory: {kernel_dir}".format(
191-
kernel_dir=kernel_dir
192-
)
193-
)
181+
self.log.info(f"KernelSpecCache: observing directory: {kernel_dir}")
194182
self.observed_dirs.add(kernel_dir)
195183
self.observer.schedule(
196184
KernelSpecChangeHandler(self), kernel_dir, recursive=True
197185
)
198186
else:
199187
self.log.warning(
200-
"KernelSpecCache: kernel_dir '{kernel_dir}' does not exist"
201-
" and will not be observed.".format(kernel_dir=kernel_dir)
188+
f"KernelSpecCache: kernel_dir '{kernel_dir}' does not exist"
189+
" and will not be observed."
202190
)
203191
self.observer.start()
204192

@@ -223,7 +211,7 @@ class KernelSpecChangeHandler(FileSystemEventHandler):
223211
# Events related to these files trigger the management of the KernelSpec cache. Should we find
224212
# other files qualify as indicators of a kernel specification's state (like perhaps detached parameter
225213
# files in the future) should be added to this list - at which time it should become configurable.
226-
watched_files = ["kernel.json"]
214+
watched_files: ClassVar = ["kernel.json"]
227215

228216
def __init__(self, kernel_spec_cache: KernelSpecCache, **kwargs):
229217
"""Initialize the handler."""

enterprise_gateway/services/processproxies/conductor.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import subprocess
1414
import time
1515
from random import randint
16-
from typing import Any
16+
from typing import Any, ClassVar
1717

1818
from jupyter_client import localinterfaces
1919
from jupyter_server.utils import url_unescape
@@ -32,8 +32,8 @@ class ConductorClusterProcessProxy(RemoteProcessProxy):
3232
Kernel lifecycle management for Conductor clusters.
3333
"""
3434

35-
initial_states = {"SUBMITTED", "WAITING", "RUNNING"}
36-
final_states = {"FINISHED", "KILLED", "RECLAIMED"} # Don't include FAILED state
35+
initial_states: ClassVar = {"SUBMITTED", "WAITING", "RUNNING"}
36+
final_states: ClassVar = {"FINISHED", "KILLED", "RECLAIMED"} # Don't include FAILED state
3737

3838
def __init__(self, kernel_manager: RemoteKernelManager, proxy_config: dict):
3939
"""Initialize the proxy."""
@@ -227,9 +227,7 @@ def _update_notebook_master_rest_url(self, env_dict: dict) -> None:
227227

228228
if updated_one_notebook_master_rest_url and updated_one_notebook_master_web_submission_url:
229229
self.log.debug(
230-
"Updating KERNEL_NOTEBOOK_MASTER_REST to '{}'.".format(
231-
updated_one_notebook_master_rest_url
232-
)
230+
f"Updating KERNEL_NOTEBOOK_MASTER_REST to '{updated_one_notebook_master_rest_url}'."
233231
)
234232
os.environ["KERNEL_NOTEBOOK_MASTER_REST"] = updated_one_notebook_master_rest_url
235233
env_dict["KERNEL_NOTEBOOK_MASTER_REST"] = updated_one_notebook_master_rest_url
@@ -416,9 +414,7 @@ async def handle_timeout(self) -> None:
416414
)
417415

418416
if time_interval > self.kernel_launch_timeout:
419-
reason = "Application failed to start within {} seconds.".format(
420-
self.kernel_launch_timeout
421-
)
417+
reason = f"Application failed to start within {self.kernel_launch_timeout} seconds."
422418
error_http_code = 500
423419
if self._get_application_id(True):
424420
if self._query_app_state_by_driver_id(self.driver_id) != "WAITING":
@@ -435,9 +431,7 @@ async def handle_timeout(self) -> None:
435431
self.application_id, self.kernel_launch_timeout
436432
)
437433
await asyncio.get_event_loop().run_in_executor(None, self.kill)
438-
timeout_message = "KernelID: '{}' launch timeout due to: {}".format(
439-
self.kernel_id, reason
440-
)
434+
timeout_message = f"KernelID: '{self.kernel_id}' launch timeout due to: {reason}"
441435
self.log_and_raise(http_status_code=error_http_code, reason=timeout_message)
442436

443437
def _get_application_id(self, ignore_final_states: bool = False) -> str:
@@ -473,9 +467,7 @@ def _get_application_id(self, ignore_final_states: bool = False) -> str:
473467
)
474468
else:
475469
self.log.debug(
476-
"ApplicationID not yet assigned for KernelID: '{}' - retrying...".format(
477-
self.kernel_id
478-
)
470+
f"ApplicationID not yet assigned for KernelID: '{self.kernel_id}' - retrying..."
479471
)
480472
return self.application_id
481473

@@ -525,9 +517,7 @@ def _query_app_by_driver_id(self, driver_id: str) -> dict | None:
525517
response = None if not response or not response["applist"] else response["applist"]
526518
except Exception as e:
527519
self.log.warning(
528-
"Getting application with cmd '{}' failed with exception: '{}'. Continuing...".format(
529-
cmd, e
530-
)
520+
f"Getting application with cmd '{cmd}' failed with exception: '{e}'. Continuing..."
531521
)
532522
return response
533523

@@ -557,9 +547,7 @@ def _query_app_by_id(self, app_id: str) -> dict | None:
557547
response = None if response is None or not response["applist"] else response["applist"]
558548
except Exception as e:
559549
self.log.warning(
560-
"Getting application with cmd '{}' failed with exception: '{}'. Continuing...".format(
561-
cmd, e
562-
)
550+
f"Getting application with cmd '{cmd}' failed with exception: '{e}'. Continuing..."
563551
)
564552
return response
565553

enterprise_gateway/services/processproxies/container.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,13 @@ def _enforce_prohibited_ids(self, **kwargs: dict[str, Any] | None) -> None:
112112
if kernel_uid in prohibited_uids:
113113
http_status_code = 403
114114
error_message = (
115-
"Kernel's UID value of '{}' has been denied via EG_PROHIBITED_UIDS!".format(
116-
kernel_uid
117-
)
115+
f"Kernel's UID value of '{kernel_uid}' has been denied via EG_PROHIBITED_UIDS!"
118116
)
119117
self.log_and_raise(http_status_code=http_status_code, reason=error_message)
120118
elif kernel_gid in prohibited_gids:
121119
http_status_code = 403
122120
error_message = (
123-
"Kernel's GID value of '{}' has been denied via EG_PROHIBITED_GIDS!".format(
124-
kernel_gid
125-
)
121+
f"Kernel's GID value of '{kernel_gid}' has been denied via EG_PROHIBITED_GIDS!"
126122
)
127123
self.log_and_raise(http_status_code=http_status_code, reason=error_message)
128124

enterprise_gateway/services/processproxies/distributed.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import signal
1111
from socket import gethostbyname
1212
from subprocess import STDOUT
13-
from typing import Any
13+
from typing import Any, ClassVar
1414

1515
from ..kernels.remotemanager import RemoteKernelManager
1616
from .processproxy import BaseProcessProxyABC, RemoteProcessProxy
@@ -24,8 +24,8 @@
2424
class TrackKernelOnHost:
2525
"""A class for tracking a kernel on a host."""
2626

27-
_host_kernels = {}
28-
_kernel_host_mapping = {}
27+
_host_kernels: ClassVar = {}
28+
_kernel_host_mapping: ClassVar = {}
2929

3030
def add_kernel_id(self, host: str, kernel_id: str) -> None:
3131
"""Add a kernel to a host."""
@@ -229,9 +229,7 @@ async def handle_timeout(self) -> None:
229229
self.kernel_launch_timeout, self.assigned_host, self.kernel_log
230230
)
231231
)
232-
timeout_message = "KernelID: '{}' launch timeout due to: {}".format(
233-
self.kernel_id, reason
234-
)
232+
timeout_message = f"KernelID: '{self.kernel_id}' launch timeout due to: {reason}"
235233
await asyncio.get_event_loop().run_in_executor(None, self.kill)
236234
self.log_and_raise(http_status_code=500, reason=timeout_message)
237235

0 commit comments

Comments
 (0)