Skip to content

Commit

Permalink
Fix new UP032 errors from ruff 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Oct 19, 2023
1 parent 3804cfd commit 37b6fe8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 32 deletions.
6 changes: 3 additions & 3 deletions lib/galaxy/authnz/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _parse_oidc_config(self, config_file):
if root.tag != "OIDC":
raise etree.ParseError(
"The root element in OIDC_Config xml file is expected to be `OIDC`, "
"found `{}` instead -- unable to continue.".format(root.tag)
f"found `{root.tag}` instead -- unable to continue."
)
for child in root:
if child.tag != "Setter":
Expand All @@ -79,7 +79,7 @@ def _parse_oidc_config(self, config_file):
if "Property" not in child.attrib or "Value" not in child.attrib or "Type" not in child.attrib:
log.error(
"Could not find the node attributes `Property` and/or `Value` and/or `Type`;"
" found these attributes: `{}`; skipping this node.".format(child.attrib)
f" found these attributes: `{child.attrib}`; skipping this node."
)
continue
try:
Expand Down Expand Up @@ -110,7 +110,7 @@ def _parse_oidc_backends_config(self, config_file):
if root.tag != "OIDC":
raise etree.ParseError(
"The root element in OIDC config xml file is expected to be `OIDC`, "
"found `{}` instead -- unable to continue.".format(root.tag)
f"found `{root.tag}` instead -- unable to continue."
)
for child in root:
if child.tag != "provider":
Expand Down
12 changes: 3 additions & 9 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def calculate_user_disk_usage_statements(user_id, quota_source_map, for_sqlite=F
)
if for_sqlite:
# hacky alternative for older sqlite
statement = """
statement = f"""
WITH new (user_id, quota_source_label, disk_usage) AS (
VALUES(:id, :label, ({label_usage}))
)
Expand All @@ -614,9 +614,7 @@ def calculate_user_disk_usage_statements(user_id, quota_source_map, for_sqlite=F
LEFT JOIN user_quota_source_usage AS old
ON new.user_id = old.user_id
AND new.quota_source_label = old.quota_source_label
""".format(
label_usage=label_usage
)
"""
else:
statement = f"""
INSERT INTO user_quota_source_usage(user_id, quota_source_label, disk_usage)
Expand Down Expand Up @@ -996,11 +994,7 @@ def calculate_disk_usage_default_source(self, object_store):
exclude_objectstore_ids = quota_source_map.default_usage_excluded_ids()
default_cond = "dataset.object_store_id IS NULL OR" if default_quota_enabled and exclude_objectstore_ids else ""
default_usage_dataset_condition = (
(
"AND ( {default_cond} dataset.object_store_id NOT IN :exclude_object_store_ids )".format(
default_cond=default_cond,
)
)
(f"AND ( {default_cond} dataset.object_store_id NOT IN :exclude_object_store_ids )")
if exclude_objectstore_ids
else ""
)
Expand Down
6 changes: 2 additions & 4 deletions lib/galaxy/quota/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,14 @@ def _default_unregistered_quota(self, quota_source_label):
def _default_quota(self, default_type, quota_source_label):
label_condition = "IS NULL" if quota_source_label is None else "= :label"
query = text(
"""
f"""
SELECT bytes
FROM quota as default_quota
LEFT JOIN default_quota_association on default_quota.id = default_quota_association.quota_id
WHERE default_quota_association.type = :default_type
AND default_quota.deleted != :is_true
AND default_quota.quota_source_label {label_condition}
""".format(
label_condition=label_condition
)
"""
)

conn = self.sa_session.connection()
Expand Down
12 changes: 5 additions & 7 deletions lib/galaxy/web/framework/middleware/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def send_report(rep, exc_data, html=True):


def error_template(head_html, exception, extra):
return """
return f"""
<!DOCTYPE HTML>
<html>
<head>
Expand All @@ -476,24 +476,22 @@ def error_template(head_html, exception, extra):
.content {{ max-width: 720px; margin: auto; margin-top: 50px; }}
</style>
<title>Internal Server Error</title>
{}
{head_html}
</head>
<body>
<div class="content">
<h1>Internal Server Error</h1>
<h2>Galaxy was unable to successfully complete your request</h2>
<p>{}</p>
<p>{exception}</p>
This may be an intermittent problem due to load or other unpredictable factors, reloading the page may address the problem.
{}
{extra}
</div>
</body>
</html>""".format(
head_html, exception, extra
)
</html>"""


def make_error_middleware(app, global_conf, **kw):
Expand Down
14 changes: 5 additions & 9 deletions lib/galaxy/webapps/galaxy/api/cloudauthz.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ def create(self, trans, payload, **kwargs):
* status: HTTP response code
* message: A message complementary to the response code.
"""
msg_template = f"Rejected user `{str(trans.user.id)}`'s request to create cloudauthz config because of {{}}."
msg_template = f"Rejected user `{trans.user.id}`'s request to create cloudauthz config because of {{}}."
if not isinstance(payload, dict):
raise ActionInputError(
"Invalid payload data type. The payload is expected to be a dictionary, but "
"received data of type `{}`.".format(str(type(payload)))
f"received data of type `{type(payload)}`."
)

missing_arguments = []
Expand All @@ -116,7 +116,7 @@ def create(self, trans, payload, **kwargs):
if len(missing_arguments) > 0:
log.debug(msg_template.format(f"missing required config {missing_arguments}"))
raise RequestParameterMissingException(
"The following required arguments are missing in the payload: " "{}".format(missing_arguments)
f"The following required arguments are missing in the payload: {missing_arguments}"
)

description = payload.get("description", "")
Expand Down Expand Up @@ -200,9 +200,7 @@ def delete(self, trans, encoded_authz_id, **kwargs):
return view
except Exception as e:
log.exception(
msg_template.format(
"exception while deleting the cloudauthz record with " "ID: `{}`.".format(encoded_authz_id)
)
msg_template.format(f"exception while deleting the cloudauthz record with ID: `{encoded_authz_id}`.")
)
raise InternalServerError(
"An unexpected error has occurred while responding to the DELETE request of the "
Expand Down Expand Up @@ -270,9 +268,7 @@ def update(self, trans, encoded_authz_id, payload, **kwargs):
raise e
except Exception as e:
log.exception(
msg_template.format(
"exception while updating the cloudauthz record with " "ID: `{}`.".format(encoded_authz_id)
)
msg_template.format(f"exception while updating the cloudauthz record with ID: `{encoded_authz_id}`.")
)
raise InternalServerError(
"An unexpected error has occurred while responding to the PUT request of the "
Expand Down

0 comments on commit 37b6fe8

Please sign in to comment.