Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#1255)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Steven Silvester <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and blink1073 authored Apr 4, 2023
1 parent 3d4e162 commit cd8010e
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 28 deletions.
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.21.0
rev: 0.22.0
hooks:
- id: check-github-workflows

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

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

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.254
rev: v0.0.260
hooks:
- id: ruff
args: ["--fix"]
4 changes: 2 additions & 2 deletions jupyter_server/auth/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def set_password(args):
password1 = getpass("" if args.quiet else "Provide password: ")
password_repeat = getpass("" if args.quiet else "Repeat password: ")
if password1 != password_repeat:
warnings.warn("Passwords do not match, try again")
warnings.warn("Passwords do not match, try again", stacklevel=2)
elif len(password1) < 4: # noqa
warnings.warn("Please provide at least 4 characters")
warnings.warn("Please provide at least 4 characters", stacklevel=2)
else:
password = password1

Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/auth/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def is_token_authenticated(self, handler: JupyterHandler) -> bool:
- skip origin-checks for scripts
"""
# ensure get_user has been called, so we know if we're token-authenticated
handler.current_user
handler.current_user # noqa
return getattr(handler, "_token_authenticated", False)

def validate_security(
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def is_token_authenticated(cls, handler):
"""DEPRECATED in 2.0, use IdentityProvider API"""
if getattr(handler, "_user_id", None) is None:
# ensure get_user has been called, so we know if we're token-authenticated
handler.current_user
handler.current_user # noqa
return getattr(handler, "_token_authenticated", False)

@classmethod
Expand Down
6 changes: 4 additions & 2 deletions jupyter_server/auth/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def passwd(passphrase=None, algorithm="argon2"):
passphrase = p0
break
else:
warnings.warn("Passwords do not match.")
warnings.warn("Passwords do not match.", stacklevel=2)
else:
msg = "No matching passwords found. Giving up."
raise ValueError(msg)
Expand Down Expand Up @@ -161,7 +161,9 @@ def persist_config(config_file=None, mode=0o600):
os.chmod(config_file, mode)
except Exception:
tb = traceback.format_exc()
warnings.warn(f"Failed to set permissions on {config_file}:\n{tb}", RuntimeWarning)
warnings.warn(
f"Failed to set permissions on {config_file}:\n{tb}", RuntimeWarning, stacklevel=2
)


def set_password(password=None, config_file=None):
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@ def get_anonymous_username() -> str:
Get a random user-name based on the moons of Jupyter.
This function returns names like "Anonymous Io" or "Anonymous Metis".
"""
return moons_of_jupyter[random.randint(0, len(moons_of_jupyter) - 1)]
return moons_of_jupyter[random.randint(0, len(moons_of_jupyter) - 1)] # noqa
8 changes: 5 additions & 3 deletions jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def authorizer(self):
"https://github.com/jupyter-server/jupyter_server/blob/"
"653740cbad7ce0c8a8752ce83e4d3c2c754b13cb/jupyter_server/serverapp.py"
"#L234-L256",
stacklevel=2,
)
from jupyter_server.auth import AllowAllAuthorizer

Expand All @@ -245,6 +246,7 @@ def identity_provider(self):
"add an identity provider to the tornado settings: "
"https://github.com/jupyter-server/jupyter_server/blob/v2.0.0/"
"jupyter_server/serverapp.py#L242",
stacklevel=2,
)
from jupyter_server.auth import IdentityProvider

Expand Down Expand Up @@ -594,10 +596,10 @@ async def prepare(self):
# check for overridden get_current_user + default IdentityProvider
# deprecated way to override auth (e.g. JupyterHub < 3.0)
# allow deprecated, overridden get_current_user
warnings.warn(
warnings.warn( # noqa
"Overriding JupyterHandler.get_current_user is deprecated in jupyter-server 2.0."
" Use an IdentityProvider class.",
DeprecationWarning,
DeprecationWarning
# stacklevel not useful here
)
user = self.get_current_user()
Expand Down Expand Up @@ -984,7 +986,7 @@ def get_absolute_path(cls, roots, path):

def validate_absolute_path(self, root, absolute_path):
"""check if the file should be served (raises 404, 403, etc.)"""
if absolute_path == "":
if not absolute_path:
raise web.HTTPError(404)

for root in self.root:
Expand Down
1 change: 1 addition & 0 deletions jupyter_server/extension/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def get_loader(obj, logger=None):
"name will be deprecated in future releases "
"of Jupyter Server.".format(name=obj),
DeprecationWarning,
stacklevel=2,
)
return func

Expand Down
4 changes: 2 additions & 2 deletions jupyter_server/gateway/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from .managers import GatewayClient

# Keepalive ping interval (default: 30 seconds)
GATEWAY_WS_PING_INTERVAL_SECS = int(os.getenv("GATEWAY_WS_PING_INTERVAL_SECS", 30))
GATEWAY_WS_PING_INTERVAL_SECS = int(os.getenv("GATEWAY_WS_PING_INTERVAL_SECS", "30"))


class WebSocketChannelsHandler(WebSocketHandler, JupyterHandler):
Expand Down Expand Up @@ -229,7 +229,7 @@ async def _read_messages(self, callback):

# NOTE(esevan): if websocket is not disconnected by client, try to reconnect.
if not self.disconnected and self.retry < GatewayClient.instance().gateway_retry_max:
jitter = random.randint(10, 100) * 0.01
jitter = random.randint(10, 100) * 0.01 # noqa
retry_interval = (
min(
GatewayClient.instance().gateway_retry_interval * (2**self.retry),
Expand Down
6 changes: 3 additions & 3 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def random_ports(port, n):
for i in range(min(5, n)):
yield port + i
for _ in range(n - 5):
yield max(1, port + random.randint(-2 * n, 2 * n))
yield max(1, port + random.randint(-2 * n, 2 * n)) # noqa


def load_handlers(name):
Expand Down Expand Up @@ -1239,7 +1239,7 @@ def _default_allow_remote(self):

# if blank, self.ip was configured to "*" meaning bind to all interfaces,
# see _valdate_ip
if self.ip == "":
if self.ip == "": # noqa
return True

try:
Expand Down Expand Up @@ -1879,7 +1879,7 @@ def init_configurables(self):
)
# Trigger a default/validation here explicitly while we still support the
# deprecated trait on ServerApp (FIXME remove when deprecation finalized)
self.contents_manager.preferred_dir
self.contents_manager.preferred_dir # noqa
self.session_manager = self.session_manager_class(
parent=self,
log=self.log,
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/kernels/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def select_subprotocol(self, subprotocols):
preferred_protocol = self.connection.kernel_ws_protocol
if preferred_protocol is None:
preferred_protocol = "v1.kernel.websocket.jupyter.org"
elif preferred_protocol == "":
elif preferred_protocol == "": # noqa
preferred_protocol = None
selected_subprotocol = preferred_protocol if preferred_protocol in subprotocols else None
# None is the default, "legacy" protocol
Expand Down
6 changes: 3 additions & 3 deletions jupyter_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def path2url(path):
"""Convert a local file path to a URL"""
pieces = [quote(p) for p in path.split(os.sep)]
# preserve trailing /
if pieces[-1] == "":
if pieces[-1] == "": # noqa
pieces[-1] = "/"
url = url_path_join(*pieces)
return url
Expand Down Expand Up @@ -121,7 +121,7 @@ def to_os_path(path: ApiPath, root: str = "") -> str:
root must be a filesystem path already.
"""
parts = str(path).strip("/").split("/")
parts = [p for p in parts if p != ""] # remove duplicate splits
parts = [p for p in parts if p != ""] # noqa # remove duplicate splits
path_ = os.path.join(root, *parts)
return os.path.normpath(path_)

Expand All @@ -135,7 +135,7 @@ def to_api_path(os_path: str, root: str = "") -> ApiPath:
if os_path.startswith(root):
os_path = os_path[len(root) :]
parts = os_path.strip(os.path.sep).split(os.path.sep)
parts = [p for p in parts if p != ""] # remove duplicate splits
parts = [p for p in parts if p != ""] # noqa # remove duplicate splits
path = "/".join(parts)
return ApiPath(path)

Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ integration = "test --integration_tests=true {args}"
[tool.hatch.envs.lint]
detached = true
dependencies = [
"black[jupyter]==23.1.0",
"black[jupyter]==23.3.0",
"mdformat>0.7",
"ruff==0.0.254",
"ruff==0.0.260",
]
[tool.hatch.envs.lint.scripts]
style = [
Expand Down Expand Up @@ -243,7 +243,8 @@ unfixable = [
# EM101 Exception must not use a string literal
# PLR2004 Magic value used in comparison
# S108 Probable insecure usage of temporary file or directory
"tests/*" = ["B011", "F841", "C408", "E402", "T201", "EM101", "EM102", "EM103", "PLR2004", "S108"]
# PLC1901 `ext_pkg.version == ""` can be simplified to `not ext_pkg.version` as an empty string is falsey
"tests/*" = ["B011", "F841", "C408", "E402", "T201", "EM101", "EM102", "EM103", "PLR2004", "S108", "PLC1901"]
# Ignore flake 8 errors from shimmed imports
"jupyter_server/base/zmqhandlers.py" = ["F401"]
# PLR2004 Magic value used in comparison
Expand Down
2 changes: 1 addition & 1 deletion tests/auth/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async def test_logout(jp_serverapp, login, http_server_client, jp_base_url):
assert resp.code == 200
cookie_header = resp.headers["Set-Cookie"]
cookies = parse_cookie(cookie_header)
assert cookies.get("test-cookie") == ""
assert not cookies.get("test-cookie")
assert "Successfully logged out" in resp.body.decode("utf8")


Expand Down
2 changes: 1 addition & 1 deletion tests/extension/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_extension_package_api():
app = path1["app"]

e = ExtensionPackage(name="tests.extension.mockextensions", enabled=True)
e.extension_points
e.extension_points # noqa
assert hasattr(e, "extension_points")
assert len(e.extension_points) == len(metadata_list)
assert app.name in e.extension_points
Expand Down
2 changes: 1 addition & 1 deletion tests/test_serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_server_info_file(tmp_path, jp_configurable_serverapp):
app.remove_server_info_file()

assert list(list_running_servers(app.runtime_dir)) == []
app.remove_server_info_file
app.remove_server_info_file()


def test_root_dir(tmp_path, jp_configurable_serverapp):
Expand Down

0 comments on commit cd8010e

Please sign in to comment.