Files
openlane2/docs/_ext/migration_comparison.py
Mohamed Gaber aea7423b3d Glossary, FAQ, Getting Started Guide for OpenLane and Caravel (#315)
* Updated docstrings across the board for spelling and terminology
mistakes
* **API Break**: Moved `DesignFormat`, `DesignFormatObject` from
`openlane.common` to `openlane.state`

## Docs

* Added Glossary
* Added FAQ
* Separated the "Getting Started" guide into a tutorial for newcomers
and a
  migration guide for OpenLane veterans
* Added extensions to make the documentation better to write and use:
  * `sphinx-tippy` for tooltips
  * `sphinx-copybutton` for copying terminal commands
  * `sphinxcontrib-spelling` so we don't write "Verliog"
* Custom extension so Flows, Steps and Variables can be referenced using
custom MyST roles
* Added a new target to the `Makefile`, `watch-docs`, which watches for
changes to rebuild the docs (requires `nodemon`)
* Updated generated documentation for steps, flows and universal
configuration variable
* Updated Readme to reflect `aarch64` support

---------

Co-authored-by: kareefardi <kareem.farid@efabless.com>
Co-authored-by: Kareem Farid <kareefardi@users.noreply.github.com>
Co-authored-by: Passant <bassant.hassan@efabless.com>
2024-01-30 14:30:05 +02:00

115 lines
3.0 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2024 Efabless Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
import re
from typing import List
from enum import IntEnum
from sphinx.application import Sphinx
def setup(app):
app.connect("source-read", subst_migration_comparison)
return {"version": "1.0", "parallel_read_safe": True}
migration_comparison_rx = re.compile(
r"^(`{3,})!migration_comparison(\[\w*\])?(?:\s+(.+))?"
)
def subst_migration_comparison(app: Sphinx, docname: str, sourceRef: List[str]):
class State(IntEnum):
default = 0
before = 1
after = 2
rationale = 3
source = sourceRef[0]
final_string = ""
state = State.default
before = ""
after = ""
rationale = ""
closing = ""
lines_in = source.splitlines()
highlighting = None
if lines_in[0] != "!register migration_comparison":
return
for line in lines_in[1:]:
if state == State.default:
if match := migration_comparison_rx.match(line):
final_string += (match[3] or "") + "\n"
state = State.before
before = ""
after = ""
rationale = ""
highlighting = None
closing = match[1]
if match[2] is not None:
highlighting = match[2].strip("[]")
else:
final_string += line + "\n"
elif state == State.before:
if line == "---":
state = State.after
continue
before += line + "\n"
elif state == State.after:
if line == "---":
state = State.rationale
continue
after += line + "\n"
elif state == State.rationale:
if line == closing:
state = State.default
if highlighting is not None:
before = f"```{highlighting}\n{before}\n```\n"
after = f"```{highlighting}\n{after}\n```\n"
final_string += f"""
<table style="width: 100%; table-layout:fixed;">
<tr>
<th style="width: 50%;"> OpenLane &lt;2.0 </th>
<th style="width: 50%;"> OpenLane ≥2.0 </th>
</tr>
<tr>
<td style="width: 50%;">
<div style="overflow:scroll; width:100%;">
{before}
</div>
</td>
<td style="width: 50%;">
<div style="overflow:scroll; width:100%;">
{after}
</div>
</td>
</tr>
</table>
{rationale}
"""
continue
rationale += line + "\n"
sourceRef[0] = final_string