From bceb40986a0049706b8346bb594dc791a9bdcd5d Mon Sep 17 00:00:00 2001 From: Weiping Yan <152196713+appleweiping@users.noreply.github.com> Date: Sun, 30 Aug 2026 17:32:06 +0800 Subject: [PATCH] Fix PrettyPrint dependency compatibility Remove the unused prettyprint package, which collides with PrettyPrintTree on case-insensitive filesystems. Constrain PrettyPrintTree to the compatible 1.x API, install it in the lightweight unit-test job, and cover PortTree text output with a regression test. Signed-off-by: Weiping Yan <152196713+appleweiping@users.noreply.github.com> Assisted-by: OpenAI Codex --- .github/workflows/tests.yml | 2 +- setup.py | 3 +-- tests/test_port_tree.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 tests/test_port_tree.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0dc2f1a2..673f6229 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,7 +36,7 @@ jobs: # only. Keeping the environment small is what makes this job fast # enough to run on every push. - name: Install test dependencies - run: pip install pytest gdstk numpy pandas pydantic docopt + run: pip install pytest gdstk numpy pandas pydantic docopt 'prettyprinttree>=1.36.4,<2' # The heavier DRC/LVS workflows run the gdsfactory backend (Python # 3.10, gdsfactory 7.7), so gdstk currently has no CI coverage at all. diff --git a/setup.py b/setup.py index c927da31..26b9beab 100644 --- a/setup.py +++ b/setup.py @@ -31,8 +31,7 @@ # `ModuleNotFoundError: No module named 'docopt'` and the deck # never runs. "docopt", - "prettyprint", - "prettyprinttree", + "prettyprinttree>=1.36.4,<2", "gdstk", "svgutils", "nltk", diff --git a/tests/test_port_tree.py b/tests/test_port_tree.py new file mode 100644 index 00000000..73c56ce4 --- /dev/null +++ b/tests/test_port_tree.py @@ -0,0 +1,35 @@ +from __future__ import annotations + +import unittest +from pathlib import Path +from tempfile import TemporaryDirectory + + +class PortTreeTests(unittest.TestCase): + def test_print_writes_the_port_hierarchy(self) -> None: + from glayout.backend import Component + from glayout.util.port_utils import PortTree + + component = Component("demo") + component.add_port( + name="device_gate_N", + center=(0, 0), + width=1, + orientation=90, + layer=(1, 0), + ) + + with TemporaryDirectory() as directory: + output = Path(directory) / "ports.txt" + PortTree(component).print(savetofile=True, outfile_name=str(output)) + + self.assertTrue(output.is_file()) + text = output.read_text() + self.assertIn("demo", text) + self.assertIn("device", text) + self.assertIn("gate", text) + self.assertIn("N", text) + + +if __name__ == "__main__": + unittest.main()