Skip to content

Commit 9f61db1

Browse files
oharboeclaude
andcommitted
def2stream: say what is missing when the AUTO_MEMORIES list is
Review asked for a missing RESULTS_DIR or blackboxes.txt to mean no generated macros. It does not: do-auto-memories always writes the list, empty when nothing was converted, so a missing one is a broken flow, and passing over it would turn into "has no matching GDS/OAS cell" errors for the generated macros further on. It stays a stop, now with a message naming what is missing instead of a KeyError or FileNotFoundError; under klayout -r the merge exits 1 with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 0498d4e commit 9f61db1

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎flow/test/test_def2stream.py‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,29 @@ def test_names_from_blackboxes_txt(self):
373373
)
374374

375375
def test_missing_list_is_an_error(self):
376+
# the flow always writes it; a missing list is a broken flow, not
377+
# a design without generated macros
376378
with tempfile.TemporaryDirectory() as results:
377-
with self.assertRaises(FileNotFoundError):
379+
with self.assertRaisesRegex(RuntimeError, "blackboxes.txt is missing"):
378380
def2stream.auto_memories_cells(
379381
{"AUTO_MEMORIES": "1", "RESULTS_DIR": results}
380382
)
381383

384+
def test_missing_results_dir_is_an_error(self):
385+
with self.assertRaisesRegex(RuntimeError, "RESULTS_DIR is not set"):
386+
def2stream.auto_memories_cells({"AUTO_MEMORIES": "1"})
387+
388+
def test_empty_list_allows_nothing(self):
389+
with tempfile.TemporaryDirectory() as results:
390+
os.mkdir(os.path.join(results, "memories"))
391+
open(os.path.join(results, "memories", "blackboxes.txt"), "w").close()
392+
self.assertEqual(
393+
def2stream.auto_memories_cells(
394+
{"AUTO_MEMORIES": "1", "RESULTS_DIR": results}
395+
),
396+
frozenset(),
397+
)
398+
382399

383400
class TestOrphanCells(unittest.TestCase):
384401
def test_orphan_cell_is_error(self):

‎flow/util/def2stream.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,18 @@ def auto_memories_cells(environ):
143143
"""
144144
if environ.get("AUTO_MEMORIES") != "1":
145145
return frozenset()
146-
path = os.path.join(environ["RESULTS_DIR"], "memories", "blackboxes.txt")
147-
with open(path) as f:
146+
# do-auto-memories always writes the list, empty when nothing was
147+
# converted; without it the merge cannot tell a generated macro from
148+
# a cell whose GDS is missing.
149+
results_dir = environ.get("RESULTS_DIR")
150+
if not results_dir:
151+
raise RuntimeError("AUTO_MEMORIES=1 but RESULTS_DIR is not set")
152+
path = os.path.join(results_dir, "memories", "blackboxes.txt")
153+
if not os.path.isfile(path):
154+
raise RuntimeError(
155+
f"AUTO_MEMORIES=1 but {path} is missing; do-auto-memories writes it"
156+
)
157+
with open(path, encoding="utf-8") as f:
148158
return frozenset(line.split()[0] for line in f if line.strip())
149159

150160

0 commit comments

Comments
 (0)