Skip to content

Commit df4c350

Browse files
committed
Format with black
1 parent 79b26cb commit df4c350

21 files changed

+206
-355
lines changed

api/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
date_format_string = "%Y-%m-%d %H:%M:%S %z"
77

88
logging.basicConfig(
9-
format=format_string,
10-
datefmt=date_format_string,
11-
level=getattr(logging, constants.Config.LOG_LEVEL.upper())
9+
format=format_string, datefmt=date_format_string, level=getattr(logging, constants.Config.LOG_LEVEL.upper())
1210
)
1311

1412
logging.getLogger().info("Logging initialization complete")

api/database.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class TeamUser(Base):
1515
"""A user who belongs to a team."""
1616

1717
__tablename__ = "team_has_user"
18-
__table_args__ = (
19-
PrimaryKeyConstraint('team_id', 'user_id'),
20-
)
18+
__table_args__ = (PrimaryKeyConstraint("team_id", "user_id"),)
2119

2220
team_id = Column(ForeignKey("teams.id"), nullable=False)
2321
user_id = Column(ForeignKey("users.id"), nullable=False)
@@ -65,18 +63,14 @@ class Team(Base):
6563
jam = relationship("Jam", back_populates="teams", lazy="joined")
6664
users = relationship("TeamUser", back_populates="team", lazy="joined")
6765

68-
__table_args__ = (
69-
Index('team_name_jam_unique', text("lower(name)"), "jam_id", unique=True),
70-
)
66+
__table_args__ = (Index("team_name_jam_unique", text("lower(name)"), "jam_id", unique=True),)
7167

7268

7369
class Winner(Base):
7470
"""A user who has won a code jam."""
7571

7672
__tablename__ = "winners"
77-
__table_args__ = (
78-
PrimaryKeyConstraint('jam_id', 'user_id'),
79-
)
73+
__table_args__ = (PrimaryKeyConstraint("jam_id", "user_id"),)
8074

8175
jam_id = Column(ForeignKey("jams.id"), nullable=False)
8276
user_id = Column(ForeignKey("users.id"), nullable=False)

api/middleware.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class TokenAuthentication(AuthenticationBackend):
1515
def __init__(self, token: str) -> None:
1616
self.expected_auth_header = f"Token {token}"
1717

18-
async def authenticate(
19-
self, request: Request
20-
) -> tuple[AuthCredentials, SimpleUser]:
18+
async def authenticate(self, request: Request) -> tuple[AuthCredentials, SimpleUser]:
2119
"""Authenticate the request based on the Authorization header."""
2220
if Config.DEBUG:
2321
credentials = AuthCredentials(scopes=["debug"])

api/routers/codejams.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ async def get_codejams(session: AsyncSession = Depends(get_db_session)) -> list[
2424
@router.get(
2525
"/{codejam_id}",
2626
response_model=CodeJamResponse,
27-
responses={
28-
404: {
29-
"description": "CodeJam could not be found or there is no ongoing code jam."
30-
}
31-
}
27+
responses={404: {"description": "CodeJam could not be found or there is no ongoing code jam."}},
3228
)
3329
async def get_codejam(codejam_id: int, session: AsyncSession = Depends(get_db_session)) -> Jam:
3430
"""
@@ -37,9 +33,7 @@ async def get_codejam(codejam_id: int, session: AsyncSession = Depends(get_db_se
3733
Passing -1 as the codejam ID will return the ongoing codejam.
3834
"""
3935
if codejam_id == -1:
40-
ongoing_jams = (
41-
await session.execute(select(Jam).where(Jam.ongoing == True))
42-
).unique().scalars().all()
36+
ongoing_jams = (await session.execute(select(Jam).where(Jam.ongoing == True))).unique().scalars().all()
4337

4438
if not ongoing_jams:
4539
raise HTTPException(status_code=404, detail="There is no ongoing codejam.")
@@ -56,19 +50,12 @@ async def get_codejam(codejam_id: int, session: AsyncSession = Depends(get_db_se
5650
return jam
5751

5852

59-
@router.patch(
60-
"/{codejam_id}",
61-
responses={
62-
404: {
63-
"description": "Code Jam with specified ID does not exist."
64-
}
65-
}
66-
)
53+
@router.patch("/{codejam_id}", responses={404: {"description": "Code Jam with specified ID does not exist."}})
6754
async def modify_codejam(
6855
codejam_id: int,
6956
name: Optional[str] = None,
7057
ongoing: Optional[bool] = None,
71-
session: AsyncSession = Depends(get_db_session)
58+
session: AsyncSession = Depends(get_db_session),
7259
) -> None:
7360
"""Modify the specified codejam to change its name and/or whether it's the ongoing code jam."""
7461
codejam = await session.execute(select(Jam).where(Jam.id == codejam_id))
@@ -113,16 +100,19 @@ async def create_codejam(codejam: CodeJam, session: AsyncSession = Depends(get_d
113100
jam_id=jam.id,
114101
name=raw_team.name,
115102
discord_role_id=raw_team.discord_role_id,
116-
discord_channel_id=raw_team.discord_channel_id
103+
discord_channel_id=raw_team.discord_channel_id,
117104
)
118105
session.add(team)
119106
# Flush here to receive team ID
120107
await session.flush()
121108

122109
for raw_user in raw_team.users:
123-
if not (
124-
await session.execute(select(User).where(User.id == raw_user.user_id))
125-
).unique().scalars().one_or_none():
110+
if (
111+
not (await session.execute(select(User).where(User.id == raw_user.user_id)))
112+
.unique()
113+
.scalars()
114+
.one_or_none()
115+
):
126116
user = User(id=raw_user.user_id)
127117
session.add(user)
128118

api/routers/infractions.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ async def get_infractions(session: AsyncSession = Depends(get_db_session)) -> li
2222
@router.get(
2323
"/{infraction_id}",
2424
response_model=InfractionResponse,
25-
responses={
26-
404: {
27-
"description": "Infraction could not be found."
28-
}
29-
}
25+
responses={404: {"description": "Infraction could not be found."}},
3026
)
3127
async def get_infraction(infraction_id: int, session: AsyncSession = Depends(get_db_session)) -> DbInfraction:
3228
"""Get a specific infraction stored in the database by ID."""
@@ -40,13 +36,7 @@ async def get_infraction(infraction_id: int, session: AsyncSession = Depends(get
4036

4137

4238
@router.post(
43-
"/",
44-
response_model=InfractionResponse,
45-
responses={
46-
404: {
47-
"Description": "Jam ID or User ID could not be found."
48-
}
49-
}
39+
"/", response_model=InfractionResponse, responses={404: {"Description": "Jam ID or User ID could not be found."}}
5040
)
5141
async def create_infraction(infraction: Infraction, session: AsyncSession = Depends(get_db_session)) -> DbInfraction:
5242
"""Add an infraction for a user to the database."""
@@ -61,10 +51,7 @@ async def create_infraction(infraction: Infraction, session: AsyncSession = Depe
6151
raise HTTPException(404, "User with specified ID could not be found.")
6252

6353
infraction = DbInfraction(
64-
user_id=user_id,
65-
jam_id=jam_id,
66-
infraction_type=infraction.infraction_type,
67-
reason=infraction.reason
54+
user_id=user_id, jam_id=jam_id, infraction_type=infraction.infraction_type, reason=infraction.reason
6855
)
6956
session.add(infraction)
7057
await session.flush()

api/routers/teams.py

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,7 @@ async def get_teams(current_jam: bool = False, session: AsyncSession = Depends(g
4747
return teams.scalars().all()
4848

4949

50-
@router.get(
51-
"/find",
52-
response_model=TeamResponse,
53-
responses={
54-
404: {
55-
"description": "Team could not be found."
56-
}
57-
}
58-
)
50+
@router.get("/find", response_model=TeamResponse, responses={404: {"description": "Team could not be found."}})
5951
async def find_team_by_name(
6052
name: str, jam_id: Optional[int] = None, session: AsyncSession = Depends(get_db_session)
6153
) -> Team:
@@ -77,29 +69,13 @@ async def find_team_by_name(
7769
return team
7870

7971

80-
@router.get(
81-
"/{team_id}",
82-
response_model=TeamResponse,
83-
responses={
84-
404: {
85-
"description": "Team could not be found."
86-
}
87-
}
88-
)
72+
@router.get("/{team_id}", response_model=TeamResponse, responses={404: {"description": "Team could not be found."}})
8973
async def get_team(team_id: int, session: AsyncSession = Depends(get_db_session)) -> Team:
9074
"""Get a specific code jam team in the database by ID."""
9175
return await ensure_team_exists(team_id, session)
9276

9377

94-
@router.get(
95-
"/{team_id}/users",
96-
response_model=list[User],
97-
responses={
98-
404: {
99-
"description": "Team could not be found."
100-
}
101-
}
102-
)
78+
@router.get("/{team_id}/users", response_model=list[User], responses={404: {"description": "Team could not be found."}})
10379
async def get_team_users(team_id: int, session: AsyncSession = Depends(get_db_session)) -> list[TeamUser]:
10480
"""Get the users of a specific code jam team in the database."""
10581
await ensure_team_exists(team_id, session)
@@ -117,10 +93,8 @@ async def get_team_users(team_id: int, session: AsyncSession = Depends(get_db_se
11793
404: {
11894
"description": "Team or user could not be found.",
11995
},
120-
400: {
121-
"description": "This user is already on the team."
122-
}
123-
}
96+
400: {"description": "This user is already on the team."},
97+
},
12498
)
12599
async def add_user_to_team(
126100
team_id: int, user_id: int, is_leader: bool = False, session: AsyncSession = Depends(get_db_session)
@@ -151,10 +125,8 @@ async def add_user_to_team(
151125
404: {
152126
"description": "Team or user could not be found.",
153127
},
154-
400: {
155-
"description": "This user is not on this team."
156-
}
157-
}
128+
400: {"description": "This user is not on this team."},
129+
},
158130
)
159131
async def remove_user_from_team(
160132
team_id: int, user_id: int, session: AsyncSession = Depends(get_db_session)

api/routers/users.py

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ async def get_user_data(session: AsyncSession, user_id: int) -> dict[str, Any]:
3333

3434
participation_history.append(
3535
{
36-
"jam_id": user_team.team.jam.id, "top_10": top_10, "first_place": first_place,
37-
"team_id": user_team.team.id, "is_leader": user_team.is_leader, "infractions": infractions
36+
"jam_id": user_team.team.jam.id,
37+
"top_10": top_10,
38+
"first_place": first_place,
39+
"team_id": user_team.team.id,
40+
"is_leader": user_team.is_leader,
41+
"infractions": infractions,
3842
}
3943
)
4044

@@ -52,15 +56,7 @@ async def get_users(session: AsyncSession = Depends(get_db_session)) -> list[dic
5256
return [await get_user_data(session, user) for user in users.scalars().all()]
5357

5458

55-
@router.get(
56-
"/{user_id}",
57-
response_model=UserResponse,
58-
responses={
59-
404: {
60-
"description": "User could not be found."
61-
}
62-
}
63-
)
59+
@router.get("/{user_id}", response_model=UserResponse, responses={404: {"description": "User could not be found."}})
6460
async def get_user(user_id: int, session: AsyncSession = Depends(get_db_session)) -> dict[str, Any]:
6561
"""Get a specific user stored in the database by ID."""
6662
user = await session.execute(select(User).where(User.id == user_id))
@@ -72,15 +68,7 @@ async def get_user(user_id: int, session: AsyncSession = Depends(get_db_session)
7268
return await get_user_data(session, user_id)
7369

7470

75-
@router.post(
76-
"/{user_id}",
77-
response_model=UserResponse,
78-
responses={
79-
400: {
80-
"description": "User already exists."
81-
}
82-
}
83-
)
71+
@router.post("/{user_id}", response_model=UserResponse, responses={400: {"description": "User already exists."}})
8472
async def create_user(user_id: int, session: AsyncSession = Depends(get_db_session)) -> dict[str, Any]:
8573
"""Create a new user with the specified ID to the database."""
8674
user = await session.execute(select(User).where(User.id == user_id))
@@ -102,12 +90,10 @@ async def create_user(user_id: int, session: AsyncSession = Depends(get_db_sessi
10290
responses={
10391
404: {
10492
"description": (
105-
"User not found, "
106-
"there is no ongoing code jam or "
107-
"user isn't participating in current code jam."
93+
"User not found, " "there is no ongoing code jam or " "user isn't participating in current code jam."
10894
)
10995
}
110-
}
96+
},
11197
)
11298
async def get_current_team(user_id: int, session: AsyncSession = Depends(get_db_session)) -> dict[str, Any]:
11399
"""Get a user's current team information."""
@@ -117,16 +103,12 @@ async def get_current_team(user_id: int, session: AsyncSession = Depends(get_db_
117103
if not user.scalars().one_or_none():
118104
raise HTTPException(status_code=404, detail="User with specified ID could not be found.")
119105

120-
ongoing_jam = (
121-
await session.execute(select(Jam).where(Jam.ongoing == True))
122-
).unique().scalars().one_or_none()
106+
ongoing_jam = (await session.execute(select(Jam).where(Jam.ongoing == True))).unique().scalars().one_or_none()
123107

124108
if not ongoing_jam:
125109
raise HTTPException(status_code=404, detail="There is no ongoing codejam.")
126110

127-
user_teams = (
128-
await session.execute(select(TeamUser).where(TeamUser.user_id == user_id))
129-
).unique().scalars().all()
111+
user_teams = (await session.execute(select(TeamUser).where(TeamUser.user_id == user_id))).unique().scalars().all()
130112

131113
current_team = None
132114
for user_team in user_teams:
@@ -135,9 +117,6 @@ async def get_current_team(user_id: int, session: AsyncSession = Depends(get_db_
135117
break
136118

137119
if not current_team:
138-
raise HTTPException(
139-
status_code=404,
140-
detail="User with specified ID isn't participating in ongoing codejam."
141-
)
120+
raise HTTPException(status_code=404, detail="User with specified ID isn't participating in ongoing codejam.")
142121

143122
return current_team

api/routers/winners.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
@router.get(
1515
"/{jam_id}",
1616
response_model=list[WinnerResponse],
17-
responses={
18-
404: {
19-
"description": "The specified codejam could not be found."
20-
}
21-
}
17+
responses={404: {"description": "The specified codejam could not be found."}},
2218
)
2319
async def get_winners(jam_id: int, session: AsyncSession = Depends(get_db_session)) -> list[DbWinner]:
2420
"""Get the top ten winners from the specified codejam."""
@@ -37,16 +33,12 @@ async def get_winners(jam_id: int, session: AsyncSession = Depends(get_db_sessio
3733
"/{jam_id}",
3834
response_model=list[WinnerResponse],
3935
responses={
40-
400: {
41-
"description": "The provided winners list is empty or contains duplicate users."
42-
},
36+
400: {"description": "The provided winners list is empty or contains duplicate users."},
4337
404: {
4438
"description": "The codejam or one of the users provided could not be found.",
4539
},
46-
409: {
47-
"description": "One or more users are already a winner in the specified codejam."
48-
}
49-
}
40+
409: {"description": "One or more users are already a winner in the specified codejam."},
41+
},
5042
)
5143
async def create_winners(
5244
jam_id: int, winners: list[Winner], session: AsyncSession = Depends(get_db_session)

migrations/env.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ def run_migrations_offline() -> None:
5050
def do_run_migrations(connection: AsyncConnection):
5151
"""Run all migrations on the given connection."""
5252
context.configure(
53-
connection=connection,
54-
target_metadata=target_metadata,
55-
compare_type=True,
56-
compare_server_default=True
53+
connection=connection, target_metadata=target_metadata, compare_type=True, compare_server_default=True
5754
)
5855

5956
with context.begin_transaction():

0 commit comments

Comments
 (0)