Skip to content

Commit 3e913c2

Browse files
authored
WEB: Sort PDEPs by their number (#52072)
* WEB: Sort PDEPs by their number * change regex string and call match method on compiled pattern * WEB: add exception handling when title is missing number * WEB: parameter to sort_pdep should be a dict. Change func parameter type to dict * move pattern into function call, less verbose
1 parent 64c1e5e commit 3e913c2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

web/pandas_web.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,19 @@ def roadmap_pdeps(context):
317317
) as f:
318318
json.dump(pdeps, f)
319319

320-
for pdep in sorted(pdeps["items"], key=operator.itemgetter("title")):
320+
compiled_pattern = re.compile(r"^PDEP-(\d+)")
321+
322+
def sort_pdep(pdep: dict) -> int:
323+
title = pdep["title"]
324+
match = compiled_pattern.match(title)
325+
if not match:
326+
msg = f"""Could not find PDEP number in '{title}'. Please make sure to
327+
write the title as: 'PDEP-num: {title}'."""
328+
raise ValueError(msg)
329+
330+
return int(match[1])
331+
332+
for pdep in sorted(pdeps["items"], key=sort_pdep):
321333
context["pdeps"]["Under discussion"].append(
322334
{"title": pdep["title"], "url": pdep["html_url"]}
323335
)

0 commit comments

Comments
 (0)