Skip to content

Draw a hierarchy as a tree with the 'tree' directive - #18

Merged
Paebbels merged 7 commits into
devfrom
claude/tree-directive
Oct 5, 2026
Merged

Paebbels merged 7 commits into
devfrom
claude/tree-directive

Conversation

@pytooling-claude

@pytooling-claude pytooling-claude Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

New Features

  • pyTooling.Sphinx.Tree:
    • New directive tree: draws a hierarchy (a directory, a class hierarchy, a testsuite's structure) as a tree. It replaces a hierarchy drawn by hand in a code block.
      .. tree::
         :root-icon: 📦
         :node-icon: 📁
         :leaf-icon: 📄
         :icons:     > 📁
      
         - pyTooling.Sphinx
           > :file:`doc`
           - :file:`pyTooling`
             - :file:`Sphinx`
               - :mod:`~pyTooling.Sphinx.Tree`
           - :file:`README.md`
    • Content: an indented list in the style of a YAML block sequence.
      • Each entry is a line starting with a marker and a space. An entry indented deeper than the one above it is that entry's child.
      • An entry without a parent is a root, an entry with children is a node, and every other entry is a leaf. Several roots are allowed.
      • Marker - gives an entry the icon of its kind. :icons: declares more markers, each with its own icon, whatever the entry's kind is - e.g. > 📁 for an empty directory, which is a leaf.
      • An entry's text is inline ReST, so roles like :class:, :mod: and :ref: link.
    • Options:
      • :root-icon:, :node-icon: and :leaf-icon:: none by default.
      • :expanded-icon: and :collapsed-icon:: ▾ / ▸ by default.
      • :icons:: <marker> <icon>, separated by commas, also across lines. A marker is one character, not a letter or a digit; declaring - replaces the kind icons.
      • An icon is written as characters or as code points (U+1F4C1). An option without a value draws no icon.
      • :expanded-levels:: how many levels are expanded initially. Default: all.
      • :class:: additional CSS classes.
    • HTML: each entry with children is a <details>/<summary> element, so it folds and unfolds on a click, without JavaScript.
      • The stylesheet draws the connecting lines (├, └) and shows the expanded or the collapsed icon. It resets a theme's vertical margins inside a list item: sphinx_rtd_theme's 12px below a <details> left a gap in the vertical line.
      • Icons are aria-hidden.
      • Row height, indentation, expander width, icon gap, line and bottom margin are CSS custom properties (--pyTooling-tree-*).
    • Other builders, e.g. LaTeX and text: a nested bullet list without icons.
      • The nodes TreeItem and TreeLabel derive from list_item and paragraph. Sphinx dispatches a visitor along the MRO, so a builder without its own visitor falls back to the base class.
    • Errors in the content (no entry, a line that isn't an entry, an entry without text, inconsistent indentation) are reported at the directive's line. An error in an entry's text, e.g. an unknown role, is reported at that entry's line.
    • The parser builds pyTooling.Tree.Node instances.
  • Nodes are registered as sphinx-reports registers Landscape, so its nodes can be merged in unchanged:
    • pyTooling.Sphinx.Node: the node classes TreeItem and TreeLabel, RegisteredNode (name, node, html, optional latex), and the type aliases visitFunc / departFunc.
    • pyTooling.Sphinx.HTML: visit_* / depart_* per node and a translate* pair of both.
    • pyTooling.Sphinx.NODES: every node with its visitors; setup() registers them in a loop.

Documentation

  • New page Directives → tree with two rendered examples (a directory with icons, a class hierarchy with :expanded-levels: 1), the content rules, the options, the CSS custom properties and the error messages.
  • Listed on the landing page, in the README, in the module doc-string of pyTooling.Sphinx and in News.
  • doc/conf.py: an annotated autodoc-skip-member handler skips the members TreeItem and TreeLabel inherit from docutils.nodes. Otherwise :inherited-members: renders each of them, and their docutils-style doc-strings caused 42 build errors.

Unit Tests

  • tests/unit/Tree.py covers the content parser and the icon option converter:
    • parser: hierarchy, several roots, indentation depth, line indices, markers, a text ending in a colon, and each error message;
    • icon converter: characters, code points, no value, a value beyond U+10FFFF;
    • :icons: converter: markers and icons across lines, no value, and each error message.
  • tests/unit/Extension.py:
    • Registration.Nodes: setup() registers exactly the entries of NODES.
    • TreeRendering builds small projects: the HTML structure (<details>, both expander icons, kind classes, a resolved :ref:), :expanded-levels:, the LaTeX output (three nested itemize, no icons), and the line numbers of both kinds of error.
    • Project._build takes the builder's name.

@pytooling-claude
pytooling-claude Bot requested a review from Paebbels as a code owner October 5, 2026 16:39
@pytooling-claude pytooling-claude Bot added Documentation Improvements or additions to documentation Enhancement New feature or request labels Oct 5, 2026
@codacy-production

codacy-production Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 33 minor

Alerts:
⚠ 33 issues (≤ 0 issues of at least minor severity)

Results:
33 new issues

Category Results
Documentation 10 minor
CodeStyle 22 minor
Complexity 1 minor

View in Codacy

🟢 Metrics 83 complexity · 0 duplication

Metric Results
Complexity 83
Duplication 0

View in Codacy

🟢 Coverage 98.85% diff coverage · +5.23% coverage variation

Metric Results
Coverage variation ✅ +5.23% coverage variation (-1.00%)
Diff coverage ✅ 98.85% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (4e11707) 1138 674 59.23%
Head commit (b21f0ee) 1311 (+173) 845 (+171) 64.45% (+5.23%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#18) 174 172 98.85%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.70115% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.61%. Comparing base (4e11707) to head (b21f0ee).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
pyTooling/Sphinx/Tree.py 98.29% 1 Missing and 1 partial ⚠️
pyTooling/Sphinx/__init__.py 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #18      +/-   ##
==========================================
+ Coverage   58.43%   63.61%   +5.17%     
==========================================
  Files           7       10       +3     
  Lines        1138     1311     +173     
  Branches      188      220      +32     
==========================================
+ Hits          665      834     +169     
- Misses        464      466       +2     
- Partials        9       11       +2     
Flag Coverage Δ
unittests 63.61% <97.70%> (+5.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Comment thread doc/Directives/Tree.rst Resolved
Comment thread doc/conf.py Resolved
Comment thread pyTooling/Sphinx/__init__.py Resolved
claude-code and others added 4 commits October 5, 2026 22:10
The content is an indented list in the style of a YAML block sequence; an
entry's text is inline ReST, so roles like ':class:' and ':ref:' link. Options
set an icon per root, node and leaf, the expanded and collapsed icons, and how
many levels are expanded initially. HTML draws every entry with children as a
foldable '<details>' element and the stylesheet draws the lines; other
builders render nested bullet lists.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
An entry starts with '-' or with a marker declared by ':icons:', each with
its own icon - e.g. '> 📁' for an empty directory. A trailing colon is text
again. The examples write icons as characters.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
@Paebbels
Paebbels force-pushed the claude/tree-directive branch from 1ddcce8 to 4ee117b Compare October 5, 2026 22:12
claude-code and others added 2 commits October 5, 2026 22:36
sphinx_rtd_theme spaces every block in a list item by 12px. Below an entry's
'<details>', that margin ended up between the entry and its next sibling,
outside both of their lines, and left a gap in the vertical line.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
…ndscape

The node classes move to pyTooling.Sphinx.Node, their HTML visitors to
pyTooling.Sphinx.HTML as visit_*/depart_* with a translate* pair each.
NODES lists every node with its visitors per output format as a
RegisteredNode, and setup() registers them in a loop. LaTeX visitors are
optional: the tree has none and falls back to its base-classes.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Comment thread pyTooling/Sphinx/Node.py Resolved
Comment thread doc/conf.py Resolved
…-string

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
@Paebbels
Paebbels merged commit b19ac51 into dev Oct 5, 2026
48 of 49 checks passed
@Paebbels
Paebbels deleted the claude/tree-directive branch October 5, 2026 22:56
@pytooling-claude pytooling-claude Bot mentioned this pull request Oct 5, 2026
This was referenced Oct 17, 2026
@pytooling-claude pytooling-claude Bot mentioned this pull request Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants