From 91c1ff31e8c31f7d941dc809e8b0452b1118636f Mon Sep 17 00:00:00 2001 From: Kostya Farber Date: Sun, 19 Mar 2023 14:28:35 +0000 Subject: [PATCH 1/5] WEB: Sort PDEPs by their number --- web/pandas_web.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web/pandas_web.py b/web/pandas_web.py index d1f06b6fdfa43..401e9068e626d 100755 --- a/web/pandas_web.py +++ b/web/pandas_web.py @@ -307,7 +307,10 @@ def roadmap_pdeps(context): with open(pathlib.Path(context["target_path"]) / "pdeps.json", "w") as f: json.dump(pdeps, f) - for pdep in sorted(pdeps["items"], key=operator.itemgetter("title")): + regex = "(?<=PDEP-)\\d+" + compiled_pattern = re.compile(regex) + get_num = lambda pdep: int(re.findall(compiled_pattern, pdep["title"])[0]) + for pdep in sorted(pdeps["items"], key=get_num): context["pdeps"]["Under discussion"].append( {"title": pdep["title"], "url": pdep["html_url"]} ) From a862ffc9e783fb1bee9eb050e01606b823045a71 Mon Sep 17 00:00:00 2001 From: Kostya Farber Date: Tue, 21 Mar 2023 09:42:59 +0000 Subject: [PATCH 2/5] change regex string and call match method on compiled pattern --- web/pandas_web.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/pandas_web.py b/web/pandas_web.py index e1adfa7593f6e..116174b8553dc 100755 --- a/web/pandas_web.py +++ b/web/pandas_web.py @@ -307,9 +307,9 @@ def roadmap_pdeps(context): with open(pathlib.Path(context["target_path"]) / "pdeps.json", "w") as f: json.dump(pdeps, f) - regex = "(?<=PDEP-)\\d+" + regex = r"^PDEP-(\d+)" compiled_pattern = re.compile(regex) - get_num = lambda pdep: int(re.findall(compiled_pattern, pdep["title"])[0]) + get_num = lambda pdep: int(compiled_pattern.match(pdep["title"])[1]) for pdep in sorted(pdeps["items"], key=get_num): context["pdeps"]["Under discussion"].append( {"title": pdep["title"], "url": pdep["html_url"]} From 887523cbfddccf1e3e65cbe15953be42f91e2f04 Mon Sep 17 00:00:00 2001 From: Kostya Farber Date: Sat, 29 Apr 2023 21:52:18 +0100 Subject: [PATCH 3/5] WEB: add exception handling when title is missing number --- web/pandas_web.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/web/pandas_web.py b/web/pandas_web.py index 116174b8553dc..9f24036b6a2b7 100755 --- a/web/pandas_web.py +++ b/web/pandas_web.py @@ -309,8 +309,18 @@ def roadmap_pdeps(context): regex = r"^PDEP-(\d+)" compiled_pattern = re.compile(regex) - get_num = lambda pdep: int(compiled_pattern.match(pdep["title"])[1]) - for pdep in sorted(pdeps["items"], key=get_num): + + def sort_pdep(pdep: str) -> int: + title = pdep["title"] + match = compiled_pattern.match(title) + if not match: + msg = f"""Could not find PDEP number in '{title}'. Please make sure to + write the title as: 'PDEP-num: {title}'.""" + raise ValueError(msg) + + return int(match[1]) + + for pdep in sorted(pdeps["items"], key=sort_pdep): context["pdeps"]["Under discussion"].append( {"title": pdep["title"], "url": pdep["html_url"]} ) From 38bbf292f3431005f150a2afd5d44070c86a9505 Mon Sep 17 00:00:00 2001 From: Kostya Farber Date: Sat, 29 Apr 2023 22:02:03 +0100 Subject: [PATCH 4/5] WEB: parameter to sort_pdep should be a dict. Change func parameter type to dict --- web/pandas_web.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/pandas_web.py b/web/pandas_web.py index 9f24036b6a2b7..635c82877d076 100755 --- a/web/pandas_web.py +++ b/web/pandas_web.py @@ -310,7 +310,7 @@ def roadmap_pdeps(context): regex = r"^PDEP-(\d+)" compiled_pattern = re.compile(regex) - def sort_pdep(pdep: str) -> int: + def sort_pdep(pdep: dict) -> int: title = pdep["title"] match = compiled_pattern.match(title) if not match: From 6015df3124458e79f93e8e16c237b95db9a030af Mon Sep 17 00:00:00 2001 From: Kostya Farber Date: Tue, 9 May 2023 08:32:03 +0100 Subject: [PATCH 5/5] move pattern into function call, less verbose --- web/pandas_web.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/web/pandas_web.py b/web/pandas_web.py index 84f751e15e3b6..7348ac43c81de 100755 --- a/web/pandas_web.py +++ b/web/pandas_web.py @@ -317,8 +317,7 @@ def roadmap_pdeps(context): ) as f: json.dump(pdeps, f) - regex = r"^PDEP-(\d+)" - compiled_pattern = re.compile(regex) + compiled_pattern = re.compile(r"^PDEP-(\d+)") def sort_pdep(pdep: dict) -> int: title = pdep["title"]