From 3b2b5978253977fb59564cfa83c1bb2bd454f7d6 Mon Sep 17 00:00:00 2001 From: Arnau Casau Date: Wed, 5 Jun 2024 16:03:19 +0200 Subject: [PATCH 01/13] Add script to update all non-API links to guides/ --- scripts/patterns-reorg/deleted_entries.py | 7 ++ scripts/patterns-reorg/main.py | 2 + scripts/patterns-reorg/models.py | 23 +++++- scripts/patterns-reorg/redirects.json | 10 ++- .../patterns-reorg/update_internal_links.py | 71 +++++++++++++++++++ 5 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 scripts/patterns-reorg/deleted_entries.py create mode 100755 scripts/patterns-reorg/update_internal_links.py diff --git a/scripts/patterns-reorg/deleted_entries.py b/scripts/patterns-reorg/deleted_entries.py new file mode 100644 index 00000000000..77227bf4f13 --- /dev/null +++ b/scripts/patterns-reorg/deleted_entries.py @@ -0,0 +1,7 @@ +from models import DeletedPage + +DELETED_PAGES = ( + DeletedPage(slug="map-problem-to-circuits", from_file="/build/index"), + DeletedPage(slug="execute-on-hardware", from_file="/run/index"), + DeletedPage(slug="", from_file="/start/index"), +) \ No newline at end of file diff --git a/scripts/patterns-reorg/main.py b/scripts/patterns-reorg/main.py index 8b4c92c588d..06572fd3358 100755 --- a/scripts/patterns-reorg/main.py +++ b/scripts/patterns-reorg/main.py @@ -20,6 +20,7 @@ from models import determine_redirects from entries import TOP_LEVEL_ENTRIES +from deleted_entries import DELETED_PAGES def write_guides_dir() -> None: @@ -43,6 +44,7 @@ def write_guides_dir() -> None: def write_redirects_file() -> None: fp = Path("scripts/patterns-reorg/redirects.json") redirects = determine_redirects(TOP_LEVEL_ENTRIES) + redirects.update(determine_redirects(DELETED_PAGES)) text = json.dumps(redirects, indent=2) + "\n" fp.write_text(text) diff --git a/scripts/patterns-reorg/models.py b/scripts/patterns-reorg/models.py index 3c1e37b87f3..23e5e1842d8 100644 --- a/scripts/patterns-reorg/models.py +++ b/scripts/patterns-reorg/models.py @@ -88,6 +88,12 @@ def entries_as_markdown_list( return "\n".join(result) +@dataclass(frozen=True) +class DeletedPage: + slug: str + from_file: str + + def filter_entries( entries: tuple[Entry, ...], *, ignore: set[Entry] ) -> tuple[Entry, ...]: @@ -103,12 +109,23 @@ def filter_entries( def determine_redirects( - entries: tuple[Entry, ...], *, prefix: str = "" + entries: tuple[Entry, ...] | tuple[DeletedPage, ...], *, prefix: str = "" ) -> dict[str, str]: result = {} for entry in entries: - if entry.slug and entry.from_file: + if entry.slug is not None and entry.from_file: old_url = str(PurePath(entry.from_file).with_suffix("")) result[old_url] = f"{prefix}{entry.slug}" - result.update(determine_redirects(entry.children)) + + # We need to add two links for each index entry because we can + # have two links possible. For example, `/run/index` and `/run/` + # point to the same page. + old_url_split = old_url.split('/') + old_file_name = old_url_split[-1] + old_folder = old_url_split[-2] + if old_file_name == "index": + result[f"{old_folder}/"] = f"{prefix}{entry.slug}" + + if type(entry) is Entry: + result.update(determine_redirects(entry.children)) return result diff --git a/scripts/patterns-reorg/redirects.json b/scripts/patterns-reorg/redirects.json index ac7c89b172c..28c3514f3a1 100644 --- a/scripts/patterns-reorg/redirects.json +++ b/scripts/patterns-reorg/redirects.json @@ -18,6 +18,7 @@ "build/interoperate-qiskit-qasm3": "interoperate-qiskit-qasm3", "build/qasm-feature-table": "qasm-feature-table", "transpile/index": "transpile", + "transpile/": "transpile", "transpile/transpiler-stages": "transpiler-stages", "transpile/transpile-with-pass-managers": "transpile-with-pass-managers", "transpile/defaults-and-configuration-options": "defaults-and-configuration-options", @@ -32,6 +33,7 @@ "transpile/qiskit-transpiler-service": "qiskit-transpiler-service", "transpile/ai-transpiler-passes": "ai-transpiler-passes", "verify/index": "verify", + "verify/": "verify", "verify/simulate-with-qiskit-primitives": "simulate-with-qiskit-sdk-primitives", "verify/simulate-with-qiskit-aer": "simulate-with-qiskit-aer", "verify/local-testing-mode": "local-testing-mode", @@ -65,5 +67,11 @@ "build/circuit-visualization": "circuit-visualization", "verify/plot-quantum-states": "plot-quantum-states", "run/visualize-results": "visualize-results", - "run/quantum-serverless": "qiskit-serverless" + "run/quantum-serverless": "qiskit-serverless", + "/build/index": "map-problem-to-circuits", + "build/": "map-problem-to-circuits", + "/run/index": "execute-on-hardware", + "run/": "execute-on-hardware", + "/start/index": "", + "start/": "" } diff --git a/scripts/patterns-reorg/update_internal_links.py b/scripts/patterns-reorg/update_internal_links.py new file mode 100755 index 00000000000..35ed7a767c9 --- /dev/null +++ b/scripts/patterns-reorg/update_internal_links.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3.11 + +# This code is a Qiskit project. +# +# (C) Copyright IBM 2024. +# +# This code is licensed under the Apache License, Version 2.0. You may obtain a +# copy of this license in the LICENSE file in the root directory of this source +# tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this copyright +# notice, and modified files need to carry a notice indicating that they have +# been altered from the originals. + +from __future__ import annotations + +import re +import json +from pathlib import Path +import os +import glob + +def get_redirects(json_path: str)-> dict[str, str]: + dir_path = os.path.dirname(os.path.realpath(__file__)) + with open(f"{dir_path}/{json_path}") as redirects_file: + return json.load(redirects_file) + + +def update_link(markdown: str, folder: str, link: str, redirects: dict[str, str])-> str: + anchor_index = link.find("#") + + if link.startswith("http") or anchor_index == 0: + return markdown + + if anchor_index == -1: + link_without_anchor = link + anchor = "" + else: + link_without_anchor = link[:anchor_index] + anchor = link[anchor_index:] + + link_split = link_without_anchor.split('/') + if link_without_anchor.startswith("/") or link_without_anchor.startswith("../"): + search_key = f"{link_split[-2]}/{link_split[-1]}" + else: + search_key = f"{folder}/{link_split[-1]}" + + if search_key in redirects: + new_link = redirects[search_key] + if new_link == "": + new_link = "/guides/" + return markdown.replace(markdown, markdown.replace(link, f"{new_link}{anchor}")) + + return markdown + + +def main() -> None: + inline_link_re = re.compile(r'\[([^\]]+)\]\(([^)]+)\)') + folders = ["build", "run", "start", "transpile", "verify"] + redirects = get_redirects("redirects.json") + + for folder in folders: + for file_path in glob.glob(f"docs/{folder}/*"): + file = Path(file_path) + markdown = file.read_text() + markdown = re.sub(inline_link_re, lambda m: update_link(m[0], folder, m[2], redirects), markdown) + file.write_text(markdown) + + +if __name__ == "__main__": + main() From 474c5652177f7fe2275914771fb718fe639e0b4d Mon Sep 17 00:00:00 2001 From: Arnau Casau Date: Wed, 5 Jun 2024 16:08:10 +0200 Subject: [PATCH 02/13] new line and use link --- scripts/patterns-reorg/deleted_entries.py | 2 +- scripts/patterns-reorg/update_internal_links.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/patterns-reorg/deleted_entries.py b/scripts/patterns-reorg/deleted_entries.py index 77227bf4f13..3a0a45b886c 100644 --- a/scripts/patterns-reorg/deleted_entries.py +++ b/scripts/patterns-reorg/deleted_entries.py @@ -4,4 +4,4 @@ DeletedPage(slug="map-problem-to-circuits", from_file="/build/index"), DeletedPage(slug="execute-on-hardware", from_file="/run/index"), DeletedPage(slug="", from_file="/start/index"), -) \ No newline at end of file +) diff --git a/scripts/patterns-reorg/update_internal_links.py b/scripts/patterns-reorg/update_internal_links.py index 35ed7a767c9..c3be737ced2 100755 --- a/scripts/patterns-reorg/update_internal_links.py +++ b/scripts/patterns-reorg/update_internal_links.py @@ -40,7 +40,7 @@ def update_link(markdown: str, folder: str, link: str, redirects: dict[str, str] anchor = link[anchor_index:] link_split = link_without_anchor.split('/') - if link_without_anchor.startswith("/") or link_without_anchor.startswith("../"): + if link.startswith("/") or link.startswith("../"): search_key = f"{link_split[-2]}/{link_split[-1]}" else: search_key = f"{folder}/{link_split[-1]}" From b2737ea3946e89ed4bb6a6f2d670c9132bc257d7 Mon Sep 17 00:00:00 2001 From: Arnau Casau Date: Wed, 5 Jun 2024 18:11:07 +0200 Subject: [PATCH 03/13] remove new script --- .../patterns-reorg/update_internal_links.py | 71 ------------------- 1 file changed, 71 deletions(-) delete mode 100755 scripts/patterns-reorg/update_internal_links.py diff --git a/scripts/patterns-reorg/update_internal_links.py b/scripts/patterns-reorg/update_internal_links.py deleted file mode 100755 index c3be737ced2..00000000000 --- a/scripts/patterns-reorg/update_internal_links.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python3.11 - -# This code is a Qiskit project. -# -# (C) Copyright IBM 2024. -# -# This code is licensed under the Apache License, Version 2.0. You may obtain a -# copy of this license in the LICENSE file in the root directory of this source -# tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this copyright -# notice, and modified files need to carry a notice indicating that they have -# been altered from the originals. - -from __future__ import annotations - -import re -import json -from pathlib import Path -import os -import glob - -def get_redirects(json_path: str)-> dict[str, str]: - dir_path = os.path.dirname(os.path.realpath(__file__)) - with open(f"{dir_path}/{json_path}") as redirects_file: - return json.load(redirects_file) - - -def update_link(markdown: str, folder: str, link: str, redirects: dict[str, str])-> str: - anchor_index = link.find("#") - - if link.startswith("http") or anchor_index == 0: - return markdown - - if anchor_index == -1: - link_without_anchor = link - anchor = "" - else: - link_without_anchor = link[:anchor_index] - anchor = link[anchor_index:] - - link_split = link_without_anchor.split('/') - if link.startswith("/") or link.startswith("../"): - search_key = f"{link_split[-2]}/{link_split[-1]}" - else: - search_key = f"{folder}/{link_split[-1]}" - - if search_key in redirects: - new_link = redirects[search_key] - if new_link == "": - new_link = "/guides/" - return markdown.replace(markdown, markdown.replace(link, f"{new_link}{anchor}")) - - return markdown - - -def main() -> None: - inline_link_re = re.compile(r'\[([^\]]+)\]\(([^)]+)\)') - folders = ["build", "run", "start", "transpile", "verify"] - redirects = get_redirects("redirects.json") - - for folder in folders: - for file_path in glob.glob(f"docs/{folder}/*"): - file = Path(file_path) - markdown = file.read_text() - markdown = re.sub(inline_link_re, lambda m: update_link(m[0], folder, m[2], redirects), markdown) - file.write_text(markdown) - - -if __name__ == "__main__": - main() From 93c25aa88c8b2f0250a1a231998ad0c0147c0b7d Mon Sep 17 00:00:00 2001 From: Arnau Casau Date: Wed, 5 Jun 2024 18:52:54 +0200 Subject: [PATCH 04/13] fix / on the redirects --- scripts/patterns-reorg/deleted_entries.py | 6 +++--- scripts/patterns-reorg/redirects.json | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/patterns-reorg/deleted_entries.py b/scripts/patterns-reorg/deleted_entries.py index 3a0a45b886c..0b408e9845a 100644 --- a/scripts/patterns-reorg/deleted_entries.py +++ b/scripts/patterns-reorg/deleted_entries.py @@ -1,7 +1,7 @@ from models import DeletedPage DELETED_PAGES = ( - DeletedPage(slug="map-problem-to-circuits", from_file="/build/index"), - DeletedPage(slug="execute-on-hardware", from_file="/run/index"), - DeletedPage(slug="", from_file="/start/index"), + DeletedPage(slug="/map-problem-to-circuits", from_file="build/index"), + DeletedPage(slug="/execute-on-hardware", from_file="run/index"), + DeletedPage(slug="", from_file="start/index"), ) diff --git a/scripts/patterns-reorg/redirects.json b/scripts/patterns-reorg/redirects.json index c23014591c8..0e229128397 100644 --- a/scripts/patterns-reorg/redirects.json +++ b/scripts/patterns-reorg/redirects.json @@ -68,10 +68,10 @@ "verify/plot-quantum-states": "plot-quantum-states", "run/visualize-results": "visualize-results", "run/quantum-serverless": "qiskit-serverless", - "/build/index": "map-problem-to-circuits", + "build/index": "map-problem-to-circuits", "build/": "map-problem-to-circuits", - "/run/index": "execute-on-hardware", + "run/index": "execute-on-hardware", "run/": "execute-on-hardware", - "/start/index": "", + "start/index": "", "start/": "" } From 4cffdcd979867df3cd00e2079abcf301625252b0 Mon Sep 17 00:00:00 2001 From: Arnau Casau <47946624+arnaucasau@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:53:31 +0200 Subject: [PATCH 05/13] Update scripts/patterns-reorg/models.py Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- scripts/patterns-reorg/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patterns-reorg/models.py b/scripts/patterns-reorg/models.py index 4629ec1c329..c8987d9162d 100644 --- a/scripts/patterns-reorg/models.py +++ b/scripts/patterns-reorg/models.py @@ -126,7 +126,7 @@ def determine_redirects( result[old_url] = f"{prefix}{entry.slug.removeprefix('/')}" # We need to add two links for each index entry because we can - # have two links possible. For example, `/run/index` and `/run/` + # have two links possible. For example, `/run/index` and `/run` # point to the same page. old_url_split = old_url.split('/') old_file_name = old_url_split[-1] From c8036912c207a7470e9f3480f8f4761b64206030 Mon Sep 17 00:00:00 2001 From: Arnau Casau <47946624+arnaucasau@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:53:44 +0200 Subject: [PATCH 06/13] Update scripts/patterns-reorg/models.py Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- scripts/patterns-reorg/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patterns-reorg/models.py b/scripts/patterns-reorg/models.py index c8987d9162d..0f1e7d14313 100644 --- a/scripts/patterns-reorg/models.py +++ b/scripts/patterns-reorg/models.py @@ -134,7 +134,7 @@ def determine_redirects( if old_file_name == "index": result[f"{old_folder}/"] = f"{prefix}{entry.slug.removeprefix('/')}" - if type(entry) is Entry: + if isinstance(entry, Entry): result.update(determine_redirects(entry.children)) return result From 867cb82a73784bd9e1b34458fb6a703c823beef0 Mon Sep 17 00:00:00 2001 From: Arnau Casau <47946624+arnaucasau@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:55:01 +0200 Subject: [PATCH 07/13] Update scripts/patterns-reorg/models.py Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- scripts/patterns-reorg/models.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/patterns-reorg/models.py b/scripts/patterns-reorg/models.py index 0f1e7d14313..3f7542165a0 100644 --- a/scripts/patterns-reorg/models.py +++ b/scripts/patterns-reorg/models.py @@ -128,9 +128,7 @@ def determine_redirects( # We need to add two links for each index entry because we can # have two links possible. For example, `/run/index` and `/run` # point to the same page. - old_url_split = old_url.split('/') - old_file_name = old_url_split[-1] - old_folder = old_url_split[-2] + old_folder, old_file_name = old_url.split('/') if old_file_name == "index": result[f"{old_folder}/"] = f"{prefix}{entry.slug.removeprefix('/')}" From be0ffbb0007515b99daaa268233b2b664592222b Mon Sep 17 00:00:00 2001 From: Arnau Casau Date: Wed, 5 Jun 2024 19:06:43 +0200 Subject: [PATCH 08/13] add early return --- scripts/patterns-reorg/models.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/patterns-reorg/models.py b/scripts/patterns-reorg/models.py index 3f7542165a0..86b31b26d2a 100644 --- a/scripts/patterns-reorg/models.py +++ b/scripts/patterns-reorg/models.py @@ -121,18 +121,22 @@ def determine_redirects( ) -> dict[str, str]: result = {} for entry in entries: - if entry.slug is not None and entry.from_file: - old_url = str(PurePath(entry.from_file).with_suffix("")) - result[old_url] = f"{prefix}{entry.slug.removeprefix('/')}" - - # We need to add two links for each index entry because we can - # have two links possible. For example, `/run/index` and `/run` - # point to the same page. - old_folder, old_file_name = old_url.split('/') - if old_file_name == "index": - result[f"{old_folder}/"] = f"{prefix}{entry.slug.removeprefix('/')}" - if isinstance(entry, Entry): result.update(determine_redirects(entry.children)) + if entry.slug is None or not entry.from_file: + continue + + old_url = str(PurePath(entry.from_file).with_suffix("")) + result[old_url] = f"{prefix}{entry.slug.removeprefix('/')}" + + # We need to add two links for each index entry because we can + # have two links possible. For example, `/run/index` and `/run` + # point to the same page. + old_folder, old_file_name = old_url.split('/') + if old_file_name == "index": + result[f"{old_folder}/"] = f"{prefix}{entry.slug.removeprefix('/')}" + + + return result From 0a694619756e60746fb52820dfe64ccc3a9d7ef5 Mon Sep 17 00:00:00 2001 From: Arnau Casau Date: Wed, 5 Jun 2024 19:08:20 +0200 Subject: [PATCH 09/13] DRY redirect_to --- scripts/patterns-reorg/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/patterns-reorg/models.py b/scripts/patterns-reorg/models.py index 86b31b26d2a..84a1ca12b0f 100644 --- a/scripts/patterns-reorg/models.py +++ b/scripts/patterns-reorg/models.py @@ -128,14 +128,15 @@ def determine_redirects( continue old_url = str(PurePath(entry.from_file).with_suffix("")) - result[old_url] = f"{prefix}{entry.slug.removeprefix('/')}" + redirect_to = f"{prefix}{entry.slug.removeprefix('/')}" + result[old_url] = redirect_to # We need to add two links for each index entry because we can # have two links possible. For example, `/run/index` and `/run` # point to the same page. old_folder, old_file_name = old_url.split('/') if old_file_name == "index": - result[f"{old_folder}/"] = f"{prefix}{entry.slug.removeprefix('/')}" + result[f"{old_folder}/"] = redirect_to From 95f284870780dc42b3565e5b30b1743a0083cb3b Mon Sep 17 00:00:00 2001 From: Arnau Casau Date: Wed, 5 Jun 2024 19:39:35 +0200 Subject: [PATCH 10/13] feedback --- scripts/patterns-reorg/deleted_entries.py | 6 ++-- scripts/patterns-reorg/main.py | 3 +- scripts/patterns-reorg/models.py | 38 +++++++++++++---------- scripts/patterns-reorg/redirects.json | 10 +++--- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/scripts/patterns-reorg/deleted_entries.py b/scripts/patterns-reorg/deleted_entries.py index 0b408e9845a..4fca53c1941 100644 --- a/scripts/patterns-reorg/deleted_entries.py +++ b/scripts/patterns-reorg/deleted_entries.py @@ -1,7 +1,7 @@ from models import DeletedPage DELETED_PAGES = ( - DeletedPage(slug="/map-problem-to-circuits", from_file="build/index"), - DeletedPage(slug="/execute-on-hardware", from_file="run/index"), - DeletedPage(slug="", from_file="start/index"), + DeletedPage(redirect_to="/map-problem-to-circuits", old_slug="build/index"), + DeletedPage(redirect_to="/execute-on-hardware", old_slug="run/index"), + DeletedPage(redirect_to="", old_slug="start/index"), ) diff --git a/scripts/patterns-reorg/main.py b/scripts/patterns-reorg/main.py index 7505b638774..f598f0708a7 100755 --- a/scripts/patterns-reorg/main.py +++ b/scripts/patterns-reorg/main.py @@ -54,8 +54,7 @@ def write_guides_dir() -> None: def write_redirects_file() -> None: fp = Path("scripts/patterns-reorg/redirects.json") - redirects = determine_redirects(TOP_LEVEL_ENTRIES) - redirects.update(determine_redirects(DELETED_PAGES)) + redirects = determine_redirects((*TOP_LEVEL_ENTRIES, *DELETED_PAGES)) text = json.dumps(redirects, indent=2) + "\n" fp.write_text(text) diff --git a/scripts/patterns-reorg/models.py b/scripts/patterns-reorg/models.py index 84a1ca12b0f..b744bcfc3ea 100644 --- a/scripts/patterns-reorg/models.py +++ b/scripts/patterns-reorg/models.py @@ -98,8 +98,8 @@ def entries_as_markdown_list( @dataclass(frozen=True) class DeletedPage: - slug: str - from_file: str + redirect_to: str + old_slug: str def filter_entries( @@ -115,6 +115,15 @@ def filter_entries( result.append(new_entry) return tuple(result) +def add_redirect_to_dict(dict: dict[str, str], old_url: str, redirect_to: str)-> None: + dict[old_url] = redirect_to + # We need to add two links for each index entry because we can + # have two links possible. For example, `/run/index` and `/run` + # point to the same page. + old_folder, old_file_name = old_url.split('/') + if old_file_name == "index": + dict[f"{old_folder}"] = redirect_to + def determine_redirects( entries: tuple[Entry, ...] | tuple[DeletedPage, ...], *, prefix: str = "" @@ -124,20 +133,15 @@ def determine_redirects( if isinstance(entry, Entry): result.update(determine_redirects(entry.children)) - if entry.slug is None or not entry.from_file: - continue - - old_url = str(PurePath(entry.from_file).with_suffix("")) - redirect_to = f"{prefix}{entry.slug.removeprefix('/')}" - result[old_url] = redirect_to - - # We need to add two links for each index entry because we can - # have two links possible. For example, `/run/index` and `/run` - # point to the same page. - old_folder, old_file_name = old_url.split('/') - if old_file_name == "index": - result[f"{old_folder}/"] = redirect_to - - + if entry.slug is None or not entry.from_file: + continue + + old_url = str(PurePath(entry.from_file).with_suffix("")) + redirect_to = f"{prefix}{entry.slug.removeprefix('/')}" + add_redirect_to_dict(result, old_url, redirect_to) + + elif isinstance(entry, DeletedPage): + redirect_to = f"{prefix}{entry.redirect_to.removeprefix('/')}" + add_redirect_to_dict(result, entry.old_slug, redirect_to) return result diff --git a/scripts/patterns-reorg/redirects.json b/scripts/patterns-reorg/redirects.json index 0e229128397..f3b07ae3a06 100644 --- a/scripts/patterns-reorg/redirects.json +++ b/scripts/patterns-reorg/redirects.json @@ -18,7 +18,7 @@ "build/interoperate-qiskit-qasm3": "interoperate-qiskit-qasm3", "build/qasm-feature-table": "qasm-feature-table", "transpile/index": "transpile", - "transpile/": "transpile", + "transpile": "transpile", "transpile/transpiler-stages": "transpiler-stages", "transpile/transpile-with-pass-managers": "transpile-with-pass-managers", "transpile/defaults-and-configuration-options": "defaults-and-configuration-options", @@ -33,7 +33,7 @@ "transpile/qiskit-transpiler-service": "qiskit-transpiler-service", "transpile/ai-transpiler-passes": "ai-transpiler-passes", "verify/index": "debugging-tools", - "verify/": "debugging-tools", + "verify": "debugging-tools", "verify/simulate-with-qiskit-primitives": "simulate-with-qiskit-sdk-primitives", "verify/simulate-with-qiskit-aer": "simulate-with-qiskit-aer", "verify/local-testing-mode": "local-testing-mode", @@ -69,9 +69,9 @@ "run/visualize-results": "visualize-results", "run/quantum-serverless": "qiskit-serverless", "build/index": "map-problem-to-circuits", - "build/": "map-problem-to-circuits", + "build": "map-problem-to-circuits", "run/index": "execute-on-hardware", - "run/": "execute-on-hardware", + "run": "execute-on-hardware", "start/index": "", - "start/": "" + "start": "" } From 2db6b2b603e8d0c91d001c773662553487510017 Mon Sep 17 00:00:00 2001 From: Arnau Casau Date: Wed, 5 Jun 2024 19:42:02 +0200 Subject: [PATCH 11/13] update type hint --- scripts/patterns-reorg/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patterns-reorg/models.py b/scripts/patterns-reorg/models.py index b744bcfc3ea..df53ee62ca1 100644 --- a/scripts/patterns-reorg/models.py +++ b/scripts/patterns-reorg/models.py @@ -126,7 +126,7 @@ def add_redirect_to_dict(dict: dict[str, str], old_url: str, redirect_to: str)-> def determine_redirects( - entries: tuple[Entry, ...] | tuple[DeletedPage, ...], *, prefix: str = "" + entries: tuple[Entry | DeletedPage, ...], *, prefix: str = "" ) -> dict[str, str]: result = {} for entry in entries: From 8f0b73e03557157d4372d26dd8fa4766c59bb6a2 Mon Sep 17 00:00:00 2001 From: Arnau Casau Date: Wed, 5 Jun 2024 19:49:15 +0200 Subject: [PATCH 12/13] private helper and new dict name --- scripts/patterns-reorg/models.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/patterns-reorg/models.py b/scripts/patterns-reorg/models.py index df53ee62ca1..0182a15ec0f 100644 --- a/scripts/patterns-reorg/models.py +++ b/scripts/patterns-reorg/models.py @@ -115,14 +115,14 @@ def filter_entries( result.append(new_entry) return tuple(result) -def add_redirect_to_dict(dict: dict[str, str], old_url: str, redirect_to: str)-> None: - dict[old_url] = redirect_to +def _add_redirect_to_dict(redirects: dict[str, str], old_url: str, redirect_to: str)-> None: + redirects[old_url] = redirect_to # We need to add two links for each index entry because we can # have two links possible. For example, `/run/index` and `/run` # point to the same page. old_folder, old_file_name = old_url.split('/') if old_file_name == "index": - dict[f"{old_folder}"] = redirect_to + redirects[f"{old_folder}"] = redirect_to def determine_redirects( @@ -138,10 +138,10 @@ def determine_redirects( old_url = str(PurePath(entry.from_file).with_suffix("")) redirect_to = f"{prefix}{entry.slug.removeprefix('/')}" - add_redirect_to_dict(result, old_url, redirect_to) + _add_redirect_to_dict(result, old_url, redirect_to) elif isinstance(entry, DeletedPage): redirect_to = f"{prefix}{entry.redirect_to.removeprefix('/')}" - add_redirect_to_dict(result, entry.old_slug, redirect_to) + _add_redirect_to_dict(result, entry.old_slug, redirect_to) return result From 7e7e70624ab4ec217cf60493a96e03f321f63fa3 Mon Sep 17 00:00:00 2001 From: Arnau Casau <47946624+arnaucasau@users.noreply.github.com> Date: Wed, 5 Jun 2024 19:50:04 +0200 Subject: [PATCH 13/13] Update scripts/patterns-reorg/deleted_entries.py Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- scripts/patterns-reorg/deleted_entries.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/patterns-reorg/deleted_entries.py b/scripts/patterns-reorg/deleted_entries.py index 4fca53c1941..78a5616cabc 100644 --- a/scripts/patterns-reorg/deleted_entries.py +++ b/scripts/patterns-reorg/deleted_entries.py @@ -1,7 +1,7 @@ from models import DeletedPage DELETED_PAGES = ( - DeletedPage(redirect_to="/map-problem-to-circuits", old_slug="build/index"), - DeletedPage(redirect_to="/execute-on-hardware", old_slug="run/index"), - DeletedPage(redirect_to="", old_slug="start/index"), + DeletedPage(old_slug="build/index", redirect_to="/map-problem-to-circuits"), + DeletedPage(old_slug="run/index", redirect_to="/execute-on-hardware"), + DeletedPage(old_slug="start/index", redirect_to=""), )