Skip to content

Commit

Permalink
sync deps and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Sep 5, 2023
1 parent e7ba99e commit d15419b
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 21 deletions.
3 changes: 1 addition & 2 deletions jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,7 @@ def set_attachment_header(self, filename):
escaped_filename = url_escape(filename)
self.set_header(
"Content-Disposition",
"attachment;"
f" filename*=utf-8''{escaped_filename}",
f"attachment; filename*=utf-8''{escaped_filename}",
)

def get_origin(self):
Expand Down
3 changes: 1 addition & 2 deletions jupyter_server/extension/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,7 @@ def launch_instance(cls, argv=None, **kwargs):
# Log if extension is blocking other extensions from loading.
if not cls.load_other_extensions:
serverapp.log.info(
f"{cls.name} is running without loading "
"other extensions."
f"{cls.name} is running without loading other extensions."
)
# Start the server.
try:
Expand Down
8 changes: 4 additions & 4 deletions jupyter_server/gateway/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ async def get_kernel_spec(self, kernel_name, **kwargs):
try:
response = await gateway_request(kernel_spec_url, method="GET")
except web.HTTPError as error:
if error.status_code == 404: # noqa[PLR2004]
if error.status_code == 404: # noqa: PLR2004
# Convert not found to KeyError since that's what the Notebook handler expects
# message is not used, but might as well make it useful for troubleshooting
msg = f"kernelspec {kernel_name} not found on Gateway server at: {GatewayClient.instance().url}"
Expand Down Expand Up @@ -336,7 +336,7 @@ async def get_kernel_spec_resource(self, kernel_name, path):
try:
response = await gateway_request(kernel_spec_resource_url, method="GET")
except web.HTTPError as error:
if error.status_code == 404: # noqa[PLR2004]
if error.status_code == 404: # noqa: PLR2004
kernel_spec_resource = None
else:
raise
Expand Down Expand Up @@ -433,7 +433,7 @@ async def refresh_model(self, model=None):
response = await gateway_request(self.kernel_url, method="GET")

except web.HTTPError as error:
if error.status_code == 404: # noqa[PLR2004]
if error.status_code == 404: # noqa: PLR2004
self.log.warning("Kernel not found at: %s" % self.kernel_url)
model = None
else:
Expand Down Expand Up @@ -527,7 +527,7 @@ async def shutdown_kernel(self, now=False, restart=False):
response = await gateway_request(self.kernel_url, method="DELETE")
self.log.debug("Shutdown kernel response: %d %s", response.code, response.reason)
except web.HTTPError as error:
if error.status_code == 404: # noqa[PLR2004]
if error.status_code == 404: # noqa: PLR2004
self.log.debug("Shutdown kernel response: kernel not found (ignored)")
else:
raise
Expand Down
10 changes: 5 additions & 5 deletions jupyter_server/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ def log_request(handler):
except AttributeError:
logger = access_log

if status < 300 or status == 304: # noqa[PLR2004]
if status < 300 or status == 304: # noqa: PLR2004
# Successes (or 304 FOUND) are debug-level
log_method = logger.debug
elif status < 400: # noqa[PLR2004]
elif status < 400: # noqa: PLR2004
log_method = logger.info
elif status < 500: # noqa[PLR2004]
elif status < 500: # noqa: PLR2004
log_method = logger.warning
else:
log_method = logger.error
Expand All @@ -84,11 +84,11 @@ def log_request(handler):
ns["username"] = username

msg = "{status} {method} {uri} ({username}@{ip}) {request_time:.2f}ms"
if status >= 400: # noqa[PLR2004]
if status >= 400: # noqa: PLR2004
# log bad referers
ns["referer"] = _scrub_uri(request.headers.get("Referer", "None"))
msg = msg + " referer={referer}"
if status >= 500 and status != 502: # noqa[PLR2004]
if status >= 500 and status != 502: # noqa: PLR2004
# Log a subset of the headers if it caused an error.
headers = {}
for header in ["Host", "Accept", "Referer", "User-Agent"]:
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def init_settings(
jenv_opt: dict = {"autoescape": True}
jenv_opt.update(jinja_env_options if jinja_env_options else {})

env = Environment( # noqa[S701]
env = Environment( # noqa: S701
loader=FileSystemLoader(template_path), extensions=["jinja2.ext.i18n"], **jenv_opt
)
sys_info = get_sys_info()
Expand Down
8 changes: 4 additions & 4 deletions jupyter_server/services/contents/filemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,10 @@ def _get_dir_size(self, path="."):
try:
if platform.system() == "Darwin":
# retuns the size of the folder in KB
result = subprocess.run(["du", "-sk", path], capture_output=True).stdout.split()
result = subprocess.run(["du", "-sk", path], capture_output=True, check=True).stdout.split()
else:
result = subprocess.run(
["du", "-s", "--block-size=1", path], capture_output=True
["du", "-s", "--block-size=1", path], capture_output=True, check=True
).stdout.split()

self.log.info(f"current status of du command {result}")
Expand Down Expand Up @@ -1137,10 +1137,10 @@ async def _get_dir_size(self, path: str = ".") -> str:
try:
if platform.system() == "Darwin":
# retuns the size of the folder in KB
result = subprocess.run(["du", "-sk", path], capture_output=True).stdout.split()
result = subprocess.run(["du", "-sk", path], capture_output=True, check=True).stdout.split()
else:
result = subprocess.run(
["du", "-s", "--block-size=1", path], capture_output=True
["du", "-s", "--block-size=1", path], capture_output=True, check=True
).stdout.split()

self.log.info(f"current status of du command {result}")
Expand Down
1 change: 0 additions & 1 deletion jupyter_server/services/kernelspecs/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def kernelspec_model(handler, name, spec_dict, resource_dir):
d = {"name": name, "spec": spec_dict, "resources": {}}

# Add resource files if they exist
resource_dir = resource_dir
for resource in ["kernel.js", "kernel.css"]:
if os.path.exists(pjoin(resource_dir, resource)):
d["resources"][resource] = url_path_join(
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 @@ -135,7 +135,7 @@ def get(self, record: Union[KernelSessionRecord, str]) -> KernelSessionRecord:
"""
if isinstance(record, str):
for r in self._records:
if record == r.kernel_id or record == r.session_id:
if record in (r.kernel_id, r.session_id):
return r
elif isinstance(record, KernelSessionRecord):
for r in self._records:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ detached = true
dependencies = [
"black[jupyter]==23.3.0",
"mdformat>0.7",
"ruff==0.0.276",
"ruff==0.0.287",
]
[tool.hatch.envs.lint.scripts]
style = [
Expand Down

0 comments on commit d15419b

Please sign in to comment.