Skip to content

Commit

Permalink
#184: Add trailing commas to meet flake8 output
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Nov 3, 2020
1 parent 0f232dd commit a9f3b08
Show file tree
Hide file tree
Showing 25 changed files with 172 additions and 164 deletions.
8 changes: 4 additions & 4 deletions datagateway_api/common/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def update_with_id(self, session_id, entity_type, id_, data):

@abstractmethod
def get_facility_cycles_for_instrument_with_filters(
self, session_id, instrument_id, filters
self, session_id, instrument_id, filters,
):
"""
Given an instrument_id get facility cycles where the instrument has
Expand All @@ -158,7 +158,7 @@ def get_facility_cycles_for_instrument_with_filters(

@abstractmethod
def get_facility_cycles_for_instrument_count_with_filters(
self, session_id, instrument_id, filters
self, session_id, instrument_id, filters,
):
"""
Given an instrument_id get the facility cycles count where the instrument has
Expand All @@ -173,7 +173,7 @@ def get_facility_cycles_for_instrument_count_with_filters(

@abstractmethod
def get_investigations_for_instrument_in_facility_cycle_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters
self, session_id, instrument_id, facilitycycle_id, filters,
):
"""
Given an instrument id and facility cycle id, get investigations that use the
Expand All @@ -189,7 +189,7 @@ def get_investigations_for_instrument_in_facility_cycle_with_filters(

@abstractmethod
def get_investigations_for_instrument_in_facility_cycle_count_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters
self, session_id, instrument_id, facilitycycle_id, filters,
):
"""
Given an instrument id and facility cycle id, get the count of the
Expand Down
12 changes: 6 additions & 6 deletions datagateway_api/common/database/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,31 @@ def update_with_id(self, session_id, entity_type, id_, data):
@requires_session_id
@queries_records
def get_facility_cycles_for_instrument_with_filters(
self, session_id, instrument_id, filters
self, session_id, instrument_id, filters,
):
return get_facility_cycles_for_instrument(instrument_id, filters)

@requires_session_id
@queries_records
def get_facility_cycles_for_instrument_count_with_filters(
self, session_id, instrument_id, filters
self, session_id, instrument_id, filters,
):
return get_facility_cycles_for_instrument_count(instrument_id, filters)

@requires_session_id
@queries_records
def get_investigations_for_instrument_in_facility_cycle_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters
self, session_id, instrument_id, facilitycycle_id, filters,
):
return get_investigations_for_instrument_in_facility_cycle(
instrument_id, facilitycycle_id, filters
instrument_id, facilitycycle_id, filters,
)

@requires_session_id
@queries_records
def get_investigations_for_instrument_in_facility_cycle_count_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters
self, session_id, instrument_id, facilitycycle_id, filters,
):
return get_investigations_for_instrument_in_facility_cycle_count(
instrument_id, facilitycycle_id, filters
instrument_id, facilitycycle_id, filters,
)
6 changes: 3 additions & 3 deletions datagateway_api/common/database/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def apply_filter(self, query):
field = getattr(query.table, self.field)
except AttributeError:
raise FilterError(
f"Unknown attribute {self.field} on table {query.table.__name__}"
f"Unknown attribute {self.field} on table {query.table.__name__}",
)

if self.included_included_field:
included_table = getattr(models, self.field)
included_included_table = getattr(models, self.included_field)
query.base_query = query.base_query.join(included_table).join(
included_included_table
included_included_table,
)
field = getattr(included_included_table, self.included_included_field)

Expand All @@ -85,7 +85,7 @@ def apply_filter(self, query):
query.base_query = query.base_query.filter(field.in_(self.value))
else:
raise FilterError(
f" Bad operation given to where filter. operation: {self.operation}"
f" Bad operation given to where filter. operation: {self.operation}",
)


Expand Down
10 changes: 5 additions & 5 deletions datagateway_api/common/database/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
else:
raise ApiError(
"Cannot select which implementation of filters to import, check the config file"
" has a valid backend type"
" has a valid backend type",
)

log = logging.getLogger()
Expand Down Expand Up @@ -521,7 +521,7 @@ def __init__(self, instrument_id, facility_cycle_id):


def get_investigations_for_instrument_in_facility_cycle(
instrument_id, facility_cycle_id, filters
instrument_id, facility_cycle_id, filters,
):
"""
Given an instrument id and facility cycle id, get investigations that use the given
Expand All @@ -534,7 +534,7 @@ def get_investigations_for_instrument_in_facility_cycle(
"""
filter_handler = FilterOrderHandler()
with InstrumentFacilityCycleInvestigationsQuery(
instrument_id, facility_cycle_id
instrument_id, facility_cycle_id,
) as query:
return get_filtered_read_query_results(filter_handler, filters, query)

Expand All @@ -558,7 +558,7 @@ def __init__(self, instrument_id, facility_cycle_id):


def get_investigations_for_instrument_in_facility_cycle_count(
instrument_id, facility_cycle_id, filters
instrument_id, facility_cycle_id, filters,
):
"""
Given an instrument id and facility cycle id, get the count of the investigations
Expand All @@ -570,7 +570,7 @@ def get_investigations_for_instrument_in_facility_cycle_count(
:return: The investigations count
"""
with InstrumentFacilityCycleInvestigationsCountQuery(
instrument_id, facility_cycle_id
instrument_id, facility_cycle_id,
) as query:
filter_handler = FilterOrderHandler()
filter_handler.add_filters(filters)
Expand Down
50 changes: 27 additions & 23 deletions datagateway_api/common/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_entity_object_from_name(entity_name):
return globals()[entity_name.upper()]
except KeyError:
raise ApiError(
f"Entity class cannot be found. Please create a class for {entity_name}"
f"Entity class cannot be found, missing class for {entity_name}",
)

def to_dict(self):
Expand Down Expand Up @@ -132,17 +132,17 @@ def _nest_dictionary_include(self, dictionary, include):
related_entity = self.get_related_entity(list(include)[0])
if not isinstance(related_entity, InstrumentedList):
dictionary[related_entity.__tablename__] = related_entity.to_nested_dict(
include[list(include)[0]]
include[list(include)[0]],
)
else:
for entity in related_entity:
if entity.__tablename__ in dictionary.keys():
dictionary[entity.__tablename__].append(
entity.to_nested_dict(include[list(include)[0]])
entity.to_nested_dict(include[list(include)[0]]),
)
else:
dictionary[entity.__tablename__] = [
entity.to_nested_dict(include[list(include)[0]])
entity.to_nested_dict(include[list(include)[0]]),
]

def _nest_string_include(self, dictionary, include):
Expand Down Expand Up @@ -289,7 +289,7 @@ class DATACOLLECTIONPARAMETER(Base, EntityHelper):
__tablename__ = "DATACOLLECTIONPARAMETER"
__table_args__ = (
Index(
"UNQ_DATACOLLECTIONPARAMETER_0", "DATACOLLECTION_ID", "PARAMETER_TYPE_ID"
"UNQ_DATACOLLECTIONPARAMETER_0", "DATACOLLECTION_ID", "PARAMETER_TYPE_ID",
),
)

Expand All @@ -306,7 +306,7 @@ class DATACOLLECTIONPARAMETER(Base, EntityHelper):
STRING_VALUE = Column(String(4000))
DATACOLLECTION_ID = Column(ForeignKey("DATACOLLECTION.ID"), nullable=False)
PARAMETER_TYPE_ID = Column(
ForeignKey("PARAMETERTYPE.ID"), nullable=False, index=True
ForeignKey("PARAMETERTYPE.ID"), nullable=False, index=True,
)

DATACOLLECTION = relationship(
Expand Down Expand Up @@ -347,7 +347,7 @@ class DATAFILE(Base, EntityHelper):
backref="DATAFILE",
)
DATASET = relationship(
"DATASET", primaryjoin="DATAFILE.DATASET_ID == DATASET.ID", backref="DATAFILE"
"DATASET", primaryjoin="DATAFILE.DATASET_ID == DATASET.ID", backref="DATAFILE",
)


Expand Down Expand Up @@ -392,7 +392,7 @@ class DATAFILEPARAMETER(Base, EntityHelper):
STRING_VALUE = Column(String(4000))
DATAFILE_ID = Column(ForeignKey("DATAFILE.ID"), nullable=False)
PARAMETER_TYPE_ID = Column(
ForeignKey("PARAMETERTYPE.ID"), nullable=False, index=True
ForeignKey("PARAMETERTYPE.ID"), nullable=False, index=True,
)

DATAFILE = relationship(
Expand Down Expand Up @@ -433,7 +433,7 @@ class DATASET(Base, EntityHelper):
backref="DATASET",
)
SAMPLE = relationship(
"SAMPLE", primaryjoin="DATASET.SAMPLE_ID == SAMPLE.ID", backref="DATASET"
"SAMPLE", primaryjoin="DATASET.SAMPLE_ID == SAMPLE.ID", backref="DATASET",
)
DATASETTYPE = relationship(
"DATASETTYPE",
Expand Down Expand Up @@ -461,7 +461,7 @@ class DATASETPARAMETER(Base, EntityHelper):
STRING_VALUE = Column(String(4000))
DATASET_ID = Column(ForeignKey("DATASET.ID"), nullable=False)
PARAMETER_TYPE_ID = Column(
ForeignKey("PARAMETERTYPE.ID"), nullable=False, index=True
ForeignKey("PARAMETERTYPE.ID"), nullable=False, index=True,
)

DATASET = relationship(
Expand Down Expand Up @@ -622,7 +622,7 @@ class INVESTIGATIONGROUP(Base, EntityHelper):
ROLE = Column(String(255), nullable=False)
GROUP_ID = Column(ForeignKey("GROUPING.ID"), nullable=False)
INVESTIGATION_ID = Column(
ForeignKey("INVESTIGATION.ID"), nullable=False, index=True
ForeignKey("INVESTIGATION.ID"), nullable=False, index=True,
)

GROUPING = relationship(
Expand Down Expand Up @@ -682,7 +682,7 @@ class INVESTIGATIONPARAMETER(Base, EntityHelper):
STRING_VALUE = Column(String(4000))
INVESTIGATION_ID = Column(ForeignKey("INVESTIGATION.ID"), nullable=False)
PARAMETER_TYPE_ID = Column(
ForeignKey("PARAMETERTYPE.ID"), nullable=False, index=True
ForeignKey("PARAMETERTYPE.ID"), nullable=False, index=True,
)

INVESTIGATION = relationship(
Expand Down Expand Up @@ -730,7 +730,7 @@ class INVESTIGATIONUSER(Base, EntityHelper):
MOD_TIME = Column(DateTime, nullable=False)
ROLE = Column(String(255), nullable=False)
INVESTIGATION_ID = Column(
ForeignKey("INVESTIGATION.ID"), nullable=False, index=True
ForeignKey("INVESTIGATION.ID"), nullable=False, index=True,
)
USER_ID = Column(ForeignKey("USER_.ID"), nullable=False)

Expand Down Expand Up @@ -760,7 +760,9 @@ class JOB(Base, EntityHelper):
OUTPUTDATACOLLECTION_ID = Column(ForeignKey("DATACOLLECTION.ID"), index=True)

APPLICATION = relationship(
"APPLICATION", primaryjoin="JOB.APPLICATION_ID == APPLICATION.ID", backref="JOB"
"APPLICATION",
primaryjoin="JOB.APPLICATION_ID == APPLICATION.ID",
backref="JOB",
)
DATACOLLECTION = relationship(
"DATACOLLECTION",
Expand All @@ -780,7 +782,7 @@ class KEYWORD(Base, EntityHelper):
MOD_TIME = Column(DateTime, nullable=False)
NAME = Column(String(255), nullable=False)
INVESTIGATION_ID = Column(
ForeignKey("INVESTIGATION.ID"), nullable=False, index=True
ForeignKey("INVESTIGATION.ID"), nullable=False, index=True,
)

INVESTIGATION = relationship(
Expand Down Expand Up @@ -840,7 +842,7 @@ class PERMISSIBLESTRINGVALUE(Base, EntityHelper):
MOD_TIME = Column(DateTime, nullable=False)
VALUE = Column(String(255), nullable=False)
PARAMETERTYPE_ID = Column(
ForeignKey("PARAMETERTYPE.ID"), nullable=False, index=True
ForeignKey("PARAMETERTYPE.ID"), nullable=False, index=True,
)

PARAMETERTYPE = relationship(
Expand All @@ -864,7 +866,7 @@ class PUBLICATION(Base, EntityHelper):
REPOSITORYID = Column(String(255))
URL = Column(String(255))
INVESTIGATION_ID = Column(
ForeignKey("INVESTIGATION.ID"), nullable=False, index=True
ForeignKey("INVESTIGATION.ID"), nullable=False, index=True,
)

INVESTIGATION = relationship(
Expand Down Expand Up @@ -932,7 +934,7 @@ class RULE(Base, EntityHelper):
GROUPING_ID = Column(ForeignKey("GROUPING.ID"), index=True)

GROUPING = relationship(
"GROUPING", primaryjoin="RULE.GROUPING_ID == GROUPING.ID", backref="RULE"
"GROUPING", primaryjoin="RULE.GROUPING_ID == GROUPING.ID", backref="RULE",
)


Expand Down Expand Up @@ -978,7 +980,7 @@ class SAMPLEPARAMETER(Base, EntityHelper):
STRING_VALUE = Column(String(4000))
SAMPLE_ID = Column(ForeignKey("SAMPLE.ID"), nullable=False)
PARAMETER_TYPE_ID = Column(
ForeignKey("PARAMETERTYPE.ID"), nullable=False, index=True
ForeignKey("PARAMETERTYPE.ID"), nullable=False, index=True,
)

PARAMETERTYPE = relationship(
Expand Down Expand Up @@ -1049,10 +1051,12 @@ class USERGROUP(Base, EntityHelper):
USER_ID = Column(ForeignKey("USER_.ID"), nullable=False)

GROUPING = relationship(
"GROUPING", primaryjoin="USERGROUP.GROUP_ID == GROUPING.ID", backref="USERGROUP"
"GROUPING",
primaryjoin="USERGROUP.GROUP_ID == GROUPING.ID",
backref="USERGROUP",
)
USER_ = relationship(
"USER", primaryjoin="USERGROUP.USER_ID == USER.ID", backref="USERGROUP"
"USER", primaryjoin="USERGROUP.USER_ID == USER.ID", backref="USERGROUP",
)


Expand All @@ -1068,7 +1072,7 @@ class STUDYINVESTIGATION(Base, EntityHelper):
MOD_ID = Column(String(255), nullable=False)
MOD_TIME = Column(DateTime, nullable=False)
INVESTIGATION_ID = Column(
ForeignKey("INVESTIGATION.ID"), nullable=False, index=True
ForeignKey("INVESTIGATION.ID"), nullable=False, index=True,
)
STUDY_ID = Column(ForeignKey("STUDY.ID"), nullable=False)

Expand Down Expand Up @@ -1099,7 +1103,7 @@ class STUDY(Base, EntityHelper):
USER_ID = Column(ForeignKey("USER_.ID"), index=True)

USER_ = relationship(
"USER", primaryjoin="STUDY.USER_ID == USER.ID", backref="STUDY"
"USER", primaryjoin="STUDY.USER_ID == USER.ID", backref="STUDY",
)


Expand Down
2 changes: 1 addition & 1 deletion datagateway_api/common/database/session_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datagateway_api.common.constants import Constants

engine = create_engine(
Constants.DATABASE_URL, poolclass=QueuePool, pool_size=100, max_overflow=0
Constants.DATABASE_URL, poolclass=QueuePool, pool_size=100, max_overflow=0,
)
session_factory = sessionmaker(engine)

Expand Down
2 changes: 1 addition & 1 deletion datagateway_api/common/date_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def str_to_datetime_object(data):
raise BadRequestError(
"Bad request made, the date entered is not in the correct format. Use"
f" the {Constants.ACCEPTED_DATE_FORMAT} format to submit dates to the"
" API"
" API",
)

return data
Expand Down
2 changes: 1 addition & 1 deletion datagateway_api/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(
self,
msg="Bad request, only one include filter may be given per request",
*args,
**kwargs
**kwargs,
):
super().__init__(msg, *args, **kwargs)
self.status_code = 400
Expand Down
2 changes: 1 addition & 1 deletion datagateway_api/common/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, field, value, operation):
if not isinstance(self.value, list):
raise BadRequestError(
"When using the 'in' operation for a WHERE filter, the values must"
" be in a list format e.g. [1, 2, 3]"
" be in a list format e.g. [1, 2, 3]",
)


Expand Down
4 changes: 2 additions & 2 deletions datagateway_api/common/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_session_id_from_auth_header():
raise MissingCredentialsError(f"No credentials provided in auth header")
if len(auth_header) != 2 or auth_header[0] != "Bearer":
raise AuthenticationError(
f" Could not authenticate consumer with auth header {auth_header}"
f" Could not authenticate consumer with auth header {auth_header}",
)
return auth_header[1]

Expand Down Expand Up @@ -97,7 +97,7 @@ def get_filters_from_query_string():
for arg in request.args:
for value in request.args.getlist(arg):
filters.append(
QueryFilterFactory.get_query_filter({arg: json.loads(value)})
QueryFilterFactory.get_query_filter({arg: json.loads(value)}),
)
return filters
except Exception as e:
Expand Down
Loading

0 comments on commit a9f3b08

Please sign in to comment.