Skip to content

Commit c68e081

Browse files
jstone-devbencap
authored andcommitted
Formatted code with ruff.
1 parent f64bf22 commit c68e081

File tree

11 files changed

+468
-237
lines changed

11 files changed

+468
-237
lines changed

src/mavedb/lib/experiments.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
from mavedb.models.contributor import Contributor
99
from mavedb.models.controlled_keyword import ControlledKeyword
1010
from mavedb.models.experiment import Experiment
11-
from mavedb.models.experiment_controlled_keyword import ExperimentControlledKeywordAssociation
11+
from mavedb.models.experiment_controlled_keyword import (
12+
ExperimentControlledKeywordAssociation,
13+
)
1214
from mavedb.models.publication_identifier import PublicationIdentifier
1315
from mavedb.models.score_set import ScoreSet
1416
from mavedb.models.user import User
@@ -117,6 +119,9 @@ def search_experiments(
117119
items = []
118120

119121
save_to_logging_context({"matching_resources": len(items)})
120-
logger.debug(msg="Experiment search yielded {len(items)} matching resources.", extra=logging_context())
122+
logger.debug(
123+
msg="Experiment search yielded {len(items)} matching resources.",
124+
extra=logging_context(),
125+
)
121126

122127
return items

src/mavedb/lib/permissions.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ def __init__(self, permitted: bool, http_code: int = 403, message: Optional[str]
3737

3838
save_to_logging_context({"permission_message": self.message, "access_permitted": self.permitted})
3939
if self.permitted:
40-
logger.debug(msg="Access to the requested resource is permitted.", extra=logging_context())
40+
logger.debug(
41+
msg="Access to the requested resource is permitted.",
42+
extra=logging_context(),
43+
)
4144
else:
42-
logger.debug(msg="Access to the requested resource is not permitted.", extra=logging_context())
45+
logger.debug(
46+
msg="Access to the requested resource is not permitted.",
47+
extra=logging_context(),
48+
)
4349

4450

4551
class PermissionException(Exception):
@@ -315,7 +321,11 @@ def has_permission(user_data: Optional[UserData], item: Base, action: Action) ->
315321
# TODO who should be allowed to delete an official collection? mavedb admins only?
316322
# A collection may be deleted even if it has been published, as long as it is not an official collection.
317323
if user_is_owner:
318-
return PermissionResponse(not item.badge_name, 403, f"insufficient permissions for URN '{item.urn}'")
324+
return PermissionResponse(
325+
not item.badge_name,
326+
403,
327+
f"insufficient permissions for URN '{item.urn}'",
328+
)
319329
# MaveDB admins may delete official collections.
320330
elif roles_permitted(active_roles, [UserRole.admin]):
321331
return PermissionResponse(True)

src/mavedb/models/collection.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ class Collection(Base):
2222

2323
id = Column(Integer, primary_key=True)
2424

25-
urn = Column(String(64), nullable=True, default=generate_collection_urn, unique=True, index=True)
25+
urn = Column(
26+
String(64),
27+
nullable=True,
28+
default=generate_collection_urn,
29+
unique=True,
30+
index=True,
31+
)
2632
private = Column(Boolean, nullable=False, default=True)
2733

2834
name = Column(String, nullable=False)
@@ -37,7 +43,9 @@ class Collection(Base):
3743
modification_date = Column(Date, nullable=False, default=date.today, onupdate=date.today)
3844

3945
user_associations: Mapped[list[mavedb.models.collection_user_association.CollectionUserAssociation]] = relationship(
40-
"CollectionUserAssociation", back_populates="collection", cascade="all, delete-orphan"
46+
"CollectionUserAssociation",
47+
back_populates="collection",
48+
cascade="all, delete-orphan",
4149
)
4250
users: AssociationProxy[list[User]] = association_proxy(
4351
"user_associations",
@@ -48,8 +56,12 @@ class Collection(Base):
4856
)
4957

5058
experiments: Mapped[list[Experiment]] = relationship(
51-
"Experiment", secondary=collection_experiments_association_table, back_populates="collections"
59+
"Experiment",
60+
secondary=collection_experiments_association_table,
61+
back_populates="collections",
5262
)
5363
score_sets: Mapped[list[ScoreSet]] = relationship(
54-
"ScoreSet", secondary=collection_score_sets_association_table, back_populates="collections"
64+
"ScoreSet",
65+
secondary=collection_score_sets_association_table,
66+
back_populates="collections",
5567
)

src/mavedb/models/collection_user_association.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ class CollectionUserAssociation(Base):
1818
collection_id = Column("collection_id", Integer, ForeignKey("collections.id"), primary_key=True)
1919
user_id = Column("user_id", Integer, ForeignKey("users.id"), primary_key=True)
2020
contribution_role: Mapped["ContributionRole"] = Column(
21-
Enum(ContributionRole, create_constraint=True, length=32, native_enum=False, validate_strings=True),
21+
Enum(
22+
ContributionRole,
23+
create_constraint=True,
24+
length=32,
25+
native_enum=False,
26+
validate_strings=True,
27+
),
2228
nullable=False,
2329
)
2430

src/mavedb/models/experiment.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010

1111
from mavedb.db.base import Base
1212
from mavedb.lib.temp_urns import generate_temp_urn
13-
from mavedb.models.collection_association import collection_experiments_association_table
13+
from mavedb.models.collection_association import (
14+
collection_experiments_association_table,
15+
)
1416
from mavedb.models.contributor import Contributor
1517
from mavedb.models.controlled_keyword import ControlledKeyword
1618
from mavedb.models.doi_identifier import DoiIdentifier
17-
from mavedb.models.experiment_controlled_keyword import ExperimentControlledKeywordAssociation
18-
from mavedb.models.experiment_publication_identifier import ExperimentPublicationIdentifierAssociation
19+
from mavedb.models.experiment_controlled_keyword import (
20+
ExperimentControlledKeywordAssociation,
21+
)
22+
from mavedb.models.experiment_publication_identifier import (
23+
ExperimentPublicationIdentifierAssociation,
24+
)
1925
from mavedb.models.experiment_set import ExperimentSet
2026
from mavedb.models.legacy_keyword import LegacyKeyword
2127
from mavedb.models.publication_identifier import PublicationIdentifier
@@ -78,7 +84,9 @@ class Experiment(Base):
7884
score_sets: Mapped[List["ScoreSet"]] = relationship(back_populates="experiment", cascade="all, delete-orphan")
7985

8086
collections: Mapped[list["Collection"]] = relationship(
81-
"Collection", secondary=collection_experiments_association_table, back_populates="experiments"
87+
"Collection",
88+
secondary=collection_experiments_association_table,
89+
back_populates="experiments",
8290
)
8391
official_collections: Mapped[list["Collection"]] = relationship(
8492
"Collection",
@@ -98,19 +106,27 @@ class Experiment(Base):
98106
creation_date = Column(Date, nullable=False, default=date.today)
99107
modification_date = Column(Date, nullable=False, default=date.today, onupdate=date.today)
100108
contributors: Mapped[list["Contributor"]] = relationship(
101-
"Contributor", secondary=experiments_contributors_association_table, backref="experiments"
109+
"Contributor",
110+
secondary=experiments_contributors_association_table,
111+
backref="experiments",
102112
)
103113
keyword_objs: Mapped[list["ExperimentControlledKeywordAssociation"]] = relationship(
104114
back_populates="experiment", cascade="all, delete-orphan"
105115
)
106116
legacy_keyword_objs: Mapped[list[LegacyKeyword]] = relationship(
107-
"LegacyKeyword", secondary=experiments_legacy_keywords_association_table, backref="experiments"
117+
"LegacyKeyword",
118+
secondary=experiments_legacy_keywords_association_table,
119+
backref="experiments",
108120
)
109121
doi_identifiers: Mapped[list[DoiIdentifier]] = relationship(
110-
"DoiIdentifier", secondary=experiments_doi_identifiers_association_table, backref="experiments"
122+
"DoiIdentifier",
123+
secondary=experiments_doi_identifiers_association_table,
124+
backref="experiments",
111125
)
112126
publication_identifier_associations: Mapped[list[ExperimentPublicationIdentifierAssociation]] = relationship(
113-
"ExperimentPublicationIdentifierAssociation", back_populates="experiment", cascade="all, delete-orphan"
127+
"ExperimentPublicationIdentifierAssociation",
128+
back_populates="experiment",
129+
cascade="all, delete-orphan",
114130
)
115131
publication_identifiers: AssociationProxy[List[PublicationIdentifier]] = association_proxy(
116132
"publication_identifier_associations",
@@ -120,7 +136,9 @@ class Experiment(Base):
120136

121137
# sra_identifiers = relationship('SraIdentifier', secondary=experiments_sra_identifiers_association_table, backref='experiments')
122138
raw_read_identifiers: Mapped[list[RawReadIdentifier]] = relationship(
123-
"RawReadIdentifier", secondary=experiments_raw_read_identifiers_association_table, backref="experiments"
139+
"RawReadIdentifier",
140+
secondary=experiments_raw_read_identifiers_association_table,
141+
backref="experiments",
124142
)
125143

126144
# Unfortunately, we can't use association_proxy here, because in spite of what the documentation seems to imply, it
@@ -170,7 +188,10 @@ async def set_keywords(self, db, keywords: list):
170188
ExperimentControlledKeywordAssociation(
171189
experiment=self,
172190
controlled_keyword=await self._find_keyword(
173-
db, keyword_obj.keyword.key, keyword_obj.keyword.value, keyword_obj.keyword.vocabulary
191+
db,
192+
keyword_obj.keyword.key,
193+
keyword_obj.keyword.value,
194+
keyword_obj.keyword.vocabulary,
174195
),
175196
description=keyword_obj.description,
176197
)

src/mavedb/models/score_set.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ class ScoreSet(Base):
9090
approved = Column(Boolean, nullable=False, default=False)
9191
published_date = Column(Date, nullable=True)
9292
processing_state = Column(
93-
Enum(ProcessingState, create_constraint=True, length=32, native_enum=False, validate_strings=True),
93+
Enum(
94+
ProcessingState,
95+
create_constraint=True,
96+
length=32,
97+
native_enum=False,
98+
validate_strings=True,
99+
),
94100
nullable=True,
95101
)
96102
processing_errors = Column(JSONB, nullable=True)
@@ -100,7 +106,13 @@ class ScoreSet(Base):
100106
variants: Mapped[list["Variant"]] = relationship(back_populates="score_set", cascade="all, delete-orphan")
101107

102108
mapping_state = Column(
103-
Enum(MappingState, create_constraint=True, length=32, native_enum=False, validate_strings=True),
109+
Enum(
110+
MappingState,
111+
create_constraint=True,
112+
length=32,
113+
native_enum=False,
114+
validate_strings=True,
115+
),
104116
nullable=True,
105117
)
106118
mapping_errors = Column(JSONB, nullable=True)
@@ -113,7 +125,10 @@ class ScoreSet(Base):
113125
license: Mapped["License"] = relationship("License")
114126
superseded_score_set_id = Column("replaces_id", Integer, ForeignKey("scoresets.id"), index=True, nullable=True)
115127
superseded_score_set: Mapped[Optional["ScoreSet"]] = relationship(
116-
"ScoreSet", uselist=False, foreign_keys="ScoreSet.superseded_score_set_id", remote_side=[id]
128+
"ScoreSet",
129+
uselist=False,
130+
foreign_keys="ScoreSet.superseded_score_set_id",
131+
remote_side=[id],
117132
)
118133
superseding_score_set: Mapped[Optional["ScoreSet"]] = relationship(
119134
"ScoreSet", uselist=False, back_populates="superseded_score_set"
@@ -127,18 +142,26 @@ class ScoreSet(Base):
127142
modification_date = Column(Date, nullable=False, default=date.today, onupdate=date.today)
128143

129144
legacy_keyword_objs: Mapped[list["LegacyKeyword"]] = relationship(
130-
"LegacyKeyword", secondary=score_sets_legacy_keywords_association_table, backref="score_sets"
145+
"LegacyKeyword",
146+
secondary=score_sets_legacy_keywords_association_table,
147+
backref="score_sets",
131148
)
132149
contributors: Mapped[list["Contributor"]] = relationship(
133-
"Contributor", secondary=score_sets_contributors_association_table, backref="score_sets"
150+
"Contributor",
151+
secondary=score_sets_contributors_association_table,
152+
backref="score_sets",
134153
)
135154
doi_identifiers: Mapped[list["DoiIdentifier"]] = relationship(
136-
"DoiIdentifier", secondary=score_sets_doi_identifiers_association_table, backref="score_sets"
155+
"DoiIdentifier",
156+
secondary=score_sets_doi_identifiers_association_table,
157+
backref="score_sets",
137158
)
138159
publication_identifier_associations: Mapped[
139160
list[mavedb.models.score_set_publication_identifier.ScoreSetPublicationIdentifierAssociation]
140161
] = relationship(
141-
"ScoreSetPublicationIdentifierAssociation", back_populates="score_set", cascade="all, delete-orphan"
162+
"ScoreSetPublicationIdentifierAssociation",
163+
back_populates="score_set",
164+
cascade="all, delete-orphan",
142165
)
143166
publication_identifiers: AssociationProxy[List[PublicationIdentifier]] = association_proxy(
144167
"publication_identifier_associations",
@@ -162,7 +185,9 @@ class ScoreSet(Base):
162185
score_calibrations = Column(JSONB, nullable=True)
163186

164187
collections: Mapped[list["Collection"]] = relationship(
165-
"Collection", secondary=collection_score_sets_association_table, back_populates="score_sets"
188+
"Collection",
189+
secondary=collection_score_sets_association_table,
190+
back_populates="score_sets",
166191
)
167192
official_collections: Mapped[list["Collection"]] = relationship(
168193
"Collection",

0 commit comments

Comments
 (0)