Skip to content

Commit

Permalink
Merge pull request #5473 from Pinata-Consulting/python-black
Browse files Browse the repository at this point in the history
python: ran black .
  • Loading branch information
maliberty authored Jul 30, 2024
2 parents 39ae355 + c3a4f97 commit c2be161
Show file tree
Hide file tree
Showing 227 changed files with 3,718 additions and 2,586 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/black.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Lint Python

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable

121 changes: 64 additions & 57 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

# -- Project information -----------------------------------------------------

project = 'OpenROAD'
copyright = 'The Regents of the University of California, 2021'
author = 'OpenROAD Team'
project = "OpenROAD"
copyright = "The Regents of the University of California, 2021"
author = "OpenROAD Team"


# -- General configuration ---------------------------------------------------
Expand All @@ -25,77 +25,85 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.ifconfig',
'sphinx.ext.mathjax',
'sphinx.ext.napoleon',
'sphinx.ext.todo',
'sphinx_external_toc',
'sphinx_copybutton',
'myst_parser',
'sphinxcontrib.mermaid'
"sphinx.ext.autodoc",
"sphinx.ext.ifconfig",
"sphinx.ext.mathjax",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx_external_toc",
"sphinx_copybutton",
"myst_parser",
"sphinxcontrib.mermaid",
]

myst_enable_extensions = [
'amsmath',
'colon_fence',
'deflist',
'dollarmath',
'html_admonition',
'html_image',
'replacements',
'smartquotes',
'substitution',
'tasklist',
'html_image',
"amsmath",
"colon_fence",
"deflist",
"dollarmath",
"html_admonition",
"html_image",
"replacements",
"smartquotes",
"substitution",
"tasklist",
"html_image",
]

external_toc_path = 'toc.yml'
external_toc_path = "toc.yml"

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = ['.md']
source_suffix = [".md"]

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = [
'_build',
'Thumbs.db',
'.DS_Store',
'**/LICENSE',
'**/LICENSE.md',
'README.md',
'misc/NewToolDocExample.md',
'docs/releases/PostAlpha2.1BranchMethodology.md',
'main/src/odb/src/def/README.md',
'main/src/odb/src/def/doc/README.md',
'main/src/odb/src/lef/README.md',
'main/docs',
'md', # manpage dir
'man', # manpage dir
'cat', # manpage dir
'html' # manpage dir
"_build",
"Thumbs.db",
".DS_Store",
"**/LICENSE",
"**/LICENSE.md",
"README.md",
"misc/NewToolDocExample.md",
"docs/releases/PostAlpha2.1BranchMethodology.md",
"main/src/odb/src/def/README.md",
"main/src/odb/src/def/doc/README.md",
"main/src/odb/src/lef/README.md",
"main/docs",
"md", # manpage dir
"man", # manpage dir
"cat", # manpage dir
"html", # manpage dir
]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None

# Mermaid related args
mermaid_output_format = 'svg'
mermaid_params = ['-p', 'puppeteer-config.json',
'--theme', 'forest',
'--width', '200',
'--backgroundColor', 'transparent']
mermaid_init_js = "mermaid.initialize({startOnLoad:true, flowchart:{useMaxWidth:false}})"
mermaid_output_format = "svg"
mermaid_params = [
"-p",
"puppeteer-config.json",
"--theme",
"forest",
"--width",
"200",
"--backgroundColor",
"transparent",
]
mermaid_init_js = (
"mermaid.initialize({startOnLoad:true, flowchart:{useMaxWidth:false}})"
)
mermaid_verbose = True

# -- Options for HTML output -------------------------------------------------
Expand All @@ -112,7 +120,6 @@
"use_issues_button": True,
# "use_repository_button": True,
"use_download_button": True,

# list for more fine-grained ordering of icons
"icon_links": [
{
Expand Down Expand Up @@ -141,7 +148,7 @@
"icon": "https://img.shields.io/github/stars/The-OpenROAD-Project/OpenROAD",
"type": "url",
},
],
],
}

# Add any paths that contain custom static files (such as style sheets) here,
Expand All @@ -151,21 +158,21 @@


def swap_prefix(file, old, new):
with open(file, 'r') as f:
with open(file, "r") as f:
lines = f.read()
lines = lines.replace(old, new)
with open(file, 'wt') as f:
with open(file, "wt") as f:
f.write(lines)


def setup(app):
import os

if not os.path.exists('./main'):
os.symlink('..', './main')
if not os.path.exists("./main"):
os.symlink("..", "./main")
# these prefix swaps will be reverted and is needed for sphinx compilation.
swap_prefix('../README.md', '(docs/', '(../')
swap_prefix('../README.md', '```mermaid', '```{mermaid}\n:align: center\n')
swap_prefix("../README.md", "(docs/", "(../")
swap_prefix("../README.md", "```mermaid", "```{mermaid}\n:align: center\n")

# for populating OR Messages page.
command = "python getMessages.py"
Expand Down
24 changes: 15 additions & 9 deletions docs/getMessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,41 @@
command = "python ../etc/find_messages.py -d ../src"
output = os.popen(command).read()

with open('user/MessagesFinal.md', 'w') as f:
with open("user/MessagesFinal.md", "w") as f:
f.write("# OpenROAD Messages Glossary\n")
f.write("Listed below are the OpenROAD warning/errors you may encounter while using the application.\n")
f.write(
"Listed below are the OpenROAD warning/errors you may encounter while using the application.\n"
)
f.write("\n")
f.write("| Tool | Code | Filename:Line Number | Type | Information |\n")
f.write("| ---- | ---- | -------------------- | ---- | ----------------------- |\n")

lines = output.split('\n')
lines = output.split("\n")
for line in lines:
columns = line.split()
if not columns: continue
ant = columns[0]
if not columns:
continue
ant = columns[0]
num = columns[1]
fileLineNum = f"[{columns[2]}]({columns[-1]})"
msgType = columns[-2]
tool = columns[0].lower()
try:
# aim is to match all level1 header and their corresponding text.
message = open(f"../src/{tool}/doc/messages/{num}.md").read()
pattern = re.compile(r'#\s*(?P<header1>[^\n]+)\n*(?P<body_text>.*?)(?=\n#|$)', re.DOTALL)
pattern = re.compile(
r"#\s*(?P<header1>[^\n]+)\n*(?P<body_text>.*?)(?=\n#|$)", re.DOTALL
)
matches = pattern.finditer(message)
m = []
for match in matches:
header1 = match.group('header1')
body_text = match.group('body_text').strip()
header1 = match.group("header1")
body_text = match.group("body_text").strip()
m.append(f"{header1}-{body_text}")
message = " ".join(x for x in m)

except OSError as e:
message = "-"
if not message: message = "-"
if not message:
message = "-"
f.write(f"| {ant} | {num} | {fileLineNum} | {msgType} |{message} |\n")
85 changes: 55 additions & 30 deletions docs/getPatch.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,78 @@
#!/usr/bin/env python3
import os


def swap_prefix(file, old, new):
with open(file, 'r') as f:
with open(file, "r") as f:
lines = f.read()
lines = lines.replace(old, new)
with open(file, 'wt') as f:
with open(file, "wt") as f:
f.write(lines)


# modify ../include/ord/OpenROAD.hh
swap_prefix('../include/ord/OpenRoad.hh', 'namespace dft {\nclass Dft;\n}',
'namespace dft {\nclass Dft;\n}\n\nnamespace tool{\nclass Tool;\n}')
swap_prefix(
"../include/ord/OpenRoad.hh",
"namespace dft {\nclass Dft;\n}",
"namespace dft {\nclass Dft;\n}\n\nnamespace tool{\nclass Tool;\n}",
)

swap_prefix('../include/ord/OpenRoad.hh', 'dft::Dft* getDft() { return dft_; }',
'dft::Dft* getDft() { return dft_; }\n tool::Tool* getTool() { return tool_; }')
swap_prefix(
"../include/ord/OpenRoad.hh",
"dft::Dft* getDft() { return dft_; }",
"dft::Dft* getDft() { return dft_; }\n tool::Tool* getTool() { return tool_; }",
)

swap_prefix('../include/ord/OpenRoad.hh', 'dft::Dft* dft_ = nullptr;',
'dft::Dft* dft_ = nullptr;\n tool::Tool* tool_ = nullptr;')
swap_prefix(
"../include/ord/OpenRoad.hh",
"dft::Dft* dft_ = nullptr;",
"dft::Dft* dft_ = nullptr;\n tool::Tool* tool_ = nullptr;",
)

# modify ../src/CMakeLists.txt
swap_prefix('../src/CMakeLists.txt', 'add_subdirectory(dft)',
'add_subdirectory(dft)\nadd_subdirectory(tool)')
swap_prefix(
"../src/CMakeLists.txt",
"add_subdirectory(dft)",
"add_subdirectory(dft)\nadd_subdirectory(tool)",
)

swap_prefix('../src/CMakeLists.txt', 'pdn\n dft', 'pdn\n dft\n tool')
swap_prefix("../src/CMakeLists.txt", "pdn\n dft", "pdn\n dft\n tool")

# modify ../src/OpenROAD.cc
swap_prefix('../src/OpenRoad.cc', '#include "utl/MakeLogger.h"',
'#include "utl/MakeLogger.h"\n#include "tool/MakeTool.hh"')
swap_prefix(
"../src/OpenRoad.cc",
'#include "utl/MakeLogger.h"',
'#include "utl/MakeLogger.h"\n#include "tool/MakeTool.hh"',
)

swap_prefix('../src/OpenRoad.cc', 'dft_ = dft::makeDft();',
'dft_ = dft::makeDft();\n tool_ = makeTool();')
swap_prefix(
"../src/OpenRoad.cc",
"dft_ = dft::makeDft();",
"dft_ = dft::makeDft();\n tool_ = makeTool();",
)

swap_prefix('../src/OpenRoad.cc', 'dft::deleteDft(dft_);',
'dft::deleteDft(dft_);\n deleteTool(tool_);')
swap_prefix(
"../src/OpenRoad.cc",
"dft::deleteDft(dft_);",
"dft::deleteDft(dft_);\n deleteTool(tool_);",
)

swap_prefix('../src/OpenRoad.cc', 'dft::initDft(this);',
'dft::initDft(this);\n initTool(this);')
swap_prefix(
"../src/OpenRoad.cc",
"dft::initDft(this);",
"dft::initDft(this);\n initTool(this);",
)

# create a patch file
_ = os.popen('git add ../include/ord/OpenRoad.hh').read()
_ = os.popen('git add ../src/CMakeLists.txt').read()
_ = os.popen('git add ../src/OpenRoad.cc').read()
_ = os.popen('git diff --cached > misc/AddTool.patch').read()
_ = os.popen("git add ../include/ord/OpenRoad.hh").read()
_ = os.popen("git add ../src/CMakeLists.txt").read()
_ = os.popen("git add ../src/OpenRoad.cc").read()
_ = os.popen("git diff --cached > misc/AddTool.patch").read()

# restore all changes except patch
_ = os.popen('git reset ../include/ord/OpenRoad.hh').read()
_ = os.popen('git reset ../src/CMakeLists.txt').read()
_ = os.popen('git reset ../src/OpenRoad.cc').read()
_ = os.popen('git restore ../include/ord/OpenRoad.hh').read()
_ = os.popen('git restore ../src/CMakeLists.txt').read()
_ = os.popen('git restore ../src/OpenRoad.cc').read()

_ = os.popen("git reset ../include/ord/OpenRoad.hh").read()
_ = os.popen("git reset ../src/CMakeLists.txt").read()
_ = os.popen("git reset ../src/OpenRoad.cc").read()
_ = os.popen("git restore ../include/ord/OpenRoad.hh").read()
_ = os.popen("git restore ../src/CMakeLists.txt").read()
_ = os.popen("git restore ../src/OpenRoad.cc").read()
9 changes: 5 additions & 4 deletions docs/revert-links.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python3


def swap_prefix(file, old, new):
with open(file, 'r') as f:
with open(file, "r") as f:
lines = f.read()
lines = lines.replace(old, new)
with open(file, 'wt') as f:
with open(file, "wt") as f:
f.write(lines)


swap_prefix('../README.md', '(../', '(docs/')
swap_prefix('../README.md', '```{mermaid}\n:align: center\n', '```mermaid')
swap_prefix("../README.md", "(../", "(docs/")
swap_prefix("../README.md", "```{mermaid}\n:align: center\n", "```mermaid")
Loading

0 comments on commit c2be161

Please sign in to comment.