Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set redirects for future deleted pages in the patterns reorg #1497

Merged
merged 14 commits into from
Jun 5, 2024
7 changes: 7 additions & 0 deletions scripts/patterns-reorg/deleted_entries.py
Original file line number Diff line number Diff line change
@@ -0,0 +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"),
arnaucasau marked this conversation as resolved.
Show resolved Hide resolved
)
3 changes: 2 additions & 1 deletion scripts/patterns-reorg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from models import determine_redirects
from entries import TOP_LEVEL_ENTRIES
from deleted_entries import DELETED_PAGES


def create_parser() -> ArgumentParser:
Expand Down Expand Up @@ -53,7 +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 = determine_redirects((*TOP_LEVEL_ENTRIES, *DELETED_PAGES))
text = json.dumps(redirects, indent=2) + "\n"
fp.write_text(text)

Expand Down
33 changes: 29 additions & 4 deletions scripts/patterns-reorg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ def entries_as_markdown_list(
return "\n".join(result)


@dataclass(frozen=True)
class DeletedPage:
redirect_to: str
old_slug: str


def filter_entries(
entries: tuple[Entry, ...], *, ignore: set[Entry]
) -> tuple[Entry, ...]:
Expand All @@ -109,14 +115,33 @@ 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:
arnaucasau marked this conversation as resolved.
Show resolved Hide resolved
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, ...], *, 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 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('/')}"
result.update(determine_redirects(entry.children))
redirect_to = f"{prefix}{entry.slug.removeprefix('/')}"
add_redirect_to_dict(result, old_url, redirect_to)

elif isinstance(entry, DeletedPage):
arnaucasau marked this conversation as resolved.
Show resolved Hide resolved
redirect_to = f"{prefix}{entry.redirect_to.removeprefix('/')}"
add_redirect_to_dict(result, entry.old_slug, redirect_to)

return result
10 changes: 9 additions & 1 deletion scripts/patterns-reorg/redirects.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -32,6 +33,7 @@
"transpile/qiskit-transpiler-service": "qiskit-transpiler-service",
"transpile/ai-transpiler-passes": "ai-transpiler-passes",
"verify/index": "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",
Expand Down Expand Up @@ -65,5 +67,11 @@
"build/circuit-visualization": "visualize-circuits",
"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": ""
}
Loading