Skip to content
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

Enable some flake8-logging-format rules in ruff #16915

Merged
merged 2 commits into from
Oct 25, 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
20 changes: 8 additions & 12 deletions lib/galaxy/jobs/runners/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/metadata/set_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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""
Expand Down
31 changes: 13 additions & 18 deletions lib/galaxy/tools/error_reports/plugins/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions lib/galaxy/visualization/plugins/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions lib/galaxy/visualization/plugins/resource_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
exclude = [
"lib/tool_shed/test/test_data/repos"
]
Expand Down