Skip to content

tree: a legend explaining the icons - #32

Merged
Paebbels merged 3 commits into
devfrom
claude/tree-legend
Oct 15, 2026
Merged

Paebbels merged 3 commits into
devfrom
claude/tree-legend

Conversation

@pytooling-claude

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

Copy link
Copy Markdown

New Features

  • pyTooling.Sphinx.Tree:
    • An icon option may explain its icon: a | between spaces separates the icon from its text, e.g. :leaf-icon: 📄 | file. The text is inline ReST, like an entry's description; the same separator rules apply (a | in a literal or a role's text, or escaped as \|, separates nothing).
    • The texts form the tree's legend: one line of the icons with a text - root, node and leaf first, then the markers, in the order declared. An icon without a text isn't listed.
    • New option :legend: with top, bottom or none (default bottom, also without a value) places the legend above or below the tree, or leaves it out. Without any text, the tree has no legend; an explicit :legend: top or :legend: bottom then warns: tree: ':legend: top' without an icon having a text draws no legend.
    • An icon declared twice with the same text - e.g. 📁 for :node-icon: and for a marker of empty directories - is listed once. The same icon with two different texts is an error, as the legend would contradict itself: tree: Icon '📁' has two texts: 'directory' and 'folder'.
    • New option reader describedIcon (<icon> [| <text>]) for :root-icon:, :node-icon: and :leaf-icon:, rejecting two separators and a text without an icon.
    • New StringEnum LegendPosition (Top, Bottom, Hidden; DEFAULT = Bottom); LegendPosition.Parse reads :legend:, and an unknown value names the allowed ones: 'left' is not a valid LegendPosition. with the note Allowed values: top, bottom, none.
    • New post-transform RemoveTreeLegends: LaTeX, text, manual pages and Texinfo write a tree as a nested bullet list without icons, so they get no legend.
  • pyTooling.Sphinx.Node: new nodes TreeLegend (a nodes.paragraph) and TreeLegendItem (a nodes.inline, attribute icon).
  • pyTooling.Sphinx.HTML: translateTreeLegend and translateTreeLegendItem. The legend is a <p class="pytooling-tree-legend tree-legend-top|bottom"> of <span class="tree-legend-item"> items, hidden from a screen reader like the icons it explains.
  • pyTooling.Sphinx.NODES registers both nodes; setup() registers RemoveTreeLegends.
  • Stylesheet: the legend is a wrapping flex line; new custom properties --pyTooling-tree-legend-gap (1.5em, between two items) and --pyTooling-tree-legend-margin (0.5em, between tree and legend).

Example:

.. tree::
   :legend:    top
   :root-icon: 📦 | package
   :node-icon: 📁 | directory
   :leaf-icon: 📄 | file
   :icons:     > 📁 | directory
               * 🐍 | Python module

   - pyTooling.Sphinx
     > doc
     - pyTooling
       - Sphinx
         * Tree.py
     - README.md

renders the legend 📦 package · 📁 directory · 📄 file · 🐍 Python module above the tree.

Syntax

The text sits behind the icon in the option declaring it, so an icon and its meaning are declared once, in one place: the legend can't name an icon the tree doesn't declare, and changing an icon can't leave a stale legend behind. The separator is the one of the descriptions in the content.

Rejected:

  • One option listing the texts by kind and icon, e.g. :legend: root:package 📁:directory``: the icon is declared in one option and explained in another; its keys mix kind names and icons, while a marker's icon is keyed by its marker; and a text in backticks can't contain a role.
  • Renaming :root-icon:, :node-icon: and :leaf-icon: to :root:, :node: and :leaf:: every existing tree uses the current names, and they match :expanded-icon: and :collapsed-icon:. Without a |, an option means what it meant before.
  • A legend for :expanded-icon: and :collapsed-icon:: they are controls for folding, not a statement about the content.

Changes

  • pyTooling.Sphinx.Tree.markerIcons returns each marker's icon and text, dict[str, tuple[str, str]] instead of dict[str, str]. A line with a separator | holds one marker, so a text may contain commas; a line without one is still split at its commas, so every existing :icons: value reads as before.

Documentation

  • doc/Directives/Tree.rst: new section Legend with a rendered example; the options :root-icon:, :node-icon:, :leaf-icon: and :icons: with their texts, and the new option :legend:; the two new custom properties; the output formats without a legend; the new error and warning messages.
  • doc/News.rst: the legend in v0.1.0's new features.
  • doc/conf.py: the API reference skips members inherited from enum and built-in types too (renamed skipDocutilsNodeMembers → skipForeignMembers), so a StringEnum lists its own members instead of every method of a string. This also drops 16 enum internals (__new__, _generate_next_value_, ...) from ShowTestcases' page; its own members stay.

Unit Tests

  • tests/unit/Tree.py: describedIcon (icon and text, icon only, escaped separators, no value, two separators, text without icon), LegendPosition.Parse (each position, no value, an unknown value and its note), and markerIcons with texts, including a text with a comma and lines mixing both forms.
  • tests/unit/Extension.py, new testsuite Trees with a legend in a document: HTML below and above the tree, :legend: none, an icon with two texts, :legend: without texts, and no legend in text and LaTeX.
  • tests/unit/Reports.py: setup() registers two post-transforms now.
  • Locally, the same tests fail as on dev: Rendering::Parallel, and - without the pyEDAA.Reports checkout on the path - the report tests, which need a newer pyEDAA.Reports than the container's copy.

* An icon option takes a text behind a '|' between spaces: ':leaf-icon: 📄 | file' (`describedIcon`). ':icons:'
  declares a marker with a text on a line of its own; a line without text is still split at its commas.
* Option ':legend:' (`top`, `bottom`, `none`; default `bottom`) places the legend: one line of the icons with a text,
  in the order declared. An icon declared twice with the same text is listed once; two different texts are an error.
  ':legend:' without any text is warned about.
* Nodes `TreeLegend` and `TreeLegendItem` with HTML visitors; the legend is hidden from a screen reader like the icons.
* `RemoveTreeLegends` removes the legend for LaTeX, text, manual pages and Texinfo, whose trees show no icons.
* Stylesheet: '--pyTooling-tree-legend-gap' and '--pyTooling-tree-legend-margin'.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
@pytooling-claude
pytooling-claude Bot requested a review from Paebbels as a code owner October 15, 2026 13:08
@pytooling-claude pytooling-claude Bot added Documentation Improvements or additions to documentation Enhancement New feature or request labels Oct 15, 2026
@codacy-production

codacy-production Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 7 minor

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

Results:
7 new issues

Category Results
Documentation 4 minor
CodeStyle 2 minor
Complexity 1 minor

View in Codacy

🟢 Metrics 50 complexity · 2 duplication

Metric Results
Complexity 50
Duplication 2

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.50% coverage variation

Metric Results
Coverage variation ✅ +0.50% coverage variation (-1.00%)
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (8275e0d) 3221 2641 81.99%
Head commit (e31feaa) 3308 (+87) 2729 (+88) 82.50% (+0.50%)

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 (#32) 118 118 100.00%

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 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.04%. Comparing base (8275e0d) to head (42cd64d).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #32      +/-   ##
==========================================
+ Coverage   79.44%   80.04%   +0.60%     
==========================================
  Files          19       19              
  Lines        3221     3308      +87     
  Branches      486      502      +16     
==========================================
+ Hits         2559     2648      +89     
+ Misses        580      579       -1     
+ Partials       82       81       -1     
Flag Coverage Δ
unittests 80.04% <100.00%> (+0.60%) ⬆️

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.

* `LegendPosition` (`Top`, `Bottom`, `Hidden`; `DEFAULT` = `Bottom`) replaces the tuple `LEGEND_POSITIONS`, and
  `LegendPosition.Parse` the option reader `legendPosition`: an unknown value names the allowed ones in a note, and
  ':legend:' without a value draws the legend below the tree.
* doc/conf.py: the API reference skips members inherited from `enum` and built-in types too, so a `StringEnum` lists
  its members, not every method of a string.

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

@Paebbels Paebbels left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we offer a list of commonly used unicode icons with there icon, icon name, hex value? Can we offer a copy (into clipboard) button too?
This would be a new PR.

Comment thread pyTooling/Sphinx/Tree.py Resolved
Comment thread pyTooling/Sphinx/Tree.py Resolved
Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
@pytooling-claude

Copy link
Copy Markdown
Author

Answering the review's general comment - a list of commonly used Unicode icons, with a copy button:

Yes, I think that's useful: picking an icon is the step of writing a tree that sends you to a search engine. A proposal for the new PR, after this one:

  • A page in the tree documentation, e.g. Icons, with a table per topic - files and folders, code and packages, CI (workflow, action, container), status (✅ ❌ ⚠️) -: the icon, its Unicode name, and its code points as an option takes them, e.g. U+1F4C1.
  • Generated, not typed: the rows come from a list of icons, the names and code points from Python's unicodedata, so a row can't contradict its icon. An emoji with a variation selector shows both code points, e.g. ⚙️ = U+2699 U+FE0F, which :root-icon: accepts as written.
  • A copy button per row, copying the icon - or a second one copying the code points, for an editor whose font lacks the glyph. sphinx-copybutton handles code blocks only, so this would be a small script shipped with pyTooling.Sphinx' stylesheet (navigator.clipboard.writeText).
  • As a directive - e.g. .. unicode-table:: with the icons as content -, so another project can list its own icons the same way.
  • LaTeX: the table without buttons. An emoji needs the emoji font; the PDF could show the names and code points only.

Shall I go ahead with it as a new PR once #32 is merged?

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