Skip to content

Commit 1ab4f5e

Browse files
Update default of Slack View and more linting fixes (#393)
1 parent dd20f12 commit 1ab4f5e

File tree

12 files changed

+1586
-1601
lines changed

12 files changed

+1586
-1601
lines changed

modules/airtable/daily_programmer_table.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,58 @@
1010
logger = logging.getLogger(__name__)
1111

1212

13-
class DailyProgrammerTable(BaseAirtableTable): # noqa: D101
14-
def __init__(self): # noqa: ANN101, ANN204, D107
13+
class DailyProgrammerTable(BaseAirtableTable):
14+
"""Airtable table for the daily programmer channel."""
15+
16+
def __init__(self: "DailyProgrammerTable") -> None:
17+
"""Initialize the daily programmer table."""
1518
super().__init__("Daily Programmer")
1619

1720
@staticmethod
18-
def parse_daily_programmer_row(row: dict[str, Any]) -> DailyProgrammerInfo: # noqa: D102
21+
def parse_daily_programmer_row(row: dict[str, Any]) -> DailyProgrammerInfo:
22+
"""Parse a daily programmer row.
23+
24+
:param row: The row to parse.
25+
:return: The parsed row.
26+
"""
1927
fields = {snake_case(k): v for k, v in row["fields"].items()}
2028
try:
2129
return DailyProgrammerInfo(
2230
**fields,
2331
airtable_id=row["id"],
2432
created_at=row["createdTime"],
2533
)
26-
except ValidationError as valid_e:
27-
raise valid_e # noqa: TRY201
34+
except ValidationError:
35+
logger.exception("Unable to parse daily programmer row.", extra={"row": row})
36+
raise
2837

29-
def retrieve_valid_daily_programmer_row_by_slug( # noqa: D102
30-
self, # noqa: ANN101
38+
def retrieve_valid_daily_programmer_row_by_slug(
39+
self: "DailyProgrammerTable",
3140
slug: str,
3241
) -> DailyProgrammerInfo:
42+
"""Retrieve a valid daily programmer row by slug.
43+
44+
:param slug: The slug to match.
45+
:return: The parsed row.
46+
"""
3347
return self.parse_daily_programmer_row(
3448
self.first(
3549
formula=f"{{Slug}} = '{slug}'",
3650
view="Valid",
3751
),
3852
)
3953

40-
def retrieve_valid_daily_programmer_by_view( # noqa: D102
41-
self, # noqa: ANN101
54+
def retrieve_valid_daily_programmer_by_view(
55+
self: "DailyProgrammerTable",
4256
view_name: str,
4357
) -> dict[str, DailyProgrammerInfo]:
58+
"""Retrieve all valid daily programmer rows by view.
59+
60+
:param view_name: The view name to retrieve messages from.
61+
:return: The dictionary of messages.
62+
"""
4463
logger.info("STAGE: Retrieving daily programmer rows by view")
45-
logger.debug(f"With view_name: {view_name}") # noqa: G004
64+
logger.info("With view_name", extra={"view_name": view_name})
4665
messages = {}
4766
for row in self.all(view=view_name):
4867
parsed_row = self.parse_daily_programmer_row(row)

modules/airtable/mentorship_tables.py

Lines changed: 109 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,25 @@
2222
class MentorshipAffiliationsTable(BaseAirtableTable):
2323
"""Airtable table for the mentorship affiliations table."""
2424

25-
def __init__(self) -> None: # noqa: ANN101, D107
25+
def __init__(self: "MentorshipAffiliationsTable") -> None:
26+
"""Initialize the mentorship affiliations table."""
2627
super().__init__("Affiliations")
2728

2829
@cached_property
29-
def valid_affiliations(self) -> list[MentorshipAffiliation]: # noqa: ANN101
30+
def valid_affiliations(self: "MentorshipAffiliationsTable") -> list[MentorshipAffiliation]:
3031
"""Return the valid affiliations from the table.
3132
3233
:return: A list of valid affiliations.
3334
"""
3435
return [self.parse_affiliation_row(row) for row in self.all(view="Valid")]
3536

3637
@staticmethod
37-
def parse_affiliation_row(row: dict[str, Any]) -> MentorshipAffiliation: # noqa: D102
38+
def parse_affiliation_row(row: dict[str, Any]) -> MentorshipAffiliation:
39+
"""Parse an affiliation row.
40+
41+
:param row: The row to parse.
42+
:return: The parsed affiliation row.
43+
"""
3844
fields = {snake_case(k): v for k, v in row["fields"].items()}
3945
try:
4046
return MentorshipAffiliation(
@@ -47,75 +53,97 @@ def parse_affiliation_row(row: dict[str, Any]) -> MentorshipAffiliation: # noqa
4753
raise validation_exception from validation_exception
4854

4955

50-
class MentorshipMentorsTable(BaseAirtableTable): # noqa: D101
51-
def __init__(self): # noqa: ANN101, ANN204, D107
56+
class MentorshipMentorsTable(BaseAirtableTable):
57+
"""Table containing the mentors who have signed up to mentor others."""
58+
59+
def __init__(self: "MentorshipMentorsTable") -> None:
60+
"""Initialize the mentorship mentors table."""
5261
super().__init__("Mentors")
5362

5463
@cached_property
55-
def valid_mentors(self) -> list[Mentor]: # noqa: ANN101
64+
def valid_mentors(self: "MentorshipMentorsTable") -> list[Mentor]:
5665
"""Returns the mentors from the table sorted by row ID.
5766
5867
:return: list of mentors
59-
:rtype: list[Mentor]
6068
"""
6169
try:
6270
return [self.parse_mentor_row(row) for row in self.all(view="Valid")]
63-
except ValidationError as valid_e:
64-
raise valid_e # noqa: TRY201
71+
except ValidationError:
72+
logger.exception("Unable to retrieve the list of mentors")
73+
raise
6574

6675
@staticmethod
67-
def parse_mentor_row(row: dict[str, Any]) -> Mentor: # noqa: D102
76+
def parse_mentor_row(row: dict[str, Any]) -> Mentor:
77+
"""Parse a mentor row.
78+
79+
:param row: The row to parse.
80+
:return: The parsed row.
81+
"""
6882
fields = {snake_case(k): v for k, v in row["fields"].items()}
6983
try:
7084
return Mentor(
7185
**fields,
7286
airtable_id=row["id"],
7387
created_at=row["createdTime"],
7488
)
75-
except ValidationError as valid_e:
76-
raise valid_e # noqa: TRY201
89+
except ValidationError:
90+
logger.exception("Unable to parse mentor row.", extra={"row": row})
91+
raise
7792

7893

79-
class MentorshipSkillsetsTable(BaseAirtableTable): # noqa: D101
80-
def __init__(self): # noqa: ANN101, ANN204, D107
94+
class MentorshipSkillsetsTable(BaseAirtableTable):
95+
"""Airtable table for the mentorship skillsets table."""
96+
97+
def __init__(self: "MentorshipSkillsetsTable") -> None:
98+
"""Initialize the mentorship skillsets table."""
8199
super().__init__("Skillsets")
82100

83101
@cached_property
84-
def valid_skillsets(self) -> list[MentorshipSkillset]: # noqa: ANN101
102+
def valid_skillsets(self: "MentorshipSkillsetsTable") -> list[MentorshipSkillset]:
85103
"""Returns the skillsets from the table.
86104
87-
:return: list of skillsets
88-
:rtype: list[MentorshipSkillset]
105+
:return: The list of skillsets.
89106
"""
90107
try:
91108
return [self.parse_skillset_row(row) for row in self.all(view="Valid")]
92-
except ValidationError as valid_e:
93-
raise valid_e # noqa: TRY201
109+
except ValidationError:
110+
logger.exception("Unable to retrieve the list of skillsets")
111+
raise
94112

95113
@cached_property
96-
def mentors_by_skillsets(self) -> dict[str, str]: # noqa: ANN101, D102
114+
def mentors_by_skillsets(self: "MentorshipSkillsetsTable") -> dict[str, str]:
115+
"""Returns the mentors by skillset.
116+
117+
:return: The mentors by skillset.
118+
"""
97119
try:
98120
mentors_by_skillset = {}
99121
for row in self.all(fields=["Name", "Mentors"], view="Valid"):
100122
mentors_by_skillset[row["Name"]] = row["Mentors"]
101123
return mentors_by_skillset # noqa: TRY300
102-
except Exception as e:
103-
logger.warning(f"Issue retrieving mentor IDs by skillset: {e}") # noqa: G004
104-
raise e # noqa: TRY201
124+
except Exception:
125+
logger.exception("Issue retrieving mentor IDs by skillset")
126+
raise
105127

106128
@staticmethod
107-
def parse_skillset_row(row: dict[str, Any]) -> MentorshipSkillset: # noqa: D102
129+
def parse_skillset_row(row: dict[str, Any]) -> MentorshipSkillset:
130+
"""Parse a skillset row.
131+
132+
:param row: The row to parse.
133+
:return: The parsed row.
134+
"""
108135
fields = {snake_case(k): v for k, v in row["fields"].items()}
109136
try:
110137
return MentorshipSkillset(
111138
**fields,
112139
airtable_id=row["id"],
113140
created_at=row["createdTime"],
114141
)
115-
except ValidationError as valid_e:
116-
raise valid_e # noqa: TRY201
142+
except ValidationError:
143+
logger.exception("Unable to parse skillset row.", extra={"row": row})
144+
raise
117145

118-
def mentors_by_skillset(self, skillsets_to_search: list[str]) -> set[str]: # noqa: ANN101
146+
def mentors_by_skillset(self: "MentorshipSkillsetsTable", skillsets_to_search: list[str]) -> set[str]:
119147
"""Retrieve mentor IDs by skillset.
120148
121149
:param skillsets_to_search: The skillsets to search for.
@@ -134,78 +162,106 @@ def mentors_by_skillset(self, skillsets_to_search: list[str]) -> set[str]: # no
134162
mentors.append(
135163
row["fields"]["Mentors"] if row["fields"]["Mentors"] else [],
136164
)
137-
except KeyError as key_e:
138-
logger.warning(f"Key error intercepted: {key_e}") # noqa: G004
165+
except KeyError:
166+
logger.exception("Key error intercepted retrieving mentors by skillset", extra={"row": row})
139167
pass
140168

141169
# Flatten the array and get unique values
142170
return set(chain(*mentors))
143-
except Exception as e:
171+
except Exception:
144172
logger.exception(
145173
"Issue retrieving mentor IDs with particular skillsets",
146-
extra={"error": e, "skillsets": skillsets_to_search},
174+
extra={"skillsets": skillsets_to_search},
147175
)
148-
raise e from e
176+
raise
149177

150178

151-
class MentorshipServicesTable(BaseAirtableTable): # noqa: D101
152-
def __init__(self): # noqa: ANN101, ANN204, D107
179+
class MentorshipServicesTable(BaseAirtableTable):
180+
"""Airtable table for the mentorship services table."""
181+
182+
def __init__(self: "MentorshipServicesTable") -> None:
183+
"""Initialize the mentorship services table."""
153184
super().__init__("Services")
154185

155186
@cached_property
156-
def valid_services(self) -> list[MentorshipService]: # noqa: ANN101
187+
def valid_services(self: "MentorshipServicesTable") -> list[MentorshipService]:
157188
"""Returns the services from the table.
158189
159-
:return: list of services from the table
160-
:rtype: list[MentorshipService]
190+
:return: The list of services from the table.
161191
"""
162192
try:
163193
return [self.parse_service_row(row) for row in self.all(view="Valid")]
164-
except ValidationError as valid_e:
165-
raise valid_e # noqa: TRY201
194+
except ValidationError:
195+
logger.exception("Unable to retrieve the list of services")
196+
raise
166197

167198
@staticmethod
168-
def parse_service_row(row: dict[str, Any]) -> MentorshipService: # noqa: D102
199+
def parse_service_row(row: dict[str, Any]) -> MentorshipService:
200+
"""Parse a service row.
201+
202+
:param row: The row to parse.
203+
:return: The parsed row.
204+
"""
169205
fields = {snake_case(k): v for k, v in row["fields"].items()}
170206
try:
171207
return MentorshipService(
172208
**fields,
173209
airtable_id=row["id"],
174210
created_at=row["createdTime"],
175211
)
176-
except ValidationError as valid_e:
177-
raise valid_e # noqa: TRY201
212+
except ValidationError:
213+
logger.exception("Unable to parse service row.", extra={"row": row})
214+
raise
215+
178216

217+
class MentorshipRequestsTable(BaseAirtableTable):
218+
"""Airtable table for the mentorship requests table."""
179219

180-
class MentorshipRequestsTable(BaseAirtableTable): # noqa: D101
181-
def __init__(self): # noqa: ANN101, ANN204, D107
220+
def __init__(self: "MentorshipRequestsTable") -> None:
221+
"""Initialize the mentorship requests table."""
182222
super().__init__("Mentor Requests")
183223

184224
@cached_property
185-
def valid_services(self) -> list[MentorshipRequest]: # noqa: ANN101
225+
def valid_services(self: "MentorshipRequestsTable") -> list[MentorshipRequest]:
186226
"""Returns the services from the table.
187227
188228
:return: list of services from the table
189-
:rtype: list[MentorshipService]
190229
"""
191230
try:
192231
return [self.parse_request_row(row) for row in self.all(view="Valid")]
193-
except ValidationError as valid_e:
194-
raise valid_e # noqa: TRY201
232+
except ValidationError:
233+
logger.exception("Unable to retrieve the list of requests")
234+
raise
195235

196236
@staticmethod
197-
def parse_request_row(row: dict[str, Any]) -> MentorshipRequest: # noqa: D102
237+
def parse_request_row(row: dict[str, Any]) -> MentorshipRequest:
238+
"""Parse a request row.
239+
240+
:param row: The row to parse.
241+
:return: The parsed row.
242+
"""
198243
fields = {snake_case(k): v for k, v in row["fields"].items()}
199244
try:
200245
return MentorshipRequest(
201246
**fields,
202247
airtable_id=row["id"],
203248
created_at=row["createdTime"],
204249
)
205-
except ValidationError as valid_e:
206-
raise valid_e # noqa: TRY201
250+
except ValidationError:
251+
logger.exception("Unable to parse request row.", extra={"row": row})
252+
raise
207253

208-
def return_record_by_slack_message_ts(self, timestamp: str) -> MentorshipRequest: # noqa: ANN101, D102
254+
def return_record_by_slack_message_ts(self: "MentorshipRequestsTable", timestamp: str) -> MentorshipRequest:
255+
"""Return a specific record by the recorded timestamp.
256+
257+
:param timestamp: The timestamp to use to find the record.
258+
:return: The mentorship request found with the timestamp.
259+
"""
260+
logger.info("Returning record using timestamp", extra={"timestamp": timestamp})
209261
row = self.first(formula=f"{{Slack Message TS}} = '{timestamp}'")
210-
logger.debug(f"Returned row: {row}") # noqa: G004
262+
if not row:
263+
logger.error("Unable to find record", extra={"timestamp": timestamp})
264+
error_message = f"Unable to find record with timestamp {timestamp}"
265+
raise ValueError(error_message)
266+
logger.info("Found record", extra={"row": row})
211267
return self.parse_request_row(row)

0 commit comments

Comments
 (0)