Skip to content

Commit 949085e

Browse files
authored
Update ruff config (#429)
* Update ruff config * fix import
1 parent f9a651d commit 949085e

23 files changed

+113
-126
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
- id: trailing-whitespace
2222

2323
- repo: https://github.com/python-jsonschema/check-jsonschema
24-
rev: 0.27.2
24+
rev: 0.27.3
2525
hooks:
2626
- id: check-github-workflows
2727

@@ -77,7 +77,7 @@ repos:
7777
]
7878

7979
- repo: https://github.com/astral-sh/ruff-pre-commit
80-
rev: v0.1.6
80+
rev: v0.1.7
8181
hooks:
8282
- id: ruff
8383
types_or: [python, jupyter]

docs/source/conf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
HERE = osp.abspath(osp.dirname(__file__))
2424
sys.path.insert(0, osp.join(HERE, "..", ".."))
2525

26-
from jupyterlab_server import LabServerApp, _version # noqa
26+
from jupyterlab_server import LabServerApp, _version # noqa: E402
2727

2828
# -- Project information -----------------------------------------------------
2929

3030
project = "JupyterLab Server"
31-
copyright = "2021, Project Jupyter" # noqa
31+
copyright = "2021, Project Jupyter"
3232
author = "Project Jupyter"
3333

3434
# The short X.Y version.
@@ -53,7 +53,7 @@
5353
]
5454

5555
try:
56-
import enchant # type:ignore # noqa
56+
import enchant # noqa: F401
5757

5858
extensions += ["sphinxcontrib.spelling"]
5959
except ImportError:
@@ -131,7 +131,7 @@
131131
"""
132132

133133

134-
def setup(app):
134+
def setup(app): # noqa: ARG001
135135
dest = osp.join(HERE, "changelog.md")
136136
shutil.copy(osp.join(HERE, "..", "..", "CHANGELOG.md"), dest)
137137
destination = osp.join(HERE, "api/app-config.rst")

jupyterlab_server/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .app import LabServerApp
77
from .handlers import LabConfig, LabHandler, add_handlers
88
from .licenses_app import LicensesApp
9-
from .spec import get_openapi_spec, get_openapi_spec_dict # noqa
9+
from .spec import get_openapi_spec, get_openapi_spec_dict # noqa: F401
1010
from .translation_utils import translator
1111
from .workspaces_app import WorkspaceExportApp, WorkspaceImportApp, WorkspaceListApp
1212
from .workspaces_handler import WORKSPACE_EXTENSION, slugify

jupyterlab_server/app.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,14 @@ def _deprecated_trait(self, change: Any) -> None:
9393
# protects backward-compatible config from warnings
9494
# if they set the same value under both names
9595
self.log.warning(
96-
"{cls}.{old} is deprecated in JupyterLab {version}, use {cls}.{new} instead".format(
97-
cls=self.__class__.__name__,
98-
old=old_attr,
99-
new=new_attr,
100-
version=version,
101-
)
96+
"%s.%s is deprecated in JupyterLab %s, use %s.%s instead",
97+
self.__class__.__name__,
98+
old_attr,
99+
version,
100+
self.__class__.__name__,
101+
new_attr,
102102
)
103+
103104
setattr(self, new_attr, change.new)
104105

105106
def initialize_settings(self) -> None:

jupyterlab_server/config.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ def get_federated_extensions(labextensions_path: list[str]) -> dict[str, Any]:
7474

7575

7676
def get_static_page_config(
77-
app_settings_dir: str | None = None, logger: Logger | None = None, level: str = "all"
77+
app_settings_dir: str | None = None, # noqa: ARG001
78+
logger: Logger | None = None, # noqa: ARG001
79+
level: str = "all",
7880
) -> dict[str, Any]:
7981
"""Get the static page config for JupyterLab
8082
@@ -105,11 +107,10 @@ def load_config(path: str) -> Any:
105107
with open(path, encoding="utf-8") as fid:
106108
if path.endswith(".json5"):
107109
return json5.load(fid)
108-
else:
109-
return json.load(fid)
110+
return json.load(fid)
110111

111112

112-
def get_page_config( # noqa: PLR0915
113+
def get_page_config(
113114
labextensions_path: list[str], app_settings_dir: str | None = None, logger: Logger | None = None
114115
) -> dict[str, Any]:
115116
"""Get the page config for the application handler"""
@@ -151,7 +152,7 @@ def get_page_config( # noqa: PLR0915
151152
for _, ext_data in federated_exts.items():
152153
if "_build" not in ext_data["jupyterlab"]:
153154
if logger:
154-
logger.warning("%s is not a valid extension" % ext_data["name"])
155+
logger.warning("%s is not a valid extension", ext_data["name"])
155156
continue
156157
extbuild = ext_data["jupyterlab"]["_build"]
157158
extension = {"name": ext_data["name"], "load": extbuild["load"]}

jupyterlab_server/handlers.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def is_url(url: str) -> bool:
6666
class LabHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler):
6767
"""Render the JupyterLab View."""
6868

69-
@lru_cache() # noqa
69+
@lru_cache # noqa: B019
7070
def get_page_config(self) -> dict[str, Any]:
7171
"""Construct the page config object"""
7272
self.application.store_id = getattr( # type:ignore[attr-defined]
@@ -105,7 +105,7 @@ def get_page_config(self) -> dict[str, Any]:
105105
.relative_to(server_root)
106106
.as_posix()
107107
)
108-
except Exception: # noqa S110
108+
except Exception: # noqa: S110
109109
pass
110110
# JupyterLab relies on an unset/default path being "/"
111111
page_config["preferredPath"] = preferred_path or "/"
@@ -176,15 +176,15 @@ def get(
176176
class NotFoundHandler(LabHandler):
177177
"""A handler for page not found."""
178178

179-
@lru_cache() # noqa
179+
@lru_cache # noqa: B019
180180
def get_page_config(self) -> dict[str, Any]:
181181
"""Get the page config."""
182182
page_config = super().get_page_config()
183183
page_config["notFoundUrl"] = self.request.path
184184
return page_config
185185

186186

187-
def add_handlers(handlers: list[Any], extension_app: LabServerApp) -> None: # noqa
187+
def add_handlers(handlers: list[Any], extension_app: LabServerApp) -> None:
188188
"""Add the appropriate handlers to the web app."""
189189
# Normalize directories.
190190
for name in LabConfig.class_trait_names():
@@ -272,8 +272,9 @@ def add_handlers(handlers: list[Any], extension_app: LabServerApp) -> None: # n
272272
allowed_extensions_uris: str = settings_config.get("allowed_extensions_uris", "")
273273

274274
if (blocked_extensions_uris) and (allowed_extensions_uris):
275-
warnings.warn( # noqa B028
276-
"Simultaneous blocked_extensions_uris and allowed_extensions_uris is not supported. Please define only one of those."
275+
warnings.warn(
276+
"Simultaneous blocked_extensions_uris and allowed_extensions_uris is not supported. Please define only one of those.",
277+
stacklevel=2,
277278
)
278279
import sys
279280

@@ -339,7 +340,7 @@ def add_handlers(handlers: list[Any], extension_app: LabServerApp) -> None: # n
339340
handlers.append((fallthrough_url, NotFoundHandler))
340341

341342

342-
def _camelCase(base: str) -> str: # noqa
343+
def _camelCase(base: str) -> str:
343344
"""Convert a string to camelCase.
344345
https://stackoverflow.com/a/20744956
345346
"""

jupyterlab_server/licenses_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ def report(self, report_format: str, bundles_pattern: str, full_text: bool) -> t
8787
bundles = self.bundles(bundles_pattern=bundles_pattern)
8888
if report_format == "json":
8989
return self.report_json(bundles), "application/json"
90-
elif report_format == "csv":
90+
if report_format == "csv":
9191
return self.report_csv(bundles), "text/csv"
92-
elif report_format == "markdown":
92+
if report_format == "markdown":
9393
return (
9494
self.report_markdown(bundles, full_text=full_text),
9595
"text/markdown",

jupyterlab_server/listings_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def fetch_listings(logger: Logger | None) -> None:
2525
blocked_extensions = []
2626
for blocked_extensions_uri in ListingsHandler.blocked_extensions_uris:
2727
logger.info(
28-
f"Fetching blocked_extensions from {ListingsHandler.blocked_extensions_uris}"
28+
"Fetching blocked_extensions from %s", ListingsHandler.blocked_extensions_uris
2929
)
3030
r = requests.request(
3131
"GET", blocked_extensions_uri, **ListingsHandler.listings_request_opts
@@ -38,7 +38,7 @@ def fetch_listings(logger: Logger | None) -> None:
3838
allowed_extensions = []
3939
for allowed_extensions_uri in ListingsHandler.allowed_extensions_uris:
4040
logger.info(
41-
f"Fetching allowed_extensions from {ListingsHandler.allowed_extensions_uris}"
41+
"Fetching allowed_extensions from %s", ListingsHandler.allowed_extensions_uris
4242
)
4343
r = requests.request(
4444
"GET", allowed_extensions_uri, **ListingsHandler.listings_request_opts

jupyterlab_server/process.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(
106106
self.logger = logger or self.get_log()
107107
self._last_line = ""
108108
if not quiet:
109-
self.logger.info(f"> {list2cmdline(cmd)}")
109+
self.logger.info("> %s", list2cmdline(cmd))
110110
self.cmd = cmd
111111

112112
kwargs = {}
@@ -130,7 +130,7 @@ def terminate(self) -> int:
130130
try:
131131
proc.wait(timeout=2.0)
132132
except subprocess.TimeoutExpired:
133-
if os.name == "nt": # noqa
133+
if os.name == "nt": # noqa: SIM108
134134
sig = signal.SIGBREAK # type:ignore[attr-defined]
135135
else:
136136
sig = signal.SIGKILL
@@ -185,8 +185,7 @@ def _create_process(self, **kwargs: Any) -> subprocess.Popen[str]:
185185
if os.name == "nt":
186186
kwargs["shell"] = True
187187

188-
proc = subprocess.Popen(cmd, **kwargs) # noqa
189-
return proc
188+
return subprocess.Popen(cmd, **kwargs) # noqa: S603
190189

191190
@classmethod
192191
def _cleanup(cls: type[Process]) -> None:
@@ -278,10 +277,10 @@ def _read_incoming(self) -> None:
278277
buf = os.read(fileno, 1024)
279278
except OSError as e:
280279
self.logger.debug("Read incoming error %s", e)
281-
return None
280+
return
282281

283282
if not buf:
284-
return None
283+
return
285284

286285
print(buf.decode("utf-8"), end="")
287286

jupyterlab_server/pytest_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def make_labserver_extension_app(
4949
) -> Callable[..., LabServerApp]:
5050
"""Return a factory function for a labserver extension app."""
5151

52-
def _make_labserver_extension_app(**kwargs: Any) -> LabServerApp:
52+
def _make_labserver_extension_app(**kwargs: Any) -> LabServerApp: # noqa: ARG001
5353
"""Factory function for lab server extension apps."""
5454
return LabServerApp(
5555
static_dir=str(jp_root_dir),

0 commit comments

Comments
 (0)