From 544769d6d2831e60d37747c8586fd125198fea12 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Tue, 24 Oct 2023 18:58:55 +0100 Subject: [PATCH 1/2] Enable flake8-logging-format rules in ruff, fix G003 and G010 errors --- lib/galaxy/jobs/runners/kubernetes.py | 20 ++++++++----------- lib/galaxy/metadata/set_metadata.py | 2 +- .../visualization/plugins/config_parser.py | 5 +++-- .../visualization/plugins/resource_parser.py | 7 +++++-- pyproject.toml | 7 +++++-- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/galaxy/jobs/runners/kubernetes.py b/lib/galaxy/jobs/runners/kubernetes.py index 1f9e984605c3..90d43aafe504 100644 --- a/lib/galaxy/jobs/runners/kubernetes.py +++ b/lib/galaxy/jobs/runners/kubernetes.py @@ -252,9 +252,8 @@ def __get_run_as_user_id(self): return int(self.runner_params["k8s_run_as_user_id"]) except Exception: log.warning( - 'User ID passed for Kubernetes runner needs to be an integer or "$uid", value ' - + self.runner_params["k8s_run_as_user_id"] - + " passed is invalid" + 'User ID passed for Kubernetes runner needs to be an integer or "$uid", value %s passed is invalid', + self.runner_params["k8s_run_as_user_id"], ) return None return None @@ -269,9 +268,8 @@ def __get_run_as_group_id(self): return int(self.runner_params["k8s_run_as_group_id"]) except Exception: log.warning( - 'Group ID passed for Kubernetes runner needs to be an integer or "$gid", value ' - + self.runner_params["k8s_run_as_group_id"] - + " passed is invalid" + 'Group ID passed for Kubernetes runner needs to be an integer or "$gid", value %s passed is invalid', + self.runner_params["k8s_run_as_group_id"], ) return None @@ -284,9 +282,8 @@ def __get_supplemental_group(self): return int(self.runner_params["k8s_supplemental_group_id"]) except Exception: log.warning( - 'Supplemental group passed for Kubernetes runner needs to be an integer or "$gid", value ' - + self.runner_params["k8s_supplemental_group_id"] - + " passed is invalid" + 'Supplemental group passed for Kubernetes runner needs to be an integer or "$gid", value %s passed is invalid', + self.runner_params["k8s_supplemental_group_id"], ) return None return None @@ -297,9 +294,8 @@ def __get_fs_group(self): return int(self.runner_params["k8s_fs_group_id"]) except Exception: log.warning( - 'FS group passed for Kubernetes runner needs to be an integer or "$gid", value ' - + self.runner_params["k8s_fs_group_id"] - + " passed is invalid" + 'FS group passed for Kubernetes runner needs to be an integer or "$gid", value %s passed is invalid', + self.runner_params["k8s_fs_group_id"], ) return None return None diff --git a/lib/galaxy/metadata/set_metadata.py b/lib/galaxy/metadata/set_metadata.py index b512f3f905b5..51054ab8e056 100644 --- a/lib/galaxy/metadata/set_metadata.py +++ b/lib/galaxy/metadata/set_metadata.py @@ -262,7 +262,7 @@ def set_meta(new_dataset_instance, file_dict): if not is_celery_task: error_desc = "Failed to find tool_stdout or tool_stderr for this job, cannot collect metadata" error_extra = f"Working dir contents [{wdc}], output directory contents [{odc}]" - log.warn(f"{error_desc}. {error_extra}") + log.warning(f"{error_desc}. {error_extra}") raise Exception(error_desc) else: tool_stdout = tool_stderr = b"" diff --git a/lib/galaxy/visualization/plugins/config_parser.py b/lib/galaxy/visualization/plugins/config_parser.py index 441ed2d6f08a..c2867c13439b 100644 --- a/lib/galaxy/visualization/plugins/config_parser.py +++ b/lib/galaxy/visualization/plugins/config_parser.py @@ -286,8 +286,9 @@ def parse_tests(self, xml_tree_list): test_result = test_elem.text.strip() if test_elem.text else None if not test_type or not test_result: log.warning( - "Skipping test. Needs both type attribute and text node to be parsed: " - + f"{test_type}, {test_elem.text}" + "Skipping test. Needs both type attribute and text node to be parsed: %s, %s", + test_type, + test_elem.text, ) continue test_result = test_result.strip() diff --git a/lib/galaxy/visualization/plugins/resource_parser.py b/lib/galaxy/visualization/plugins/resource_parser.py index 394f8aa34419..df6dedf8640a 100644 --- a/lib/galaxy/visualization/plugins/resource_parser.py +++ b/lib/galaxy/visualization/plugins/resource_parser.py @@ -134,8 +134,11 @@ def parse_config(self, trans, param_config_dict, query_params): except Exception as exception: log.warning( - "Exception parsing visualization param from query: " - + f"{param_name}, {config_val}, ({str(type(exception))}) {str(exception)}" + "Exception parsing visualization param from query: %s, %s, (%s) %s", + param_name, + config_val, + type(exception), + exception, ) config_val = None diff --git a/pyproject.toml b/pyproject.toml index f0729a813c1f..ae5fcc88b942 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -181,14 +181,17 @@ types-requests = "*" types-six = "*" [tool.ruff] -select = ["E", "F", "B", "UP"] +# Enable: pycodestyle errors (E), Pyflakes (F), flake8-bugbear (B), +# flake8-logging-format (G) and pyupgrade (UP) +select = ["E", "F", "B", "G", "UP"] target-version = "py37" # Exceptions: # B008 Do not perform function calls in argument defaults (for FastAPI Depends and Body) # B9 flake8-bugbear opinionated warnings # E402 module level import not at top of file # TODO, we would like to improve this. # E501 is line length (delegated to black) -ignore = ["B008", "B9", "E402", "E501"] +# G* are TODOs +ignore = ["B008", "B9", "E402", "E501", "G001", "G002", "G004", "G201"] exclude = [ "lib/tool_shed/test/test_data/repos" ] From 78e45777e3bd3dc6036dfe8768c715f74b9adac1 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Tue, 24 Oct 2023 19:20:43 +0100 Subject: [PATCH 2/2] Fix G201 ruff errors --- .../tools/error_reports/plugins/gitlab.py | 31 ++++++++----------- pyproject.toml | 2 +- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/lib/galaxy/tools/error_reports/plugins/gitlab.py b/lib/galaxy/tools/error_reports/plugins/gitlab.py index 9abf32a94ec4..9127deb2943c 100644 --- a/lib/galaxy/tools/error_reports/plugins/gitlab.py +++ b/lib/galaxy/tools/error_reports/plugins/gitlab.py @@ -47,16 +47,16 @@ def __init__(self, **kwargs): self.gitlab.auth() except gitlab.GitlabAuthenticationError: - log.error("GitLab error reporting - Could not authenticate with GitLab.", exc_info=True) + log.exception("GitLab error reporting - Could not authenticate with GitLab.") self.gitlab = None except gitlab.GitlabParsingError: - log.error("GitLab error reporting - Could not parse GitLab message.", exc_info=True) + log.exception("GitLab error reporting - Could not parse GitLab message.") self.gitlab = None except (gitlab.GitlabConnectionError, gitlab.GitlabHttpError): - log.error("GitLab error reporting - Could not connect to GitLab.", exc_info=True) + log.exception("GitLab error reporting - Could not connect to GitLab.") self.gitlab = None except gitlab.GitlabError: - log.error("GitLab error reporting - General error communicating with GitLab.", exc_info=True) + log.exception("GitLab error reporting - General error communicating with GitLab.") self.gitlab = None def gitlab_connect(self): @@ -195,34 +195,29 @@ def submit_report(self, dataset, job, tool, **kwargs): ) except gitlab.GitlabCreateError: - log.error("GitLab error reporting - Could not create the issue on GitLab.", exc_info=True) + log.exception("GitLab error reporting - Could not create the issue on GitLab.") return ("Internal Error.", "danger") except gitlab.GitlabOwnershipError: - log.error( - "GitLab error reporting - Could not create the issue on GitLab due to ownership issues.", - exc_info=True, - ) + log.exception("GitLab error reporting - Could not create the issue on GitLab due to ownership issues.") return ("Internal Error.", "danger") except gitlab.GitlabSearchError: - log.error("GitLab error reporting - Could not find repository on GitLab.", exc_info=True) + log.exception("GitLab error reporting - Could not find repository on GitLab.") return ("Internal Error.", "danger") except gitlab.GitlabAuthenticationError: - log.error("GitLab error reporting - Could not authenticate with GitLab.", exc_info=True) + log.exception("GitLab error reporting - Could not authenticate with GitLab.") return ("Internal Error.", "danger") except gitlab.GitlabParsingError: - log.error("GitLab error reporting - Could not parse GitLab message.", exc_info=True) + log.exception("GitLab error reporting - Could not parse GitLab message.") return ("Internal Error.", "danger") except (gitlab.GitlabConnectionError, gitlab.GitlabHttpError): - log.error("GitLab error reporting - Could not connect to GitLab.", exc_info=True) + log.exception("GitLab error reporting - Could not connect to GitLab.") return ("Internal Error.", "danger") except gitlab.GitlabError: - log.error("GitLab error reporting - General error communicating with GitLab.", exc_info=True) + log.exception("GitLab error reporting - General error communicating with GitLab.") return ("Internal Error.", "danger") except Exception: - log.error( - "GitLab error reporting - Error reporting to GitLab had an exception that could not be " - "determined.", - exc_info=True, + log.exception( + "GitLab error reporting - Error reporting to GitLab had an exception that could not be determined.", ) return ("Internal Error.", "danger") else: diff --git a/pyproject.toml b/pyproject.toml index ae5fcc88b942..ed8f9cb93a85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -191,7 +191,7 @@ target-version = "py37" # E402 module level import not at top of file # TODO, we would like to improve this. # E501 is line length (delegated to black) # G* are TODOs -ignore = ["B008", "B9", "E402", "E501", "G001", "G002", "G004", "G201"] +ignore = ["B008", "B9", "E402", "E501", "G001", "G002", "G004"] exclude = [ "lib/tool_shed/test/test_data/repos" ]