Repository navigation
tree: a legend explaining the icons - #32
Conversation
* 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>
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Documentation | 4 minor |
| CodeStyle | 2 minor |
| Complexity | 1 minor |
🟢 Metrics 50 complexity · 2 duplication
Metric Results Complexity 50 Duplication 2
🟢 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 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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
* `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
left a comment
There was a problem hiding this comment.
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.
Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
|
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:
Shall I go ahead with it as a new PR once #32 is merged? |
New Features
pyTooling.Sphinx.Tree:|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).:legend:withtop,bottomornone(defaultbottom, 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: topor:legend: bottomthen warns:tree: ':legend: top' without an icon having a text draws no legend.: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'.describedIcon(<icon> [| <text>]) for:root-icon:,:node-icon:and:leaf-icon:, rejecting two separators and a text without an icon.StringEnumLegendPosition(Top,Bottom,Hidden;DEFAULT=Bottom);LegendPosition.Parsereads:legend:, and an unknown value names the allowed ones:'left' is not a valid LegendPosition.with the noteAllowed values: top, bottom, none.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 nodesTreeLegend(anodes.paragraph) andTreeLegendItem(anodes.inline, attributeicon).pyTooling.Sphinx.HTML:translateTreeLegendandtranslateTreeLegendItem. 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.NODESregisters both nodes;setup()registersRemoveTreeLegends.--pyTooling-tree-legend-gap(1.5em, between two items) and--pyTooling-tree-legend-margin(0.5em, between tree and legend).Example:
renders the legend
📦 package · 📁 directory · 📄 file · 🐍 Python moduleabove 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:
: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.: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.:expanded-icon:and:collapsed-icon:: they are controls for folding, not a statement about the content.Changes
pyTooling.Sphinx.Tree.markerIconsreturns each marker's icon and text,dict[str, tuple[str, str]]instead ofdict[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 fromenumand built-in types too (renamedskipDocutilsNodeMembers→skipForeignMembers), so aStringEnumlists its own members instead of every method of a string. This also drops 16 enum internals (__new__,_generate_next_value_, ...) fromShowTestcases' 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), andmarkerIconswith 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.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.