-
Notifications
You must be signed in to change notification settings - Fork 5
Migrate to ruff #573
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
base: develop
Are you sure you want to change the base?
Migrate to ruff #573
Changes from all commits
0bc9f3b
1494a69
90cfdc5
fb018a9
5274729
93d0aea
a3d624f
6fb723b
22c3507
f4b13aa
d2aecb4
c8df008
a6705fa
58d46ca
047815a
7259d02
b2f95d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,11 @@ | ||
| from datetime import datetime | ||
| from functools import wraps | ||
| import json | ||
| import logging | ||
| from datetime import datetime | ||
| from functools import wraps | ||
|
|
||
| import requests | ||
| from fastapi import Request | ||
| from pydantic import ValidationError | ||
| import requests | ||
|
|
||
|
|
||
| from datagateway_api.common.date_handler import DateHandler | ||
| from datagateway_api.common.exceptions import ( | ||
|
|
@@ -25,7 +24,7 @@ def queries_records(method): | |
| Decorator for endpoint resources that search for a record in a table | ||
| :param method: The method for the endpoint | ||
| :return: Will return a 404, "No such record" if a MissingRecordError is caught | ||
| :return: Will return a 400, "Error message" if other expected errors are caught | ||
| :return: Will return a 400, "Error message" if other expected errors are caught. | ||
| """ | ||
|
|
||
| @wraps(method) | ||
|
|
@@ -52,7 +51,7 @@ def get_session_id_from_auth_header(request: Request): | |
| """ | ||
| Gets the sessionID from the Authorization header of a request | ||
| :request Request: FastAPI Request object containing the incoming headers | ||
| :return: String: SessionID | ||
| :return: String: SessionID. | ||
| """ | ||
| log.info("Getting session Id from auth header") | ||
|
|
||
|
|
@@ -63,7 +62,7 @@ def get_session_id_from_auth_header(request: Request): | |
|
|
||
| auth_header = auth_header_value.split(" ") | ||
|
|
||
| if len(auth_header) != 2 or auth_header[0] != "Bearer": | ||
| if len(auth_header) != 2 or auth_header[0] != "Bearer": # noqa: PLR2004 | ||
| raise AuthenticationError( | ||
| f"Could not authenticate consumer with auth header {auth_header}", | ||
| ) | ||
|
|
@@ -75,7 +74,7 @@ def is_valid_json(string): | |
| """ | ||
| Determines if a string is valid JSON | ||
| :param string: The string to be tested | ||
| :return: boolean representing if the string is valid JSON | ||
| :return: boolean representing if the string is valid JSON. | ||
| """ | ||
| try: | ||
| json.loads(string) | ||
|
|
@@ -89,7 +88,7 @@ def is_valid_json(string): | |
| def get_filters_from_query_string(request: Request, api_type, entity_name=None): | ||
| """ | ||
| Gets a list of filters from the query_strings arg,value pairs, and returns a list of | ||
| QueryFilter Objects | ||
| QueryFilter Objects. | ||
|
|
||
| :request Request: FastAPI Request object containing the incoming headers | ||
| :param api_type: Type of API this function is being used for i.e. DataGateway API or | ||
|
|
@@ -102,11 +101,11 @@ def get_filters_from_query_string(request: Request, api_type, entity_name=None): | |
| :return: The list of filters | ||
| """ | ||
| if api_type == "search_api": | ||
| from datagateway_api.search_api.query_filter_factory import ( | ||
| from datagateway_api.search_api.query_filter_factory import ( # noqa: PLC0415 | ||
| SearchAPIQueryFilterFactory as QueryFilterFactory, | ||
| ) | ||
| elif api_type == "datagateway_api": | ||
| from datagateway_api.datagateway_api.query_filter_factory import ( | ||
| from datagateway_api.datagateway_api.query_filter_factory import ( # noqa: PLC0415 | ||
|
Comment on lines
103
to
+108
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like ignoring these, as I don't like doing conditional imports mid-function. I also don't like the fact that a Given we pass
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll create an issue for this |
||
| DataGatewayAPIQueryFilterFactory as QueryFilterFactory, | ||
| ) | ||
| else: | ||
|
|
@@ -135,7 +134,7 @@ def get_icat_properties(icat_url, icat_check_cert): | |
| """ | ||
| ICAT properties can be retrieved using Python ICAT's client object, however this | ||
| requires the client object to be authenticated which may not always be the case | ||
| when requesting these properties, hence a HTTP request is sent as an alternative | ||
| when requesting these properties, hence a HTTP request is sent as an alternative. | ||
| """ | ||
| properties_url = f"{icat_url}/icat/properties" | ||
| r = requests.request("GET", properties_url, verify=icat_check_cert) | ||
|
|
@@ -147,7 +146,7 @@ def get_icat_properties(icat_url, icat_check_cert): | |
| def map_distinct_attributes_to_results(distinct_attributes, query_result): | ||
| """ | ||
| Maps the attribute names from a distinct filter onto the results given by the result | ||
| of a query | ||
| of a query. | ||
|
|
||
| When selecting multiple (but not all) attributes in a database query, the results | ||
| are returned in a list and not mapped to an entity object. This means the 'normal' | ||
|
|
@@ -169,7 +168,7 @@ def map_distinct_attributes_to_results(distinct_attributes, query_result): | |
| split_attr_name = attr_name.split(".") | ||
|
|
||
| if isinstance(data, datetime): | ||
| data = DateHandler.datetime_object_to_str(data) | ||
| data = DateHandler.datetime_object_to_str(data) # noqa: PLW2901 | ||
|
|
||
| # Attribute name is from the 'origin' entity (i.e. not a related entity) | ||
| if len(split_attr_name) == 1: | ||
|
|
@@ -184,7 +183,7 @@ def map_distinct_attributes_to_results(distinct_attributes, query_result): | |
| def map_nested_attrs(nested_dict, split_attr_name, query_data): | ||
| """ | ||
| A function that can be called recursively to map attributes from related | ||
| entities to the associated data | ||
| entities to the associated data. | ||
|
|
||
| :param nested_dict: Dictionary to insert data into | ||
| :type nested_dict: :class:`dict` | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how I feel about this. I assume since the first argument is unused, it wants it to be marked with an underscore? But now the arguments for
WhereFilterare different from its subclassesPythonICATWhereFilterandSearchAPIWhereFilter. And we never directly instantiateWhereFilteras far as I can see (one place weimport PythonICATWhereFilter as WhereFilterjust to be extra confusing. AndSearchAPIWhereFilteris a subclass ofPythonICATWhereFilternotWhereFilter. So why doesWhereFiltereven exist?Similarly, the other contents of
ral-facilities/datagateway-api/datagateway_api/search_api/filters.pyall import fromral-facilities/datagateway-api/datagateway_api/datagateway_api/icat/filters.pynotral-facilities/datagateway-api/datagateway_api/common/filters.py. Can we just remove this entire file and migrate the shared functionality toral-facilities/datagateway-api/datagateway_api/datagateway_api/icat/filters.pyclasses? Appreciate that's scope creep so should be in another PR. Maybe I'm missing something subtle too.In the case of this line I'd leave it and just ignore the QA rather than changing it if it's going to get nuked later, but either way it's not a big deal. The important bit to me is: why does this file exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a remnant of the database backend potentially
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll create an issue for this