Skip to content

[pre-commit.ci] pre-commit autoupdate (#1205)Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Steven Silvester <[email protected]> #1205

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

Merged
merged 7 commits into from
Feb 7, 2023
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.2
rev: 0.21.0
hooks:
- id: check-github-workflows

Expand All @@ -30,12 +30,12 @@ repos:
- id: mdformat

- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.1.0
hooks:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.236
rev: v0.0.242
hooks:
- id: ruff
args: ["--fix"]
2 changes: 1 addition & 1 deletion examples/identity/system_password/jupyter_server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ def process_login_form(self, handler):
return User(username=username, name=user_info.pw_gecos or username)


c = get_config() # type: ignore # noqa
c = get_config() # type: ignore

c.ServerApp.identity_provider_class = SystemPasswordIdentityProvider
2 changes: 1 addition & 1 deletion jupyter_server/_tz.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def dst(self, d):
return ZERO


UTC = tzUTC()
UTC = tzUTC() # type:ignore


def utc_aware(unaware):
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ def write_error(self, status_code, **kwargs):
try:
message = exception.log_message % exception.args
except Exception:
pass
pass # noqa

# construct the custom reason, if defined
reason = getattr(exception, "reason", "")
Expand Down
4 changes: 2 additions & 2 deletions jupyter_server/extension/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def _default_serverapp(self):
return ServerApp.instance()
except Exception:
# error retrieving instance, e.g. MultipleInstanceError
pass
pass # noqa

# serverapp accessed before it was defined,
# declare an empty one
Expand Down Expand Up @@ -588,7 +588,7 @@ def launch_instance(cls, argv=None, **kwargs):
extension's landing page.
"""
# Handle arguments.
if argv is None:
if argv is None: # noqa
args = sys.argv[1:] # slice out extension config.
else:
args = argv
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/extension/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def static_url(self, path, include_host=None, **kwargs):
if include_host is None:
include_host = getattr(self, "include_host", False)

if include_host:
if include_host: # noqa
base = self.request.protocol + "://" + self.request.host # type:ignore[attr-defined]
else:
base = ""
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/gateway/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ async def kernel_culled(self, kernel_id: str) -> bool: # typing: ignore
# notification model, this will need to be revisited.
km = self.kernel_manager.get_kernel(kernel_id)
except Exception: # Let exceptions here reflect culled kernel
pass
pass # noqa
return km is None


Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/nbconvert/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_exporter(format, **kwargs):
"""get an exporter, raising appropriate errors"""
# if this fails, will raise 500
try:
from nbconvert.exporters.base import get_exporter # type:ignore
from nbconvert.exporters.base import get_exporter
except ImportError as e:
raise web.HTTPError(500, "Could not import nbconvert: %s" % e) from e

Expand Down
1 change: 0 additions & 1 deletion jupyter_server/prometheus/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
)

except ImportError:

from prometheus_client import Gauge, Histogram

HTTP_REQUEST_DURATION_SECONDS = Histogram(
Expand Down
3 changes: 1 addition & 2 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,6 @@ def _deprecated_rate_limit_window(self, change):

@default("terminals_enabled")
def _default_terminals_enabled(self):

return True

authenticate_prometheus = Bool(
Expand Down Expand Up @@ -2729,7 +2728,7 @@ def _prepare_browser_open(self):
if self.identity_provider.token:
uri = url_concat(uri, {"token": self.identity_provider.token})

if self.file_to_run:
if self.file_to_run: # noqa
# Create a separate, temporary open-browser-file
# pointing at a specific file.
open_file = self.browser_open_file_to_run
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/contents/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _validate_preferred_dir(self, proposal):
if value != self.parent.preferred_dir:
self.parent.preferred_dir = os.path.join(self.root_dir, *value.split("/"))
except (AttributeError, TraitError):
pass
pass # noqa
return value

allow_hidden = Bool(False, config=True, help="Allow access to hidden files")
Expand Down
3 changes: 0 additions & 3 deletions jupyter_server/services/kernels/connection/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Kernel connection helpers."""
import json
import struct
import sys

from jupyter_client.session import Session
from tornado.websocket import WebSocketHandler
Expand Down Expand Up @@ -36,8 +35,6 @@ def serialize_binary_message(msg):
# don't modify msg or buffer list in-place
msg = msg.copy()
buffers = list(msg.pop("buffers"))
if sys.version_info < (3, 4):
buffers = [x.tobytes() for x in buffers]
bmsg = json.dumps(msg, default=json_default).encode("utf8")
buffers.insert(0, bmsg)
nbufs = len(buffers)
Expand Down
6 changes: 3 additions & 3 deletions jupyter_server/services/kernels/connection/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def create_stream(self):
self.channels[channel] = stream = meth(identity=identity)
stream.channel = channel

def nudge(self):
def nudge(self): # noqa
"""Nudge the zmq connections with kernel_info_requests
Returns a Future that will resolve when we have received
a shell or control reply and at least one iopub message,
Expand Down Expand Up @@ -444,7 +444,7 @@ def disconnect(self):
ZMQChannelsWebsocketConnection._open_sockets.remove(self)
self._close_future.set_result(None)
except Exception:
pass
pass # noqa

def handle_incoming_message(self, incoming_msg: str) -> None:
"""Handle incoming messages from Websocket to ZMQ Sockets."""
Expand Down Expand Up @@ -657,7 +657,7 @@ def write_stderr(self, error_message, parent_header):
err_msg["channel"] = "iopub"
self.write_message(json.dumps(err_msg, default=json_default))

def _limit_rate(self, channel, msg, msg_list):
def _limit_rate(self, channel, msg, msg_list): # noqa
"""Limit the message rate on a channel."""
if not (self.limit_rate and channel == "iopub"):
return False
Expand Down
1 change: 0 additions & 1 deletion jupyter_server/services/kernels/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ async def post(self, kernel_id, action):
await ensure_async(km.interrupt_kernel(kernel_id))
self.set_status(204)
if action == "restart":

try:
await km.restart_kernel(kernel_id)
except Exception as e:
Expand Down
3 changes: 2 additions & 1 deletion jupyter_server/services/kernels/kernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ def list_kernels(self):
model = self.kernel_model(kernel_id)
kernels.append(model)
except (web.HTTPError, KeyError):
pass # Probably due to a (now) non-existent kernel, continue building the list
# Probably due to a (now) non-existent kernel, continue building the list
pass # noqa
return kernels

# override _check_kernel_id to raise 404 instead of KeyError
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/sessions/sessionmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def _validate_database_filepath(self, proposal):
with open(value, "rb") as f:
header = f.read(100)

if not header.startswith(b"SQLite format 3") and header != b"": # noqa
if not header.startswith(b"SQLite format 3") and header != b"":
msg = "The given file is not an SQLite database file."
raise TraitError(msg)
return value
Expand Down
6 changes: 3 additions & 3 deletions jupyter_server/traittypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def validate(self, obj, value):
if self.subclass_from_klasses(value):
return value
except Exception:
pass
pass # noqa

self.error(obj, value)

Expand Down Expand Up @@ -109,7 +109,7 @@ def _resolve_classes(self):
klass = self._resolve_string(klass)
self.importable_klasses.append(klass)
except Exception:
pass
pass # noqa
else:
self.importable_klasses.append(klass)

Expand Down Expand Up @@ -221,7 +221,7 @@ def _resolve_classes(self):
klass = self._resolve_string(klass)
self.importable_klasses.append(klass)
except Exception:
pass
pass # noqa
else:
self.importable_klasses.append(klass)

Expand Down
4 changes: 3 additions & 1 deletion jupyter_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ def is_namespace_package(namespace):
# NOTE: using submodule_search_locations because the loader can be None
try:
spec = importlib.util.find_spec(namespace)
except ValueError: # spec is not set - see https://docs.python.org/3/library/importlib.html#importlib.util.find_spec
except (
ValueError
): # spec is not set - see https://docs.python.org/3/library/importlib.html#importlib.util.find_spec
return None

if not spec:
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ integration = "test --integration_tests=true {args}"
[tool.hatch.envs.lint]
detached = true
dependencies = [
"black[jupyter]==22.12.0",
"black[jupyter]==23.1.0",
"mdformat>0.7",
"ruff==0.0.236",
"ruff==0.0.242",
]
[tool.hatch.envs.lint.scripts]
style = [
Expand Down Expand Up @@ -217,6 +217,10 @@ ignore = [
"N818",
# SIM105 Use `contextlib.suppress(...)`
"SIM105",
# PLR0913 Too many arguments to function call
"PLR0913",
# PLR0912 Too many branches
"PLR0912",
]
unfixable = [
# Don't touch print statements
Expand Down
1 change: 0 additions & 1 deletion tests/auth/test_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ async def test_auth_disabled(request, jp_serverapp, jp_fetch):
assert not idp.auth_enabled

with mock.patch.dict(jp_serverapp.web_app.settings, {"identity_provider": idp}):

resp = await jp_fetch("/api/me", headers={"Authorization": "", "Cookie": ""})

user_info = json.loads(resp.body.decode("utf8"))
Expand Down
1 change: 0 additions & 1 deletion tests/extension/mockextensions/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def get(self):


class MockExtensionApp(ExtensionAppJinjaMixin, ExtensionApp):

name = "mockextension"
template_paths = List().tag(config=True)
static_paths = [STATIC_PATH]
Expand Down
2 changes: 0 additions & 2 deletions tests/services/contents/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,6 @@ async def test_copy_400_hidden(
contents,
contents_dir,
):

# Create text files
hidden_dir = contents_dir / ".hidden"
hidden_dir.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -795,7 +794,6 @@ async def test_rename_400_hidden(jp_fetch, jp_base_url, contents, contents_dir):


async def test_checkpoints_follow_file(jp_fetch, contents):

path = "foo"
name = "a.ipynb"

Expand Down
1 change: 0 additions & 1 deletion tests/services/contents/test_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def handle_umask():

@pytest.mark.skipif(sys.platform.startswith("win"), reason="Windows")
def test_atomic_writing_umask(handle_umask, tmp_path):

os.umask(0o022)
f1 = str(tmp_path / "1")
with atomic_writing(f1) as f:
Expand Down
4 changes: 2 additions & 2 deletions tests/services/contents/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ async def test_403(jp_file_contents_manager_class, tmp_path):


@pytest.mark.skipif(sys.platform.startswith("win"), reason="Can't test hidden files on Windows")
async def test_400(jp_file_contents_manager_class, tmp_path):
async def test_400(jp_file_contents_manager_class, tmp_path): # noqa
# Test Delete behavior
# Test delete of file in hidden directory
td = str(tmp_path)
Expand Down Expand Up @@ -503,7 +503,7 @@ async def test_modified_date(jp_contents_manager):
assert renamed["last_modified"] >= saved["last_modified"]


async def test_get(jp_contents_manager):
async def test_get(jp_contents_manager): # noqa
cm = jp_contents_manager
# Create a notebook
model = await ensure_async(cm.new_untitled(type="notebook"))
Expand Down
5 changes: 2 additions & 3 deletions tests/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def generate_model(name):
return model


async def mock_gateway_request(url, **kwargs):
async def mock_gateway_request(url, **kwargs): # noqa
method = "GET"
if kwargs["method"]:
method = kwargs["method"]
Expand Down Expand Up @@ -197,7 +197,6 @@ def helper(*args, **kwargs):


class CustomTestTokenRenewer(GatewayTokenRenewerBase): # type:ignore[misc]

TEST_EXPECTED_TOKEN_VALUE = "Use this token value: 42"

# The following are configured by the config test to ensure they flow
Expand Down Expand Up @@ -342,7 +341,7 @@ def test_gateway_request_timeout_pad_option(
GatewayClient.instance().init_connection_args()

assert app.gateway_config.request_timeout == expected_request_timeout
assert GatewayClient.instance().KERNEL_LAUNCH_TIMEOUT == expected_kernel_launch_timeout
assert expected_kernel_launch_timeout == GatewayClient.instance().KERNEL_LAUNCH_TIMEOUT

GatewayClient.clear_instance()

Expand Down
1 change: 0 additions & 1 deletion tests/test_traittypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class DummyInt(int):


class Thing(HasTraits):

a = InstanceFromClasses(
default_value=2,
klasses=[
Expand Down
1 change: 0 additions & 1 deletion tests/unix_sockets/test_serverapp_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ def test_shutdown_server(jp_environ):

@pytest.mark.integration_test
def test_jupyter_server_apps(jp_environ):

# Start a server in another process
# Stop that server
import subprocess
Expand Down