Skip to content

Commit

Permalink
Simplify stripping in cell_list generation
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrZierhoffer committed Aug 26, 2020
1 parent a28d8c1 commit d6da333
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 32 deletions.
3 changes: 2 additions & 1 deletion scripts/python-skywater-pdk/skywater_pdk/cell_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import pathlib
import pprint
import sys
import textwrap

from typing import Tuple, List, Dict
from utils import indent
Expand Down Expand Up @@ -121,7 +122,7 @@ def generate_rst(library_dir, library_name, cells):
cell_list = cell_list + cell_template.format(
cell_name = cell_json['name'],
#description = cell_json['description'].replace("\n", "\n "),
description = indent(cell_json['description'], None, ' '),
description = textwrap.indent(cell_json['description'], ' ').lstrip(),
type = cell_json['type'],
verilog_name = cell_json['verilog_name']
)
Expand Down
31 changes: 0 additions & 31 deletions scripts/python-skywater-pdk/skywater_pdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,37 +287,6 @@ def sortable_extracted_numbers(s):
return tuple(o)


def indent(text, initial_indent, subsequent_indent):
"""
>>> indent(None, '-', '*') is None
True
>>> indent('', '-', '*')
''
>>> indent('a', '- ', '* ')
'- a'
>>> indent('a\\nb\\nc', '- ', '* ')
'- a\\n* b\\n* c'
>>> indent('a\\nb\\nc', '- ', None)
'- a\\nb\\nc'
>>> indent('a\\nb\\nc', None, '* ')
'a\\n* b\\n* c'
"""

def prefixed_lines():
if text is None or len(text) == 0:
return text
s = text.splitlines(True)
yield initial_indent + s[0]
for line in s[1:]:
yield subsequent_indent + line

if text is None:
return None
initial_indent = initial_indent or ''
subsequent_indent = subsequent_indent or ''

return ''.join(prefixed_lines())

if __name__ == "__main__":
import doctest
doctest.testmod()

0 comments on commit d6da333

Please sign in to comment.