diff --git a/jupyter_server/base/handlers.py b/jupyter_server/base/handlers.py index 471c8317d6..fc20ce251c 100644 --- a/jupyter_server/base/handlers.py +++ b/jupyter_server/base/handlers.py @@ -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): diff --git a/jupyter_server/extension/application.py b/jupyter_server/extension/application.py index 9f5cb06e99..5f4f6a28af 100644 --- a/jupyter_server/extension/application.py +++ b/jupyter_server/extension/application.py @@ -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: diff --git a/jupyter_server/gateway/managers.py b/jupyter_server/gateway/managers.py index e8a622401a..f2d12d7b0b 100644 --- a/jupyter_server/gateway/managers.py +++ b/jupyter_server/gateway/managers.py @@ -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}" @@ -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 @@ -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: @@ -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 diff --git a/jupyter_server/log.py b/jupyter_server/log.py index 1ca87b279c..7bb922880b 100644 --- a/jupyter_server/log.py +++ b/jupyter_server/log.py @@ -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 @@ -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"]: diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index 95309e9cb9..c0e1cf1342 100644 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -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() diff --git a/jupyter_server/services/contents/filemanager.py b/jupyter_server/services/contents/filemanager.py index 19f4a123ba..a77fdbf28a 100644 --- a/jupyter_server/services/contents/filemanager.py +++ b/jupyter_server/services/contents/filemanager.py @@ -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}") @@ -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}") diff --git a/jupyter_server/services/kernelspecs/handlers.py b/jupyter_server/services/kernelspecs/handlers.py index e1ed186fa7..bee99bb158 100644 --- a/jupyter_server/services/kernelspecs/handlers.py +++ b/jupyter_server/services/kernelspecs/handlers.py @@ -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( diff --git a/jupyter_server/services/sessions/sessionmanager.py b/jupyter_server/services/sessions/sessionmanager.py index dda04b82c2..d20395e731 100644 --- a/jupyter_server/services/sessions/sessionmanager.py +++ b/jupyter_server/services/sessions/sessionmanager.py @@ -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: diff --git a/pyproject.toml b/pyproject.toml index f4a599c662..a662c50b5a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [