Skip to content

Commit

Permalink
Implement remarks from review of cell_list generator
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrZierhoffer committed Aug 26, 2020
1 parent 33343d0 commit a28d8c1
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions scripts/python-skywater-pdk/skywater_pdk/cell_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import sys

from typing import Tuple, List, Dict

debug = False
from utils import indent

# using a list-table here to allow for easier line breaks in description
rst_template ="""List of cells
rst_template ="""\
List of cells
-------------
.. list-table::
Expand All @@ -42,7 +42,8 @@
{cell_list}
"""

cell_template = """ * - {cell_name}
cell_template = """\
* - {cell_name}
- {description}
- {type}
- {verilog_name}
Expand Down Expand Up @@ -84,7 +85,6 @@ def collect(library_dir) -> Tuple[str, List[str]]:
cells = list(sorted(cells))
return libname, cells


def generate_rst(library_dir, library_name, cells):
"""Generate the RST file containing basic information about cells
Expand All @@ -99,8 +99,14 @@ def generate_rst(library_dir, library_name, cells):
cells: list of pathlib.Path
List of paths to JSON description files
Returns
-------
path: str
Path to generated file
"""


if not isinstance(library_dir, pathlib.Path):
library_dir = pathlib.Path(library_dir)

Expand All @@ -114,7 +120,8 @@ def generate_rst(library_dir, library_name, cells):
cell_json = json.load(c)
cell_list = cell_list + cell_template.format(
cell_name = cell_json['name'],
description = cell_json['description'].replace("\n", "\n "),
#description = cell_json['description'].replace("\n", "\n "),
description = indent(cell_json['description'], None, ' '),
type = cell_json['type'],
verilog_name = cell_json['verilog_name']
)
Expand All @@ -126,6 +133,9 @@ def generate_rst(library_dir, library_name, cells):
))
except FileNotFoundError:
print(f"ERROR: Failed to create {str(cell_list_file)}", file=sys.stderr)
raise

return cell_list_file

def main():
parser = argparse.ArgumentParser()
Expand All @@ -135,25 +145,16 @@ def main():
type=pathlib.Path,
nargs=1)

parser.add_argument(
"--debug",
help="Include verbose debug output on the console.",
action='store_true',
default=False)

args = parser.parse_args()
if args.debug:
global debug
debug = True

lib = args.library_dir[0]
if debug:
print(f"Analysing {lib}")
print(f"Analysing {lib}")
libname, cells = collect(lib)
if debug:
print(f"Library name: {libname}, found {len(cells)} cells")
generate_rst(lib, libname, cells)
print(f"Library name: {libname}, found {len(cells)} cells")
file = generate_rst(lib, libname, cells)
print(f'Generated {file}')


if __name__ == "__main__":
sys.exit(main())
sys.exit(main())

0 comments on commit a28d8c1

Please sign in to comment.