Skip to content

Constrain prettyprinttree so PortTree.print() works again - #123

Open
appleweiping wants to merge 2 commits into
ReaLLMASIC:mainfrom
appleweiping:chore/drop-unused-prettyprint-dep
Open

appleweiping wants to merge 2 commits into
ReaLLMASIC:mainfrom
appleweiping:chore/drop-unused-prettyprint-dep

Conversation

@appleweiping

Copy link
Copy Markdown

PortTree.print() passes default_orientation to PrettyPrintTree (port_utils.py:483, set whenever default_opts or savetofile is used). PrettyPrintTree removed that argument in 2.0 and accepts no **kwargs, so with the current unconstrained requirement a fresh install resolves 2.0.2 and the call raises:

TypeError: PrettyPrintTree.__init__() got an unexpected keyword argument 'default_orientation'

Pinning <2 alone is not enough, and is arguably worse. 1.36.4 keeps the argument but does not constrain its own cmd2 dependency; cmd2 4.x moved cmd2.ansi, so from PrettyPrint import PrettyPrintTree fails, port_utils falls through to its no-op shim, and print() silently returns nothing instead of raising. cmd2<3 is what actually restores output.

Verified in clean virtualenvs:

requirement resolves to result
unconstrained (current) PrettyPrintTree 2.0.2 TypeError as above
<2 only 1.36.4 + cmd2 4.2.3 import fails → silent no-op shim
<2 and cmd2<3 1.36.4 + cmd2 2.7.0 renders a tree as intended

This also drops prettyprint, an unrelated and unmaintained 2012 package that nothing in the codebase imports. It installs without error, so it breaks nothing, but it is misleading sitting next to prettyprinttree, which is the package port_utils actually uses.

I am aware cmd2 is a transitive dependency rather than something gLayout imports directly, so pinning it here is a judgement call — happy to drop that line if you would rather constrain it another way (or raise it upstream with PrettyPrintTree instead). Without it, though, the printer stays silently broken.

Note: pip install -e . fails on Python 3.14 in my environment because numpy<=1.24.0 has no cp314 wheel and its sdist build fails; this happens identically on unmodified main and is unrelated to this change. Verification above was on Python 3.11, where pip install -e . succeeds and pytest tests --ignore=tests/test_cells_layout.py gives 25 passed.

🤖 Generated with Claude Code

`PortTree.print()` passes `default_orientation` to `PrettyPrintTree`
(port_utils.py:483, set when either `default_opts` or `savetofile` is used).
PrettyPrintTree removed that argument in 2.0 and takes no `**kwargs`, so with
the current unconstrained requirement a fresh install resolves 2.0.2 and the
call raises:

    TypeError: PrettyPrintTree.__init__() got an unexpected keyword argument
    'default_orientation'

Pinning `<2` alone is not enough. 1.36.4 keeps the argument but does not
constrain its own `cmd2` dependency; cmd2 4.x moved `cmd2.ansi`, so
`from PrettyPrint import PrettyPrintTree` fails, `port_utils` falls through to
its no-op shim, and `print()` silently returns nothing instead of raising —
worse than the current loud failure. `cmd2<3` is what actually restores output.

Verified in clean virtualenvs:

- unconstrained      -> PrettyPrintTree 2.0.2, TypeError as above
- `<2` only          -> 1.36.4 + cmd2 4.2.3, ImportError -> silent no-op shim
- `<2` and `cmd2<3`  -> 1.36.4 + cmd2 2.7.0, renders a tree as intended

Also drops `prettyprint`, an unrelated and unmaintained 2012 package that
nothing in the codebase imports. It is harmless but misleading next to
`prettyprinttree`, which is the one `port_utils` actually uses.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@appleweiping

Copy link
Copy Markdown
Author

Housekeeping note: I have closed my earlier draft #118, which fixed the same import failure but pinned only prettyprinttree. This PR supersedes it — the cmd2<3 bound is the part that makes the difference between PortTree.print() raising and it silently producing nothing.

#118 also contained a regression test that builds a component, calls PortTree.print(savetofile=True, ...) and asserts the port hierarchy reaches the file, along with a line adding prettyprinttree to the fast gdstk test job so it would actually be exercised. I have deliberately left both out of this PR: I cannot install gLayout locally, so I have not run that test, and I would rather keep this change to the dependency bounds I could verify by resolution than add a test I have only reasoned about. Happy to add it if you would like it — it is on the closed branch.

@appleweiping

appleweiping commented Sep 7, 2026 •

Copy link
Copy Markdown
Author

Pushed f092508 to make the dependency fix self-checking.

  • Added the PortTree regression test from the superseded PR 118. It covers saved output and the expected hierarchy.
  • Updated the lightweight unit-test workflow to install compatible renderer bounds.

Verification on Python 3.12 with the gdstk backend:

  • focused structural and PortTree tests: 9 passed
  • broader test run excluding the layout test file: 26 passed, with 16 documented subtests passed

This leaves the PR with both the packaging fix and an automated regression guard. Please review the updated head.

@appleweiping

appleweiping commented Sep 7, 2026 •

Copy link
Copy Markdown
Author

One remote CI note: the Unit tests, DRC, and Tutorial runs are held at action required with no jobs because the branch comes from a fork. The local Python 3.12 test suite is green as reported above. Maintainer approval is the only remaining CI step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant